wpf - DataGrid Column Header binding inside Expander: Binding source not found when expander is collapsed -
i have datagrid has column shown/hidden depending on property. have had no luck in showing/hiding column, ended taking column out , put in separate datagrid , place second datagrid inside expander. header of second datagrid bound the datacontext of expander (or datagrid - same effect, have tried binding containing usercontrol).
<expander expanddirection="right" style="{dynamicresource expanderdirectionright}" isexpanded="{binding showlaterdate}"> <datagrid autogeneratecolumns="false" alternationcount="2" selectionmode="single" itemssource="{binding rows, updatesourcetrigger=propertychanged}" canuserdeleterows="true" canuseraddrows="false" canuserresizecolumns="false" snapstodevicepixels="true" visibility="{binding rows.hascontent, converter={staticresource booleantovisibilityconverter}}" horizontalalignment="left" selectedindex="{binding selectedindex, elementname=budgetdatagrid}"> <datagrid.columns> <datagridtemplatecolumn celltemplate="{staticresource laterdatatemplate}" width="{staticresource widthofvaluecolumns}"> <datagridtemplatecolumn.header> <grid margin="{staticresource marginoftextbox}"> <usercontrols:dateorageeditor date="{binding relativesource={relativesource findancestor, ancestortype={x:type expander}}, path=datacontext.laterdate, updatesourcetrigger=lostfocus}" dateofbirth="{binding relativesource={relativesource findancestor, ancestortype={x:type expander}}, path=datacontext.dateofbirth}" tabindex="11"/> </grid> </datagridtemplatecolumn.header> </datagridtemplatecolumn> </datagrid.columns> </datagrid> </expander>
this well.
problem: bound value shown when usercontrol displayed. if expander expanded! if expander collapsed when usercontrol displayed printed output:
system.windows.data error: 4 : cannot find source binding reference 'relativesource findancestor, ancestortype='system.windows.controls.expander', ancestorlevel='1''. bindingexpression:path=datacontext.dateofbirth; dataitem=null; target element 'dateorageeditor' (name='usercontrol'); target property 'dateofbirth' (type 'datetime') system.windows.data warning: 4 : cannot find source binding reference 'relativesource findancestor, ancestortype='system.windows.controls.expander', ancestorlevel='1''. bindingexpression:path=datacontext.laterdate; dataitem=null; target element 'dateorageeditor' (name='usercontrol'); target property 'date' (type 'datetime')
when expander expanded binding not updated , continues 'broken'.
question: how binding bind correctly when expander not expanded?
just found way of binding visibility of column (http://www.thomaslevesque.com/2011/03/21/wpf-how-to-bind-to-data-when-the-datacontext-is-not-inherited/) has reintroduced same problem expander. easy fix, use same kind of binding header-content visibility.
Comments
Post a Comment