i have xaml below. not able bind chkextract checkbox chkheaderextract. want chkheaderextract ischecked="{binding elementname=chkextract" , on}. unable access chkextract name. unable access chkextract control anywhere in cs file. me how do binding.
<datagrid x:name="dgentities" frozencolumncount="13" isreadonly="true" maxwidth="854" height="444" canuseraddrows="false" selecteditem="{binding getselectedrow,mode=twoway,notifyontargetupdated=true}" itemssource="{binding jobentitiescollectionviewsource.view, mode=oneway, notifyontargetupdated=true}" autogeneratecolumns="false"> <datagrid.columns> <datagridtextcolumn binding="{binding name}" header="entity" width="202" maxwidth="202" minwidth="202"/> <datagridtemplatecolumn header="status" width="138" maxwidth="138" minwidth="138"> <datagridtemplatecolumn.celltemplate> <datatemplate> <button margin="5" content="{binding extractstatus, mode=twoway, notifyontargetupdated=true}" command="{binding datacontext.hyperlinkcommand, relativesource={relativesource findancestor, ancestortype={x:type datagrid}}}" commandparameter="{binding selecteditem, elementname=dgentities}" cursor="hand" mousedoubleclick="control_onmousedoubleclick" > <button.template> <controltemplate targettype="{x:type button}"> <textblock style="{staticresource txtblkstyleextract}" textdecorations="none"><inlineuicontainer> <contentpresenter /> </inlineuicontainer></textblock> </controltemplate> </button.template> </button> </datatemplate> </datagridtemplatecolumn.celltemplate> </datagridtemplatecolumn> <datagridtemplatecolumn width="40" maxwidth="40" minwidth="40"> <datagridtemplatecolumn.header> <checkbox x:name="chkheaderextract" width="26" command="{binding datacontext.headerextractcommand,relativesource={relativesource findancestor,ancestortype={x:type datagrid}},mode=oneway}" commandparameter="{binding ischecked,relativesource={relativesource self}}" ischecked="{binding datacontext.extractheadercheck,relativesource={relativesource findancestor,ancestortype={x:type datagrid}},mode=twoway}" /> </datagridtemplatecolumn.header> <datagridtemplatecolumn.celltemplate> <datatemplate> <checkbox x:name="chkextract" horizontalalignment="center" verticalalignment="center" command="{binding datacontext.individualextractcommand,relativesource={relativesource findancestor,ancestortype={x:type datagrid}},mode=oneway}" commandparameter="{binding ischecked,relativesource={relativesource self}}" ischecked="{binding extractisselected, mode=twoway, notifyontargetupdated=true, updatesourcetrigger=propertychanged}" /> </datatemplate> </datagridtemplatecolumn.celltemplate> </datagridtemplatecolumn> </datagrid.columns> </datagrid>
the problem chkextract inside of datatemplate, means has no knowledge of names outside of it.
this means items named within datatemplate can't seen in .cs file (code-behind)
the best way checkboxes affecting 1 via viewmodel; bind chkextract.ischecked properties of objects in collection grid uses, , bind header's chkheaderextract.ischecked property on datagrid's viewmodel. way, can control interaction using c# code in viewmodel.
Comments
Post a Comment