Jeffrey Banks
Jeffrey Banks

Reputation: 11

Unable to Encapsulate and also ImplementInterface

I am using C# in Silverlight ( I created a new class folder. However, I do not have the option for incapsulate (i had to type out myself, snippets is another problem) also the resolve and implement option (I am using Visual Studio 2010) Please what am i doing wrong?? Here is a example i am trying to resolve and implement the INotifyPropertyChanged

public class Person : INotifyPropertyChanged 
{

    private string _FirstName;
    public string FirstName
    {
        get { return _firstName; }
        set { _firstName = value; }
    }

    private string _greeting;
    public string Greeting
    {
        get { return _greeting; }
        set { _greeting = value; }
    }

Upvotes: 1

Views: 86

Answers (2)

AnthonyWJones
AnthonyWJones

Reputation: 189505

This is what your code should look like:-

public class Person : INotifyPropertyChanged 
{

    private string _firstName;
    public string FirstName
    {
        get { return _firstName; }
        set { _firstName = value; NotifyPropertyChanged("FirstName"); }
    }

    private string _greeting;
    public string Greeting
    {
        get { return _greeting; }
        set { _greeting = value; NotifyPropertyChanged("Greeting");  }
    }

    private void NotifyPropertyChanged(string name)
    {
        if (PropertyChanged != null)
            PropertyChanged(this, new PropertyChangedEventArgs(name));
    }

    public event PropertyChangedEventHandler PropertyChanged;
}

Upvotes: 0

Samuel
Samuel

Reputation: 17171

Look at the casing! The private string _FirstName has a captial 'F', but the instance variable referenced right below it has a lower case 'f'. Variable names are case-sensitive

Upvotes: 2

Related Questions