Property Foo
is in my DataContext
ViewModel {
Visibility Foo;
}
But I cannot figure out how to access Foo
inside a Column
. In this case, I assume it's probably looking for Foo
in whatever object is bound to the DataGrid
ItemsSource
<DataGrid Visibility="{Binding Foo}"> // works
<DataGrid.Columns>
<DataGridTextColumn Visibility="{Binding Foo}" /> // fails
I have tried
Binding="{Binding DataContext.Foo}"
And a bunch of things with RelativeSource
tags as well.
Also, is there some way to view and select a property to bind to from a GUI?
Edit: It turns out that the Columns themselves are not FrameworkElements, so they cannot locate the DataGrid ancestor. You can however use the technique in the answer below to bind properties of the CellTemplate of the Column to the DataContext.