Bind DataGridTextColumn Visibility Property in WPF

后端 未结 1 766
余生分开走
余生分开走 2020-12-17 06:25

I have a datagrid whose ItemsSource binds to a CollectionViewSource.
In each column I specify the Path property of the binding to

相关标签:
1条回答
  • 2020-12-17 06:57

    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}}"/>  
    
    0 讨论(0)
提交回复
热议问题