I'm trying to work with a datagrid using the MVVM pattern. The problem is when I select an item in datagrid for the first time, the datagrid will update the source property correctly, then I select another item, the source property doesn't update. This is my binding in xaml:
<DataGrid ItemsSource="{Binding Customers}"
SelectedItem="{Binding SelectedCustomer, Mode=TwoWay,
UpdateSourceTrigger=PropertyChanged}" AutoGenerateColumns="False">
ViewModel code:
public Customer SelectedCustomer
{
get { return _selectedCustomer; }
set
{
if (value != _selectedCustomer)
{
_selectedCustomer = value;
NotifyOfPropertyChange(() => SelectedCustomer);
}
}
}
Thanks in advance!
Customeryou are setting inSelectedCustomeris one ofCustomerschildren. notice that theSelectedCustomermust be the same Reference of one ofCustomerschildren not the same customer. (the same Reference not customer) it is very imprtant.