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

有帮助吗?

解决方案

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.)

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top