i\'ve a problem updating my datagrid when clicking the button by using NotifyPropertyChanged. It works if i set the DataGrid.ItemsSource in code behind, but it doesn\'t if i
When you go crazy (like me) because it doesn't work this time. Check the order of the calls. The OnPropertyChanged() must be called after the value was assigned.
public string Property1
{
get { return _field1; }
set
{
// assign the value first
_field1 = value;
// then call the property changed
OnPropertyChanged("Property1");
}
}
In your codebehind .xaml.cs create property
public ObservableCollection<SampleClass> MyCollection {get; set;}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
//if i set the ItemsSource here, updating of the UI works
dataGrid1.ItemsSource = MyCollection;
}
In XAML:
<DataGrid ItemsSource="{Binding Path=., Mode=OneWay, NotifyOnSourceUpdated=True, UpdateSourceTrigger=PropertyChanged}"/>
I followed up on syned's tip. For me I had to us the Mode as
Mode=TwoWay
The key here was the
UpdateSourceTrigger
property.
Thanks a lot...!