wpf
LIST의 UI에 즉각적으로 바인딩 업데이트를 하고 싶을때..
동동(이재동)
2017. 8. 22. 12:41
물론 ViewModel에서는 MVVM Light 라이브러리에 있는 NotifyProperty가 알아서 해주겠지만
Model 같은경우는 자기가 만들면 된다.
에를 들면 ObservableCollection에서 어떤 Property를 수정하였을때 즉각적으로 바인딩된 UI에 적용하고 싶다면
Model에 INotifyPropertyChanged 인터페이스를 구축하면 된다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | public class OrderedMenuItem : INotifyPropertyChanged { public int Index { get; set; } private int _orderCount; public int OrderCount { get { return _orderCount; } set { if (_orderCount != value) { _orderCount = value; NotifyPropertyChanged("OrderCount"); } } } public event PropertyChangedEventHandler PropertyChanged; public void NotifyPropertyChanged(string propName) { if (this.PropertyChanged != null) this.PropertyChanged(this, new PropertyChangedEventArgs(propName)); } } |
참고 : http://www.wpf-tutorial.com/data-binding/responding-to-changes/