WPF: How to hide GridViewColumn using XAML?

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

I have the following object in App.xaml


        
            

        
10条回答
  •  生来不讨喜
    2020-12-05 10:33

    
                                
                                    
                                
                                
                                    
                                    
                                
                                
                                    
                                        
                                            
                                        
                                    
                                
                            
    

    class BooleanToWidthConverter :IValueConverter {

        public object Convert (object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value is bool b)
            {
                return b ? parameter : 0;
            }
            return 0;
        }
    
        public object ConvertBack (object value, Type targetType, object parameter, CultureInfo culture)
        {
            return null;
        }
    }
    

    Unfortunately, there is no "IsVisible" Property in GridViewColumn But, I have a solution can solve this problem by simple and complete way:

    1. Setting width to 0. Many Dev just stop at this step, because it seems to have been hidden but not. We still make it extendible hence bringing it back on the UI by resize column, so we need to do more step 2.
    2. Disable resize GridViewColumn by set GridViewColumnHeader IsEnabled = false.

    Code sample above:

提交回复
热议问题