I'm trying with example from here
http://msdn.microsoft.com/en-us/library/ff407126
I would like to add a control that user can define which columns are visible. Can this be done easily?
I found http://www.thomaslevesque.com/2011/03/21/wpf-how-to-bind-to-data-when-the-datacontext-is-not-inherited/ but it's different since it's not using CollectionView and CollectionViewSource.
Thanks & BR -Matti
It can be done many ways. One way is to edit the Style for DataGrid's column headers. An example of a style for column headers can be found in :
Change WPF DataGrid Column Header Style, Menu Visibility in Code Behind?
Instead of having menu in ControlTemplate like in article above there can be a button like here for the column header:
Button opens popupmenu with 2nd mouse button and click is supposed to remove the column. The button is hidden by default so there has to be trigger to make button visible when mouse moves to column header:
Because all the columns have the button the click event have to sort out which column to hide:
This might not be the best way to do it, but it works.