开发者

Unable to Encapsulate and also ImplementInterface

开发者 https://www.devze.com 2023-02-01 04:58 出处:网络
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 op

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 : INotifyPr开发者_如何学运维opertyChanged 
{

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

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


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


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;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消