Question

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...?

Was it helpful?

Solution

Use the new overload instead, unless you're not using >= VS2012:

this.RaiseAndSetIfChanged(ref theBackingField, value);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top