Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF DataGrid TwoWay Binding

I have property UserSet which contains from ObservableCollection<GridRow>. GridRow - my class, which contains 4 properties like this:

public int Id
{
    get { return id; }
    set
    {
        id = value;
        RaisePropertyChanged("Id");
    }
}

I populate UserSet, then Grid binds to it. When I change id field works setter Id. It sets right values. But, after all changes, when I click other button my UserSet has not modified values. So I can't get updated Grid. This is my XAML:

<DataGrid ItemsSource="{Binding UsersSet, Mode=TwoWay}" AutoGenerateColumns="True">

</DataGrid>

Please help.

like image 647
Alexei Malashkevich Avatar asked Dec 16 '22 23:12

Alexei Malashkevich


1 Answers

You could try and set the UpdateSourceTrigger:

<DataGrid ItemsSource="{Binding UsersSet, 
                        Mode=TwoWay, 
                        UpdateSourceTrigger=PropertyChanged}" 
          AutoGenerateColumns="True">

</DataGrid>

Without knowing the rest of your code it is pretty hard to guess.

like image 169
Emond Avatar answered Jan 16 '23 08:01

Emond