c# - Access checkbox in wpf datagrid header -
hei,
i need help figuring out how access checkbox in wpf datagrid header. here's have:
<datagrid.columns> <datagridtemplatecolumn canuserreorder="false" canuserresize="false"> <datagridtemplatecolumn.headertemplate> <datatemplate> <checkbox name="cbxall" checked="checkbox_checked" unchecked="checkbox_unchecked" horizontalcontentalignment="center" verticalcontentalignment="center" horizontalalignment="center" verticalalignment="center" /> </datatemplate> </datagridtemplatecolumn.headertemplate> <datagridtemplatecolumn.celltemplate> <datatemplate> <checkbox ischecked="{binding path=checked, updatesourcetrigger=propertychanged}" isenabled="{binding path=noerrors}" name="thecheckbox" horizontalcontentalignment="center" verticalcontentalignment="center" horizontalalignment="center" verticalalignment="center" /> </datatemplate> </datagridtemplatecolumn.celltemplate> </datagridtemplatecolumn> </datagrid.columns>
i have set name
checkbox, reason cant access on code side.
i need access checkbox uncheck after refresh datagrid items. how can this?
allthough binding might way should go, possible ask. here's 1 way of doing it:
1.give header checkbox
uid
<checkbox uid="checkall" />
2.name datagrid
<datagrid name="mydatagrid" />
3.implement next extension method
public static uielement finduid(this dependencyobject parent, string uid) { var count = visualtreehelper.getchildrencount(parent); if (count == 0) homecoming null; (int = 0; < count; i++) { var el = visualtreehelper.getchild(parent, i) uielement; if (el == null) continue; if (el.uid == uid) homecoming el; el = el.finduid(uid); if (el != null) homecoming el; } homecoming null; }
4.access , uncheck checkbox
in code behind this
checkbox checkbox = mydatagrid.finduid("checkall") checkbox; checkbox.ischecked = false;
c# wpf datagrid
No comments:
Post a Comment