admin管理员组

文章数量:1534882

2024年1月19日发(作者:)

{x:Type local:Window1}}, Path=Dogs} " >

< TextBlock VerticalAlignment ="Center" Text =" {Binding Path=Name} " >

< TextBlock VerticalAlignment ="Center" Text =" {Binding Path=Id} " >

< StackPanel >

< TextBlock VerticalAlignment ="Center" FontStyle ="Italic" > ComboBox In ListView:

< TextBlock VerticalAlignment ="Center" Foreground ="#ff3300" > Some people

< 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 > Female

< sys:String > Unknow

< 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} " >

< GridViewColumn Header ="My Dog" >

< mplate >

< DataTemplate >

< ComboBox Width ="120" Loaded ="comboBoxInListView_Loaded"

SelectedValue =" {Binding Path=MyDog, Mode=TwoWay} "

SelectedValuePath ="Id" DisplayMemberPath ="Name" >

< StackPanel Orientation ="Horizontal" >

< Button Margin ="5" Click ="btnAdd_Click" VerticalAlignment ="Center" HorizontalAlignment ="Left" Width="120" Height ="28" > Add

< Button Margin ="5" Click ="btnDel_Click" VerticalAlignment ="Center" HorizontalAlignment ="Right" Width

="120" Height ="28" > Delete

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; } }}

本文标签: 绑定转换后台代码集合