admin管理员组文章数量:1534882
2024年1月19日发(作者:)
{x:Type local:Window1}}, Path=Dogs} " >
ComboBox >
< TextBlock VerticalAlignment ="Center" Text =" {Binding Path=Name} " > TextBlock >
< TextBlock VerticalAlignment ="Center" Text =" {Binding Path=Id} " > TextBlock >
StackPanel >
< StackPanel >
< TextBlock VerticalAlignment ="Center" FontStyle ="Italic" > ComboBox In ListView: TextBlock >
< TextBlock VerticalAlignment ="Center" Foreground ="#ff3300" > Some people TextBlock >
< ListView Name ="listView1" MinHeight ="200" >
< >
< GridView >
< GridViewColumn Header ="Index" DisplayMemberBinding =" {Binding Path=Index} " />
< GridViewColumn Header ="Name" DisplayMemberBinding =" {Binding Path=Name} " />
< GridViewColumn Header ="Sex" >
< mplate >
< DataTemplate >
< ComboBox Width ="120" SelectedValue =" {Binding Path=Sex, Mode=TwoWay} " SelectedIndex ="0" >
< >
< sys:String > Male sys:String >
< sys:String > Female sys:String >
< sys:String > Unknow sys:String >
>
ComboBox >
DataTemplate >
mplate >
GridViewColumn >
< GridViewColumn Header ="Education Grade" >
< mplate >
< DataTemplate >
< ComboBox Width ="120" SelectedValue ="{Binding Path=EducationGrade, Mode=TwoWay, Converter={StaticResource educConverter}} "
ItemsSource =" {Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:Window1}}, Path=EducationTypes} " >
ComboBox >
DataTemplate >
mplate >
GridViewColumn >
< GridViewColumn Header ="My Dog" >
< mplate >
< DataTemplate >
< ComboBox Width ="120" Loaded ="comboBoxInListView_Loaded"
SelectedValue =" {Binding Path=MyDog, Mode=TwoWay} "
SelectedValuePath ="Id" DisplayMemberPath ="Name" >
ComboBox >
DataTemplate >
mplate >
GridViewColumn >
GridView >
>
ListView >
StackPanel >
< StackPanel Orientation ="Horizontal" >
< Button Margin ="5" Click ="btnAdd_Click" VerticalAlignment ="Center" HorizontalAlignment ="Left" Width="120" Height ="28" > Add Button >
< Button Margin ="5" Click ="btnDel_Click" VerticalAlignment ="Center" HorizontalAlignment ="Right" Width
="120" Height ="28" > Delete Button >
StackPanel >
StackPanel >
Grid >
Window >
Window1的后台代码::
using System;using c;using ;using ;using s;using ls;using ;using nts;using ;using ;using g;using tion;using ;using entModel;namespace ComboBoxBindings{ ///
/// Interaction logic for ///
public partial class Window1 : Window { private int index;
public Window1() { InitializeComponent(); ( new Dog( " Dog1 " )); ( new Dog( " Dog2 " )); ( new Dog( " Dog3 " )); ( " EducationGrade1 " ); ( " EducationGrade2 " ); ( " EducationGrade3 " ); this .ource = persons; } public List < String > types = new List < String > (); public List < String > EducationTypes { get
代码
{ return types; } } public BindingList < Dog > dogs = new BindingList < Dog > (); public BindingList < Dog > Dogs { get
{ return dogs; } } public BindingList < Person > persons = new BindingList < Person > (); public BindingList < Person > Persons { get
{ return persons; } } private void comboBoxInListView_Loaded( object sender, RoutedEventArgs e) { ComboBox box = sender as ComboBox; ource = null ; ource = dogs; } private void btnAdd_Click( object sender, RoutedEventArgs e) { ( new Person( ++ index)); } private void btnDel_Click( object sender, RoutedEventArgs e) { while ( this . > 0 ) { ((Person) this .edItems[ 0 ]); } } private void comboBoxInWnd_SelectionChanged( object sender, SelectionChangedEventArgs e) { ComboBox box = sender as ComboBox; this .ntext = null ; this .ntext = edItem; } }}
版权声明:本文标题:ComboBox在WPF中的绑定示例:绑定项、集合、转换,及其源代码 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://m.elefans.com/dianzi/1705679048a150675.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论