動(dòng)態(tài)刷新Colume4的值
1:原數(shù)據(jù)定義
數(shù)據(jù)類繼承:INotifyPropertyChanged, 實(shí)現(xiàn)INotifyPropertyChanged接口
public class CustomTableColumes: INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
public void NotiFy(string property)
{
? ? if (PropertyChanged != null)
? ? {
? ? ? ? PropertyChanged(this, new PropertyChangedEventArgs(property));
? ? }
}
? ? //實(shí)時(shí)刷新行里的某一列調(diào)用NotiFy
? ? ? public string Colume4
? ? ? ? {
? ? ? ? ? ? get
? ? ? ? ? ? {
? ? ? ? ? ? ? ? return _Colume4;
? ? ? ? ? ? }
? ? ? ? ? ? set
? ? ? ? ? ? {
? ? ? ? ? ? ? ? _Colume4 = value;
? ? ? ? ? ? ? NotiFy("Colume4");
? ? ? ? ? ? }
? ? ? ? }
2:ModeView 定義ObservableCollection
public class PlcDebugViewModel : GenericViewModel<XmlItemNew>
{
private ObservableCollection<CustomTableColumes> customTable = new ObservableCollection<CustomTableColumes>();
? ? ? public ObservableCollection<CustomTableColumes> CustomTable
? ? ? ? {
? ? ? ? ? ? get
? ? ? ? ? ? {
? ? ? ? ? ? ? ? return customTable;
? ? ? ? ? ? }
? ? ? ? ? ? set
? ? ? ? ? ? {
? ? ? ? ? ? ? ? this.customTable = value;
? ? ? ? ? ? ? ? this.RaisePropertyChanged(() => this.CustomTable);
? ? ? ? ? ? }
? ? ? ? }
}
3:View 綁定數(shù)據(jù)源xaml
<DataGrid? Name="Mygrid" Grid.Row="2" Grid.Column="1" Grid.RowSpan="24" Margin="5"? SelectedCellsChanged="DataRowSelected"? ItemsSource="{Binding CustomTable}" >
? ? ? ? ? ? ? ? ? ? ? ? ? ? <DataGrid.Columns>
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? <DataGridTextColumn Width="130*"? Header="名稱"? Binding="{Binding Colume0}"? IsReadOnly="True"/>
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? <DataGridTextColumn Width="60*"? Header="讀寫屬性"? Binding="{Binding Colume1}"? IsReadOnly="True"/>
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? <DataGridTextColumn Width="90*"? Header="數(shù)值范圍"? Binding="{Binding Colume2}"? IsReadOnly="True"/>
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? <DataGridTextColumn Width="100*"? Header="內(nèi)控參數(shù)"? Binding="{Binding Colume3}"? IsReadOnly="True"/>
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? <DataGridTextColumn Width="100*"? Header="當(dāng)前內(nèi)容"? Binding="{Binding Colume4}"? IsReadOnly="True"/>
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? <DataGridTextColumn Width="195*"? Header="備注說明"? Binding="{Binding Colume5}"? IsReadOnly="True"/>
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? <DataGridTextColumn Width="30*"? Header=""? Visibility="Hidden"? Binding="{Binding Colume6}"? IsReadOnly="True"/>
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? <DataGridTextColumn Width="30*"? Header=""? Visibility="Hidden"? Binding="{Binding Colume7}"? IsReadOnly="True"/>
? ? ? ? ? ? ? ? ? ? ? ? ? ? </DataGrid.Columns>
? ? ? ? ? ? ? ? ? ? ? ? </DataGrid>
看到另一種方法
