Reputation: 1792
I need to change the Datagrid columns
visibility
from 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.
Upvotes: 0
Views: 302
Reputation: 169320
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.
Upvotes: 1