We had a similar problem the RadTreeListView (based on the RadGridView) when binding a column's GridViewDataColumn.IsVisible to a property in the ViewModel. A workaround was to create a subclass of the RadTreeListView, add a dependency property that in turn was bound to the ViewModel's property, and use the dependency property's property change callback to programmatically update the column's IsVisible property.
BTW, setting a column's IsVisible to False within the xaml to initially hide the column was not working correctly. So we had to remove this from the xaml and programmatically set the IsVisible value to false within an override of OnApplyTemplate in the treeview subclass.
Combining the two is working great for us.
public class CustomTreeListView : RadTreeListView
{
public CustomTreeListView() : base()
{
}
#region DTDColumnVisible Dependency Property
/// <
summary
>
/// Dependency property used for changing the DTDColumn visibility. Binding directly to GridViewDataColumn.IsVisible
/// property does not work. Workaround.
/// </
summary
>
public bool DTDColumnVisible
{
get { return (bool)this.GetValue(DTDColumnVisibleProperty); }
set { SetValue(DTDColumnVisibleProperty, value); }
}
public static readonly DependencyProperty DTDColumnVisibleProperty = DependencyProperty.Register(
"DTDColumnVisible", typeof(bool), typeof(CustomTreeListView), new PropertyMetadata(false, new PropertyChangedCallback(OnDTDColumnVisibleChanged)));
private static void OnDTDColumnVisibleChanged(DependencyObject obj, DependencyPropertyChangedEventArgs args)
{
// Update the DTDColumn visibility
CustomTreeListView treelistview = obj as CustomTreeListView;
if (treelistview != null)
treelistview.Columns["DTDColumn"].IsVisible = (bool)args.NewValue;
}
#endregion DTDColumnVisible Dependency Property
public override void OnApplyTemplate()
{
base.OnApplyTemplate();
this.Columns["DTDColumn"].IsVisible = false;
}
}