Bind DataGridTextColumn Visibility Property in WPF

那年仲夏 提交于 2019-11-29 05:16:00

The DataGridColumn is not actually part of the VisualTree, so bindings on the class cannot find their source

You can set things like the Visibility and Width property in the CellStyle or HeaderStyle of the DataGridColumn, although that isn't quite the same.

The closest I've found to a solution would be to create a Freezable object in your <DataGrid.Resources> that stores the binding, then use that StaticResource in the Visibility binding. It's not a pretty solution, but it's the only one I can find at this time.

You can view of an example of it here

<DataGrid.Resources>
    <local:BindingProxy x:Key="proxy" Data="{Binding IsChecked, 
         ElementName=IncludeFullHist, 
         Converter={StaticResource boolItemsConverter}}" />
</DataGrid.Resources>

<DataGridTextColumn Header="First Name" Binding="{Binding Path=FirstName}"
    Visibility="{Binding Path=Data, Source={StaticResource proxy}}"/>  
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!