SilverLight:基础控件使用(2)-ComboBox,ListBox控件

ylbtech-SilverLight-Basic-Control:基础控件使用(2)-ComboBox,ListBox控件

直接在 XAML 代码中设置 Items 和通过后台代码绑定数据源

ComboBox,ListBox

1.A,返回顶部ComboBox(下拉列表框)
1,
<ComboBox Height="23" HorizontalAlignment="Left" Margin="46,45,0,0"
Name="comboBox1" VerticalAlignment="Top" Width="120" ItemsSource="{Binding}">
<ComboBoxItem Content="北京" />
<ComboBoxItem Content="上海" IsSelected="True" />
<ComboBoxItem Content="济南" />
</ComboBox>
<dataInput:Label Height="18" HorizontalAlignment="Left" Margin="46,82,0,0"
Name="label1" VerticalAlignment="Top" Width="100" />
<ComboBox Height="23" HorizontalAlignment="Left" Margin="48,111,0,0"
Name="comboBox2" VerticalAlignment="Top" Width="120" />

2, Name,Height,Width,

Content,IsSelected[设为默认选项]

3,
//取值
ComboBoxItem cbi = (ComboBoxItem)comboBox1.SelectedItem;
label1.Content = cbi.Content; #region 城市数据源
IList<ComboBoxItem> cbis = new List<ComboBoxItem>();
cbis.Add(new ComboBoxItem() { Content="shanghai" });
cbis.Add(new ComboBoxItem() { Content = "beijing" });
cbis.Add(new ComboBoxItem() { Content = "ji'nan", IsSelected=true});
#endregion
//数据绑定
comboBox2.ItemsSource = cbis;

4,

1.B,返回顶部 ListBox(列表框)
1,
<ListBox Height="76" HorizontalAlignment="Left" Margin="64,12,0,0"
Name="listBox1" VerticalAlignment="Top" Width="120">
<ListBoxItem Content="上海" />
<ListBoxItem Content="北京" IsSelected="True" />
<ListBoxItem Content="济南" />
</ListBox>
<dataInput:Label Height="18" HorizontalAlignment="Left" Margin="72,94,0,0"
Name="label1" VerticalAlignment="Top" Width="100" />
<ListBox Height="74" HorizontalAlignment="Left" Margin="64,118,0,0"
Name="listBox2" VerticalAlignment="Top" Width="120" />

2,Name,Height,Width,

Content,IsSelected[设为默认选项]

3,
//取值
ListBoxItem lbi = (ListBoxItem)listBox1.SelectedItem;
label1.Content = lbi.Content; #region 城市数据源
IList<ListBoxItem> lbis = new List<ListBoxItem>();
lbis.Add(new ListBoxItem() { Content = "shanghai" });
lbis.Add(new ListBoxItem() { Content = "beijing" });
lbis.Add(new ListBoxItem() { Content = "ji'nan", IsSelected = true });
#endregion
//数据绑定
listBox2.ItemsSource = lbis;

4,

1.C,返回顶部
 
SilverLight:基础控件使用(2)-ComboBox,ListBox控件 作者:ylbtech
出处:http://ylbtech.cnblogs.com/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
上一篇:hdu4737 A Bit Fun


下一篇:玩具装箱 BZOJ 1010