I have a datagrid whose ItemsSource
binds to a CollectionViewSource
.
In each column I specify the Path
property of the binding to
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}}"/>