c# - Databinding to an ObservableCollection -


the following in code in mainwindow.xaml.cs:

namespace test {     public partial class mainwindow : window     {         public class channelinfo : inotifypropertychanged         {             public event propertychangedeventhandler propertychanged;             protected void notify(string propertyname)             {                 if (this.propertychanged != null)                 {                         propertychanged(this, new propertychangedeventargs(propertyname));                 }             }             private string _channeldescription;             public string channeldescription             {                                 {                     return _channeldescription;                 }                 set                 {                     if (value != _channeldescription)                     {                         _channeldescription = value;                         notify("channeldescription");                     }                 }             }         }          public observablecollection<channelinfo> channels { get; set; }          public mainwindow()         {             initializecomponent();             channels = new observablecollection<channelinfo>()              {                  new channelinfo() { channeldescription = "ib" }              };             datacontext = channels;         }          private void window_loaded(object sender, routedeventargs e)         {             //((observablecollection<channelinfo>)datacontext).add(new channelinfo() { channeldescription = "ib" });                     }     } } 

in xaml have textbox defined follows:

<textbox height="23" text="{binding channeldescription}" horizontalalignment="left" margin="180,106,0,0" name="textbox1" verticalalignment="top" width="120" /> 

now problem if add item channels in constructor itself, textbox displaying bound text. when add in window_loaded above (uncomment line), text not displayed.


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -