IBRA IBRA - 4 years ago 142
C# Question

Show/Hide all datagrid columns from datacontext wpf

I need to change the

Datagrid columns
context menu
inside the header. All the columns visibility were set inside the XAML code by default.

<DataGridTextColumn Visibility="Visible" Binding="{Binding Story}" Header="Story" />

I don't want to bind each column visibility from the ViewModel.
I want is to set all the columns visibility to Visible if all of the columns were hidden, and vice versa. all from the XAML code without binding the visibility inside the column code.

mm8 mm8
Answer Source

I've added an empty column as a temporary solution and removed it when showing one or more columns, I've achieved what I wanted using the click event, by looping through all the columns and set their visibility. but I'm looking for a solution using Only XAML code.

MVVM is not about eliminating code. It is about separation of concerns. And XAML is a markup language. It is perfectly fine to add code to hide/display columns of a DataGrid in the control itself or in the view.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download