c# - DataGridTextColumn Visibility Binding -
c# - DataGridTextColumn Visibility Binding -
i'm trying bind column visibility of element this:
<window x:class="wpfapplication1.mainwindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" title="mainwindow" height="350" width="525"> <window.resources> <booleantovisibilityconverter x:key="booleantovisibilityconverter" /> </window.resources> <stackpanel> <checkbox x:name="chkcolumnvisible" content="show column" /> <datagrid x:name="mydatagrid" autogeneratecolumns="false"> <datagrid.columns> <datagridtextcolumn header="column1" visibility="{binding elementname=chkcolumnvisible, path=ischecked, converter={staticresource booleantovisibilityconverter}}"/> </datagrid.columns> </datagrid> </stackpanel>
but error in vs output:
system.windows.data error: 2 : cannot find governing frameworkelement or frameworkcontentelement target element. bindingexpression:path=ischecked; dataitem=null; target element 'datagridtextcolumn' (hashcode=48860040); target property 'visibility' (type 'visibility')
is there pure xaml way accomplish this?
the columns of datagrid
abstract objects not appearing in visual or logical tree. cannot utilize elementname
, relativesource
. source
in combination x:reference
should work though:
visibility="{binding source={x:reference chkcolumnvisible}, path=ischecked, converter={staticresource booleantovisibilityconverter}}"
c# wpf xaml wpfdatagrid
Comments
Post a Comment