문제

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