- 填充项目CoBoxItem
属性:contentControl(这个类型的control,内容可以anything)
例如:item=文字
例如:item=StacPanel (panel中添加各种东西) - DataBinding,绑定数据,自己在这方面要加强练习,用好WPF
<ComboBox Name="ColorCmbox" Width="60">
<ComboBox.ItemTemplate> (项目模板)
<DataTemplate> (数据模板)
<StackPanel>
<Rectangle Fill="{Binding name}"></Rectangle>
<TextBlock Text="{Binding name}"></TextBlock>
</StackPanel>
</DataTemplate>
</ComboBox.ItemTemplate>
<comboBox>
数据绑定的思想:
事件驱动++==》》》数据驱动,UI只负责读数据的展示,数据变化,自动通知UI的更新。
集合数据Binding 集合Control
TIP 1::::Binding 集合对象的一个属性,source 指定为集合对象
<ComboBox.ItemTemplate>
<DataTemplate>
<StackPanel>
<TextBlock Text="{Binding stationName}"></TextBlock>//binding 集合成员的一个属性 StationName
</StackPanel>
</DataTemplate>
</ComboBox.ItemTemplate>
C# : ColorCmbox.ItemsSource =netWork.subwayLines[0].stationsOfLine;// Source指定为 集合对象
TIP2::::BindingXMAL中的控件,
<Label Content="{Binding SelectedItem (Control的一个Property ), ElementName=LineCmbox (控件名称}"></Label>
属性:
1,SelectedIndex 选中的项目
2,IsEditable;可以输入然后选择,
相似:ListBOx
ListBox 为非折叠的 ListControl