WPF 控件之ComboBox绑定[2]
2014-04-22 13:01
405 查看
最近感觉新的方法Binding comboBox用起来很好用。
记录一下:
MyList就是某一个Model的list, Model中有idRow和DisplayName
SelectedID表示选中的idRow,放到这个变量中。
选中后,有时候会出现一个讨厌的红色矩形框。去掉矩形框方法(http://stackoverflow.com/questions/4135955/remove-red-rectangle-around-combobox):
About modify the Validation.ErrorTemplate[/code]
记录一下:
<ComboBox Grid.Row="0" Grid.Column="1" VerticalAlignment="Center" HorizontalAlignment="Left" MinWidth="120" x:Name="cboFamilyName" DisplayMemberPath="DisplayName" SelectedValuePath="idRow" IsEditable="True" IsReadOnly="True" ItemsSource="{Binding MyList}" SelectedValue="{Binding Path=SelectedID, Mode=TwoWay}" />
MyList就是某一个Model的list, Model中有idRow和DisplayName
SelectedID表示选中的idRow,放到这个变量中。
选中后,有时候会出现一个讨厌的红色矩形框。去掉矩形框方法(http://stackoverflow.com/questions/4135955/remove-red-rectangle-around-combobox):
Validation.ErrorTemplate="{x:Null}"
About modify the Validation.ErrorTemplate[/code]
<ControlTemplate x:Key="ComboBoxValidationErrorTamplate"> <DockPanel> <Border BorderBrush="Blue" BorderThickness="4"> <AdornedElementPlaceholder /> </Border> </DockPanel> </ControlTemplate>
And then use it in your ComboBox like
<ComboBoxValidation.ErrorTemplate="{StaticResource ComboBoxValidationErrorTamplate}" ...>
相关文章推荐
- WPF实现支持Command绑定的ComboBox控件
- 将DataTable绑定到wpf的ComboBox控件方法
- 将DataTable绑定到wpf的ComboBox控件方法
- wpf ComboBox 控件利用DataSet数据绑定
- WPF 控件之ComboBox绑定
- MVVM Light 列表类型控件的处理: Combobox、ListBox、Datagrid等所有能绑定到集合的控件
- WPF-获取Combobox已绑定的数据源并转成Dictionary
- WPF中控件与控件值的绑定——出自《IT168》
- WPF 实现数据结构对象与UI控件的绑定
- WPF 的COMBOBOX绑定(匿名类)
- 继续聊WPF——获取ComboBox中绑定的值
- WPF 控件中的数据绑定
- 如何得到WPF中控件绑定的EventTrigger
- WPF的ComboBox绑定[个人学习笔记](不成熟)
- WPF 控件使用之ComboBox
- WinForm 中 comboBox控件之数据绑定
- KeyValuePair<byte, string> 类型的数据如何绑定到ComboBox控件上
- WPF学习笔记:ComboBox的数据绑定
- WinForm控件复杂数据绑定常用数据源(对Combobox,DataGridView等控件DataSource赋值的多种方法)
- WPF--ComboBox数据绑定