There is a class

public class ClassA: INotifyPropertyChanged { public event PropertyChangedEventHandler PropertyChanged; protected void NotifyPropertyChanged(string property) { PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(property)); } string m_Text=""; public string Text { get { return m_Text; } set { m_Text = value; NotifyPropertyChanged("Text"); } } } 

There is a Grid , whose members are members of class ClassA

 <Grid> <DataGrid.Columns> <DataGridTextColumn Binding="{Binding Path=Text}"> </DataGrid.Columns> </Grid> 

Everything works out with a bang, but that's the problem, m_Text=value works only if the selected line is lost / changed. those. If I changed the data, clicked on the enterr, but did not change the highlighted line, then the Text in the class instance did not change. How to fix this bug?

    1 answer 1

    You need to add UpdateSourceTrigger=PropertyChanged to Binding.

    If I changed the data, clicked Enter, but did not change the selected line, then Text in the class instance did not change.

    since the default is UpdateSourceTrigger=LostFocus , i.e. changes occur when you lose focus, as in your case.

     <Grid> <DataGrid.Columns> <DataGridTextColumn Binding="{Binding Path=Text, UpdateSourceTrigger=PropertyChanged}"> </DataGrid.Columns> </Grid>