Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/silverlight/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# ReactiveUI RaiseAndSetIfChanged()支持字段可访问性_C#_Silverlight_Properties_System.reactive_Reactiveui - Fatal编程技术网

C# ReactiveUI RaiseAndSetIfChanged()支持字段可访问性

C# ReactiveUI RaiseAndSetIfChanged()支持字段可访问性,c#,silverlight,properties,system.reactive,reactiveui,C#,Silverlight,Properties,System.reactive,Reactiveui,问题:无法将属性的备份字段设置为private,因为在将值设置为Name时出现以下异常 System.ArgumentException : You must declare a backing field for this property named: _Name 我的代码: public class MyVM : ReactiveObject { private string _Name; public string Name { get { r

问题:无法将属性的备份字段设置为
private
,因为在将值设置为
Name
时出现以下异常

System.ArgumentException : You must declare a 
backing field for this property named: _Name
我的代码:

public class MyVM : ReactiveObject
{
    private string _Name;
    public string Name
    {
        get { return _Name; }

        set { this.RaiseAndSetIfChanged(x => x.Name, value); }
    }
}
要解决此问题,我可以将_Name设置为public:

    public string _Name;

这解决了问题,但为什么我必须公开支持字段?我在网上看到的示例使用私有备份字段…?

使用新的重载,除非您没有使用>=VS2012:

this.RaiseAndSetIfChanged(ref theBackingField, value);

谢谢工作得很好!在系统上做得很好。反应和反应界面!!!尝试用谷歌搜索,但在任何地方都找不到它!:D