Simplest way to achieve automatic notification of property change

后端 未结 6 559
时光说笑
时光说笑 2020-12-04 13:34

I know that there are solutions out there for implementing INotifyPropertyChanged, but none of them are as simple as: reference this library, create/add this attribute, done

6条回答
  •  眼角桃花
    2020-12-04 14:10

    Simon's answer is the solution, but here's my code and a screenshot for reference. I am using Prism (with MEF - ignore the attributes on the class), so I inherit from NotificationObject for INotifyPropertyChanged. (It defines a RaisePropertyChanged method, so you have to tell NotifyPropertyWeaver that in your project file.)

    The Class

    using System.ComponentModel.Composition;
    using Microsoft.Practices.Prism.ViewModel;
    
    [Export]
    [PartCreationPolicy(CreationPolicy.NonShared)]
    public class SignControllerViewModel : NotificationObject
    {
        public string Uri { get; set; }
    }
    

    The Project File

    
    
        
        
        
            
        
    
    

    The Reflector Code

    Code after INPC has been weaved into it.

提交回复
热议问题