다소 복잡한 동작을하는 ChildViewModels의 ObservableCollection이 있습니다.DataGrid - 편집 동작 변경
DataGrid가 '편집 모드'로 들어가면 행이 커밋 될 때까지 현재 셀 외부의 UI 알림을 효과적으로 사용할 수 없게됩니다.이 동작이 더 중요하게 변경 될 수 있습니까?
예 :
public class ViewModel
{
public ViewModel()
{
Childs = new ObservableCollection<ChildViewModel> {new ChildViewModel()};
}
public ObservableCollection<ChildViewModel> Childs { get; private set; }
}
public class ChildViewModel : INotifyPropertyChanged
{
private string _firstProperty;
public string FirstProperty
{
get { return _firstProperty; }
set
{
_firstProperty = value;
_secondProperty = value;
OnPropetyChanged("FirstProperty");
OnPropetyChanged("SecondProperty");
}
}
private string _secondProperty;
public string SecondProperty
{
get { return _secondProperty; }
set
{
_secondProperty = value;
OnPropetyChanged("SecondProperty");
}
}
private void OnPropetyChanged(string property)
{
if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs(property));
}
public event PropertyChangedEventHandler PropertyChanged;
}
그리고보기
:<Window.Resources>
<local:ViewModel x:Key="Data"/>
</Window.Resources>
<DataGrid DataContext="{Binding Source={StaticResource Data}}" ItemsSource="{Binding Childs}"/>
공지 사항 어떻게 행을 떠날 때까지 첫 번째 열을 편집하는 것은 숨겨진 두 번째 통지.
편집 : 구현 IEditableObject 아무것도하지 않습니다 :
public class ChildViewModel : INotifyPropertyChanged,IEditableObject
{
...
private ChildViewModel _localCopy;
public void BeginEdit()
{
_localCopy = new ChildViewModel {FirstProperty = FirstProperty, SecondProperty = SecondProperty};
}
public void EndEdit()
{
_localCopy = null;
}
public void CancelEdit()
{
SecondProperty = _localCopy.SecondProperty;
FirstProperty = _localCopy.FirstProperty;
}
}
놀라운! 너무 감사합니다!이것은 내가 소수의 손으로 머리카락을 찢어 버릴 수있게했다. 가능한 한 빨리 현상금을 수여 할 것이다. – Goblin