Does anyone know if there is an option to hide a GridViewColumn somehow like this:
One simpler approach, that still uses the concept of setting the columns width to zero but does not have the side effects of using a IValueConverter
(the user can still drag the column wider) is to create a new getter/setter that returns a width based on your ColumnIsVisible
variable and then bind to that:
public double ColumnWidth
{
get
{
if (this.ColumnIsVisible)
{
return 100;
}
else
{
return 0;
}
}
set
{
OnPropertyChanged("ColumnWidth");
}
}
Make your bindings TwoWay and if the user attempts to drag the column wider OnPropertyChanged
will be called and reset the width to 0. You might have to use a binding proxy though for your binding. Also add a call to OnPropertyChanged("ColumnWidth")
when ever ColumnIsVisible is updated :)