Hide grid row in WPF

前端 未结 8 1487
旧巷少年郎
旧巷少年郎 2020-12-02 15:21

I have a simple WPF form with a Grid declared on the form. This Grid has a bunch of rows:


    

        
8条回答
  •  不知归路
    2020-12-02 15:30

    Row does not have a Visibility property, so as others have said, you need to set the Height. Another option is to use a converter, in case you need this functionality in many views:

        [ValueConversion(typeof(bool), typeof(GridLength))]
        public class BoolToGridRowHeightConverter : IValueConverter
        {
            public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
            {
                return ((bool)value == true) ? new GridLength(1, GridUnitType.Star) : new GridLength(0);
            }
    
            public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
            {    // Don't need any convert back
                return null;
            }
        }
    

    And then in the appropriate view :

    
    

提交回复
热议问题