c# - WPF Combox data updated but UI not updated - Updated code -


here code:

mainwindow.xaml

<combobox grid.column="1" margin="2" verticalcontentalignment="center" itemssource="{binding path=lowdlane, mode=oneway}"                                   selectedindex="{binding path=currentlowdlaneindex, mode=twoway, fallbackvalue=0}"                                   dropdownopened="onlowdlanedropdownopened"                                   selectionchanged="onlowdlanechanged"> </combobox> 

mainwindow.xaml.cs

public partial class mainwindow : window {      public mainwindow(viewmodel model)     {         initializecomponent();         this.datacontext = model;     }      private void onlowdlanedropdownopened(object asender, eventargs ae)     {         ((viewmodel)this.datacontext).openeddropdown();     } } 

viewmodel.cs updated

public class viewmodel : inotifypropertychanged {     public event propertychangedeventhandler propertychangedhandler;      public list<string> lowdlane     {         { return mlowdlane; }         set         {             mlowdlane = value;            propertychangedhandler.raise(this, ()=> lowdlane);         }     }     public void openeddropdown()     {         lowdlane = new list<string> { "1", "2", "3", "4", "5", "6", "7", "8"};     }  } 

in other file propertychangedeventhandler defined:

namespace system.componentmodel 

{

public delegate void propertychangedeventhandler(object sender, propertychangedeventargs e); 

}

represents method handle system.componentmodel.inotifypropertychanged.propertychanged event raised when property changed on component.

propertychangedeventhandler works in other places don't think problem here.

i created viewmodel object in other file, , passed mainwindow. when run application, can see lowdlane property updated, ui not updated.

i have looked many similar questions, none of them solved issue. can help?

you should call notifypropertychanged method of yours inside setter

public list<string> lowdlane {       { return mlowdlane; }       set       {          mlowdlane = value;          notifypropertychanged("lowdlane"); // here       } } 

for more details see here

and may want use callermembername attribute in code see here


Comments

Popular posts from this blog

javascript - Create a stacked percentage column -

Optimising Firebase database by automatically overwriting data -

javascript - Angular UI-Grid customTemplate directive causing rows to load slowly/? -