c# - Updating the checkbox state automatically does not reflect in the GUI -


i have setting window containing observable collection of roles , components. idea here when select role on left, automatically checks components associated role on right. main problem action performed correctly behind scenes not reflected on ui.

my xaml set data template display check boxes in list:

 <listbox name="components" itemssource="{binding components, mode=twoway}" scrollviewer.cancontentscroll="false">         <listbox.itemtemplate>            <datatemplate>               <checkbox content="{binding name}" foreground="{dynamicresource mainforegroundcolor}" ischecked="{binding ischecked, mode=twoway}" margin="5 5 0 0" />            </datatemplate>          </listbox.itemtemplate> 

my viewmodel code quite simple, create selectablecomponent class hold check box state , information, , role class:

public class selectablecomponent {     public string name { get; set; }     public int id { get; set; }     public bool ischecked { get; set; } }    public class role {   public string name { get; set; }   public string projectstowatch { get; set; } }  public observablecollection<selectablecomponent> components { get; set; } 

the method gets called when change role:

public void loadspecificrolecomponents(string role) {    role r = config.instance.roles.firstordefault(a => string.equals(a.name, role, system.stringcomparison.invariantcultureignorecase));    foreach (selectablecomponent sc in components)   {        if (string.equals(r.projectstowatch, "*"))        {            sc.ischecked = true;        }        else        {            sc.ischecked = r.projectstowatch.contains(sc.name, system.stringcomparison.invariantcultureignorecase);        }   }      raisepropertychanged("components"); } 

what don't understand why ui not updated properly. since raisepropertychanged("components") on components, should update.

any type of appreciated, it's simple thing missing out on.

selectablecomponent needs implement inotifypropetychanged , raise raisepropertychanged event ischecked:

private bool _ischecked   public bool ischecked {  get{ return _ischecked;}  set  {       if(_ischecked != value)       {   _ischecked= value;           raisepropertychanged("ischecked");       }  } } 

Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -