c# - How to get selected listbox item to update another listbox? -


i'm new wpf , mvvm , hope makes sense...

i have listbox of checkbox items. when check or uncheck item, want know how fire event or whatever give me ability add selected items text different listbox.

here's i've done far:

xaml:

<listbox itemssource="{binding target}" isenabled="{binding iscontrolenabled}">      <listbox.itemtemplate>           <datatemplate>                 <checkbox content="{binding titlename}" ischecked="{binding ischecked}" />           </datatemplate>      </listbox.itemtemplate> </listbox> 

main viewmodel class:

private observablecollection<checkserveritem> _target = new observablecollection<checkserveritem>(); 

small class handle checkbox events:

public class checkserveritem : viewmodelbase {     private bool _ischecked { get; set; }     private string _title { get; set; }      public bool ischecked     {         { return _ischecked; }         set         {             _ischecked = value;             raisepropertychanged("ischecked");         }     }     public string titlename     {         { return _title; }         set         {             _title = value;             raisepropertychanged("titlename");         }     } } 

the checks handled correctly small class, can't figure out how have class either call method in main viewmodel class manages other listbox or should.

thanks help!

based on answer of filippo vigani, can following if check/uncheck checkbox mouse,

        <listbox.itemtemplate>             <datatemplate>                 <checkbox content="{binding titlename}"                           ischecked="{binding ischecked}"                           command="{binding datacontext.selectionchangedcommand, relativesource={relativesource mode=findancestor, ancestortype={x:type window}}}"                           commandparameter="{binding}" />             </datatemplate>         </listbox.itemtemplate> 

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -