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,返回顶部
 

本文转自ylbtech博客园博客,原文链接:http://www.cnblogs.com/ylbtech/p/3397062.html ,如需转载请自行联系原作者
相关文章
Silverlight自定义数据绑定控件应该如何处理IEditableObject和IEditableCollectionView对象
原文:Silverlight自定义数据绑定控件应该如何处理IEditableObject和IEditableCollectionView对象 原创文章,如需转载,请注明出处。   最近在一直研究Silverlight下的数据绑定控件,发现有这样两个接口IEditableObject 和IEditableCollectionView,记录一下结论,欢迎交流指正。
869 0

热门文章

最新文章