0

Problem: Cannot set backing field of property to private as I get the following exception when setting a value to Name.

System.ArgumentException : You must declare a 
backing field for this property named: _Name

My Code:

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

        set { this.RaiseAndSetIfChanged(x => x.Name, value); }
    }
}

To Fix this i have been able to set _Name to public:

    public string _Name;

Which fixed the problem, but why do I have to expose the backing field as public? The examples I see on the Net use private backing fields...?

4

1 回答 1

2

请改用新的重载,除非您不使用 >= VS2012:

this.RaiseAndSetIfChanged(ref theBackingField, value);
于 2013-09-22T21:28:21.807 回答