Unfortunately your Faculty
class should implement the INotifyPropertyChanged
interface to make it work. (The ObservableCollection
will only force updates if the collection itself changes - elements are added or removed - and not when properties of elements in the collection change.)
How to commit changes in WPF DataGrid to ObservableCollection Source
-
09-07-2023 - |
Question
I have DataGrid Conrol
<DataGrid Name="dataGrid" ItemsSource="{Binding Faculties}">
<DataGrid.Columns>
<DataGridTextColumn Header="Название" Width="*" Binding="{Binding Title, UpdateSourceTrigger=LostFocus, Mode=TwoWay}"/>
</DataGrid.Columns>
</DataGrid>
and View Model
private ObservableCollection<Faculty> faculties = new ObservableCollection<Faculty>();
public ObservableCollection<Faculty> Faculties
{
get { return faculties; }
set
{
faculties = value;
RaisePropertyChanged("Faculties");
}
}
Faculty class:
public class Faculty
{
public string Title { get; set; }
}
How to save changes in DataGrid to my collection? Two-Way Binding does not help
Solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow