登 录
好像wpf没有现成的组件.自己就用用户控件写了一个
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; namespace DownBox2 { /// <summary> /// UserControl1.xaml 的交互逻辑 /// </summary> public partial class DownBox : Border { private int i=0; private Double H=20,W=120; private LinearGradientBrush LGB; private FontFamily DBFont; private int DBFontSize=15; private List<String> ItemContent; public DownBox() { InitializeComponent(); Object ob = FindResource("s1"); LGB = (LinearGradientBrush)ob; ItemContent = new List<string>(); } public void SetWAndH(Double H, Double W) { this.H = H; this.W = W; } public void SetDBFontSize(int DBFontSize) { this.DBFontSize = DBFontSize; } public void SetDBFont(FontFamily DBFont) { this.DBFont = DBFont; } public void AddRow(String s) { g.RowDefinitions.Add(new RowDefinition()); TextBlock tb = new TextBlock(); tb.Height = H; tb.Width = W; tb.Text = s; tb.FontFamily = DBFont; tb.FontSize = DBFontSize; tb.MouseEnter+=new MouseEventHandler(tb_MouseEnter); tb.MouseLeave += new MouseEventHandler(tb_MouseLeave); g.Children.Add(tb); tb.SetValue(Grid.RowProperty,i); i++; ItemContent.Add(s); } public String GetItemContent(int i) //获取指定下拉框文本 { return ItemContent[i]; } public Boolean ReMoveItemContent(int i) { if (i < ItemContent.Count) { g.Children.RemoveAt(i); ItemContent.RemoveAt(i); return true; } return false; } public void tb_MouseLeave(Object sender, MouseEventArgs e) { TextBlock tb = (TextBlock)sender; tb.Background = Brushes.White; } public void tb_MouseEnter(Object sender,MouseEventArgs e) { TextBlock tb=(TextBlock)sender; tb.Background = LGB; } public void SetVi() { this.Opacity = 1; } public void SetHide() { this.Opacity = 0; } private void Border_LostFocus(object sender, RoutedEventArgs e) { this.Opacity = 0; } } }
以下是xaml中的代码
<Border x:Class="DownBox2.DownBox" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" mc:Ignorable="d" Height="auto" BorderThickness ="1" BorderBrush="Black" LostFocus="Border_LostFocus"> <Grid Name="g">
</Grid> </Border>
下面是效果图片:
抱歉!评论已关闭.