Change Notification in MVVM Hierarchies

前端 未结 5 1278
清酒与你
清酒与你 2021-02-01 07:29

Let\'s say in some abstract ViewModel base-class I have a plain-old property as follows:

public Size Size
{
    get { return _size; }
    set
    {
        _size         


        
5条回答
  •  心在旅途
    2021-02-01 07:59

    I use Josh Smith's PropertyObserver, which you can get from his MVVM Foundation library at http://mvvmfoundation.codeplex.com/.

    Usage:

    _viewmodel_observer = new PropertyObserver(_OtherViewModel)
       .RegisterHandler(m => m.Size, m => RaisePropertyChanged(Rectangle);
    

    Brian's attribute approach is nice too. One thing I like about PropertyObserver is that I can execute arbitrary code; allowing me to check conditions which may make me avoid the raise or perform other actions all together.

提交回复
热议问题