创建一个绑定类,实现INotifyPropertyChanged接口:
public class NotifyPropertyChange : INotifyPropertyChanged
{
#region INotifyPropertyChanged 成员
public event PropertyChangedEventHandler PropertyChanged;
public virtual void FirePropertyChanged(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
#endregion
}
具体需要绑定的类继承NotifyPropertyChange 类,其中需要绑定的属性的set方法中添加FirePropertyChanged方法:
public class ***Entity:NotifyPropertyChange
public int Id
{
get { return id; }
set { id = value; FirePropertyChanged("Id"); }
}
在wpf的界面中,需要与界面绑定的控件中,xaml语言如下:
<Grid >
<ListView Name="list1" SelectionChanged="list1_SelectionChanged">
<ListView.View>
<GridView>
<GridViewColumn DisplayMemberBinding="{Binding Name}" Header="名称" Width="250" />
<GridViewColumn DisplayMemberBinding="{Binding Type}" Header="类型" Width="70" />
<GridViewColumn DisplayMemberBinding="{Binding ICDValue}" Header="当前值" Width="50" />
</GridView>
</ListView.View>
</ListView>
</Grid>