0

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.

5
  • Sounds like you need to create a class that implements IValueConverter that takes your model and returns the appropriate visiblity value Commented Feb 5, 2017 at 11:50
  • How are you supposed to be able to show the context menu if the entire column is hidden? Commented Feb 5, 2017 at 14:23
  • @mm8 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. (not for adding the empty column) since this is not MVVM approach. Commented Feb 5, 2017 at 14:36
  • 1
    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. Commented Feb 5, 2017 at 14:51
  • @mm8 Thanks, I just made a quick research based on your comment, and you're absolutely right. Thank you :) Commented Feb 5, 2017 at 15:06

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.