WPF中 ComBox的用法

  • 填充项目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

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值