Alexei Malashkevich
Alexei Malashkevich

Reputation: 1645

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.

Upvotes: 4

Views: 18075

Answers (1)

Emond
Emond

Reputation: 50692

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.

Upvotes: 13

Related Questions