为什么在mvvmlight';什么是默认实现?

为什么在mvvmlight';什么是默认实现?,mvvm,mvvm-light,inotifypropertychanged,Mvvm,Mvvm Light,Inotifypropertychanged,我正在使用mvvmlight,我发现inpc的默认实现(来自mvvminpcmsg的代码片段)是: /// <summary> /// The <see cref="MyProperty" /> property's name. /// </summary> public const string MyPropertyPropertyName = "MyProperty"; private bool _myProper

我正在使用mvvmlight,我发现inpc的默认实现(来自mvvminpcmsg的代码片段)是:

    /// <summary>
    /// The <see cref="MyProperty" /> property's name.
    /// </summary>
    public const string MyPropertyPropertyName = "MyProperty";

    private bool _myProperty = false;

    /// <summary>
    /// Sets and gets the MyProperty property.
    /// Changes to that property's value raise the PropertyChanged event. 
    /// This property's value is broadcasted by the MessengerInstance when it changes.
    /// </summary>
    public bool MyProperty
    {
        get
        {
            return _myProperty;
        }

        set
        {
            if (_myProperty == value)
            {
                return;
            }

            RaisePropertyChanging(MyPropertyPropertyName);
            var oldValue = _myProperty;
            _myProperty = value;
            RaisePropertyChanged(MyPropertyPropertyName, oldValue, value, true);
        }
    }
我不认为inpc实现需要它,也不认为它有任何用途。
那么为什么要添加它呢?

所有INPC实现都需要某种方法来解决哪个属性会引发更改通知。这通常由以下人员完成:

  • 传入属性的字符串名称
  • 使用表达式解析属性名称
  • 使用属性

在您的示例中,它使用属性的字符串名称。

属性的公共常量字符串是为您在类之外但需要处理属性更改事件的场景添加的。

但是为什么它是
公共的
?@Fei:不知道这个。
public const string MyPropertyPropertyName = "MyProperty";