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