日期:2014-05-18 浏览次数:21010 次
// Data类型,包含Data1和Data2属性,用来绑定 public class MyData : INotifyPropertyChanged { public event PropertyChangedEventHandler PropertyChanged; private decimal data1; private decimal data2; public decimal Data1 { get { return data1; } set { data1 = value; if (PropertyChanged != null) this.PropertyChanged.Invoke(this, new PropertyChangedEventArgs("Data1")); } } public decimal Data2 { get { return data2; } set { data2 = value; if (PropertyChanged != null) this.PropertyChanged.Invoke(this, new PropertyChangedEventArgs("Data2")); } } } // MyDatas数据类型,用于标示集合 public class MyDatas : ObservableCollection<MyData> { } // XAML中代码 // 设置资源 <Window.Resources> <local:MyDatas x:Key="MyDatas"/> </Window.Resources> // 显示数据 <StackPanel> <Button Click="Button_Click">add people</Button> <Button Click="Button_Click_1">change comany</Button> <ListView ItemsSource="{StaticResource MyDatas}"> <ListView.View> <GridView> <GridViewColumn Header="Data1" DisplayMemberBinding="{Binding Data1}"/> <GridViewColumn Header="Data2" DisplayMemberBinding="{Binding Data2}"/> <GridViewColumn Header="Sum" DisplayMemberBinding="{Binding ???}"/> </GridView> </ListView.View> </ListView> </StackPanel>