C# & Silverlight Basic Class Syntax with Get/Set Properties not working -


i have really, simple class , tried use get/set properties aren't working me... sure obvious thing on looking can't see why aren't working. have checked out code utilizes class , fine can see.

in main code, if type

report r = new report();  string str = "taco"; r.displayname = str;  

the report declared alright , set empty strings or new list or whatever parameter's default is. every time ran displayname remained blank after code finished executing...

so tried putting stop point in class displayname set property @ set {_displayname = displayname;} , value passed in (displayname) empty string.... though string says "taco" in main code.... have no idea sure right in face. if need more code can provide it...

report r = new report();  string str = "taco";  r.setreportdisplayname(str);  

but reason above works.

public class report   {     private string _reportpath = string.empty;     public string reportpath     {         { return _reportpath; }         set { _reportpath = reportpath; }     }      private string _displayname = string.empty;     public string displayname     {         { return _displayname; }         set { _displayname = displayname; }     }      private list<parameter> _parameters = new list<parameter>();     public list<parameter> parameters     {         { return _parameters; }         set { _parameters = parameters; }     }      public report() { }     public report(string path, string display, list<parameter> param)     {         _reportpath = path;         _displayname = display         _parameters = param;     }      public void setreportdisplayname(string str)     {        _displayname = str;      } } 

you defining properties incorrectly. should done as:

private string _displayname = string.empty; public string displayname {     { return _displayname; }     set { _displayname = value; } } 

that being said, if using silverlight, want implement inotifypropertychanged. without this, data binding not reflect changes made in code.

to implement interface, you'll need add implementation. "standard" way implement via:

public class report : inotifypropertychanged {     // declare propertychanged event     public event propertychangedeventhandler propertychanged;      // raise propertychanged event     protected void notifypropertychanged(string propertyname)     {         var handler = this.propertychanged;         if (handler != null)         {             handler(this, new propertychangedeventargs(propertyname));         }     }   

at point, need define properties like:

private string _displayname = string.empty; public string displayname {     { return _displayname; }     set      {          if (_displayname != value)         {             _displayname = value;              notifypropertychanged("displayname");         }     } } 

doing allow data bind "report" class. may want consider using observablecollection<t> instead of list<t> collections want use data binding.


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -