2014-02-27 14 views
1

我可以使用監聽器使用MvvmCross監聽特定屬性。我如何聆聽我的課程的所有屬性,以及(或者)特定對象的所有屬性?使用MVX收聽PropertyChanged

_listener = new MvxPropertyChangedListener(this); 
_listener.Listen(() => HighlightText, sourceHandler); 
_listener.Listen(() => SearchText, sourceHandler); 

當前的方法效果很好,因爲我可以輕鬆地重命名屬性名稱。

回答

3

要做到這一點,最簡單的方法可能是使用代碼來訂閱自己從https://github.com/MvvmCross/MvvmCross/blob/v3.1/Cirrious/Cirrious.MvvmCross/ViewModels/MvxPropertyChangedListener.cs

_token = _ViewModel.WeakSubscribe(OnPropertyChanged); 

private void OnPropertyChanged(object sender, PropertyChangedEventArgs e) 
{ 
     // your code - may or may not use e.PropertyName 
} 

您可以輕鬆地做到這一點任何INotifyPropertyChanged的對象 - 和(傳統)的事件處理程序只應在UI上調用線。