Bddha
Bddha

Reputation: 11

WPF - DataGrid - Hiding DataGridCeckBoxColumn via DataTrigger

I've got a DataGrid in wpf with different columns. I want to change the property "Visibility" of one explicit column via datatrigger, but a cant access the "Style" property.

How can i collapse or hide the hole column?

<DataGrid.Columns>
    <DataGridCheckBoxColumn Binding="{Binding IsChanged, Mode=OneWay}"
                            Header="Changed" 
                            CanUserSort="False">
    </DataGridCheckBoxColumn>

    <!--more columns-->
</DataGrid.Columns>

Upvotes: 1

Views: 686

Answers (1)

Sphinxxx
Sphinxxx

Reputation: 13017

DataGridRow and DataGridCell have Styles, DataGridColumn doesn't. I'm guessing this is because rows and cells are the only things being displayed in the UI. Columns are only used by DataGrid internally to keep track of its rows and cells and their content.

Conveniently, columns do have a Visibility property though, which you can bind on each specific column:

<DataGridCheckBoxColumn Visibility="{Binding ...}"
                        ...

Upvotes: 1

Related Questions