gpt4 book ai didi

mvvm - 为什么在 mvvmlight 的默认实现中有一个公共(public)常量字符串属性?

转载 作者:行者123 更新时间:2023-12-03 10:36:17 26 4
gpt4 key购买 nike

我正在使用 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);
}
}

我想知道为什么要添加公共(public) const 字符串?
public const string MyPropertyPropertyName = "MyProperty";

我不认为它是 inpc 实现所必需的,我也没有看到它的任何用法。
那为什么要加呢?

最佳答案

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

关于mvvm - 为什么在 mvvmlight 的默认实现中有一个公共(public)常量字符串属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26706821/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com