MVVM - RaisePropertyChanged turning code into a mess

前端 未结 5 1990
萌比男神i
萌比男神i 2021-01-12 00:08

New to MVVM so please excuse my ignorance.

I THINK i\'m using it right but I find my ViewModel has too many of these:

RaisePropertyChanged(\"SomeProp         


        
5条回答
  •  暖寄归人
    2021-01-12 00:30

    Take a look at this What is the best or most interesting use of Extension Methods you've seen?.

    It describes an extension method and a helper method that my Model and ViewModel classes use to enable the following strongly typed (no magic string) properties.

    private string _name;
    public string Name
    {
        get { return _name; }
        set { this.NotifySetProperty(ref _name, value, () => this.Name); }
    }
    

    This is about as simple as I think it can get. Hope it helps.

提交回复
热议问题