c# - Selecting multiple Checkboxes at once -
i'm looking way select multiple checkboxes @ once in wpf. i'm using mvvm pattern without further augments prism. i'm loading data mysql database , binding data grid. want select of tables , add them data grid. solution came creating checkboxes dynamically , binding them isselected property in data grid.
<datagridtemplatecolumn header="" width="auto" canuserresize="false" canuserreorder="false"> <datagridtemplatecolumn.celltemplate> <datatemplate> <checkbox x:name="radiobuttondatabase" ischecked="{binding isselected, updatesourcetrigger=propertychanged}" /> </datatemplate> </datagridtemplatecolumn.celltemplate> </datagridtemplatecolumn> the thing: works. bad thing: each entry in datagrid has manually clicked, isselected updated each object. i'd see solution makes multiselection possible (with shift), , possibly key(space?). other ideas welcome. research on internet didn't yield satisfying solution.
i'd prefer no answers using codebehind, i'm trying stick close strict mvvm possible.
you can define command checkbox in viewmodel(cause hope want binding reflect on isselected property each data item when checked):
<checkbox command="{binding relativesource={relativesource mode=findancestor,ancestortype={x:type datagrid}},path=datacontext.checkedcommand}" .../> viewmodel:
{ checkedcommand = new relaycommand(() => this.checkallcheckboxes()); } public relaycommand checkedcommand { get; set; } public void checkallcheckboxes() { //set isselected true items here } get relay command here
update: define row style datagrid bind isselected property of datagridrow model's property , in command action check if row selected:
<datagrid.rowstyle> <style targettype="{x:type datagridrow}"> <setter property="isselected" value="{binding isrowselected}" /> </style> </datagrid.rowstyle> if want enable/disable on selection add binding checkbox:
isenabled="{binding relativesource={relativesource ancestortype={x:type datagridrow}},path=isselected,mode=oneway}"
Comments
Post a Comment