WPF: How to hide GridViewColumn using XAML?

后端 未结 10 681
北海茫月
北海茫月 2020-12-05 09:59

I have the following object in App.xaml


        
            

        
10条回答
  •  悲&欢浪女
    2020-12-05 10:50

    In a small utility I wrote, I have a list view where the user can hide/show some columns. There is no Visibility property on the columns, so I decided to set the hidden columns width to zero. Not ideal, as the user can still resize them and make them visible again.

    Anyway, to do this, I used:

    
        
            
            
        
    
    

    IsThreadIdShown is bound to a check box on the toolbar. And the multi-value converter is:

    public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) {
        if (values.Length != 2) {
            return null;
        }
    
        object o0 = values[0];
        object o1 = values[1];
    
        if (! (o1 is bool)) {
            return o0;
        }
        bool toBeDisplayed = (bool) o1;
        if (! toBeDisplayed) {
            return 0.0;
        }
    
        if (! (o0 is double)) {
            return 0;
        }
    
        return (double) o0;
    }
    
    public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture) {
    
        return new object[] { (double)value, Binding.DoNothing };
    }
    

提交回复
热议问题