c# - Binding to child item property -
i have pages view models. page
displaed in frame
using frame.navigationmanager.navigate()
.
in 1 page
have groupbox
child datagrid
. want groupbox
change it's visibility
according items count in datagrid
.
here have:
<groupbox .... visibility="{binding elementname=somedatagrid, path=hasitems, converter={staticresource booleantovisibilityconverter}}"> <datagrid x:name="somedatagrid" isreadonly="true" itemssource="{binding items}"/> </groupbox>
the problem
after changing page
, going have following binding exception
system.windows.data error: 4 : cannot find source binding reference
'elementname=somedatagrid'. bindingexpression:path=hasitems;
i've tried using x:reference
got same problem.
could explain i'm doing wrong?
probably, items
collection empty @ point , makes groupbox
become collapsed. when groupbox
gets collapsed, removes content (the datagrid
) view.
with datagrid
removed view, binding
can no longer find reference, breaks.
if you, i'd bind groupbox
visibility
directly viewmodel property, instead of binding datagrid
.
<groupbox .... visibility="{binding hasitems, converter={staticresource booleantovisibilityconverter}}"> <datagrid x:name="somedatagrid" isreadonly="true" itemssource="{binding items}"/> </groupbox>
in viewmodel:
public bool hasitems { { return items != null && items.count() > 0; } } public ienumerable items { { // ... } set { // ... raisepropertychanged("hasitems"); } }
Comments
Post a Comment