判断WPF中gridview中的数据是否为空,若为空则不显示该字段方法

时间:2021-09-09 19:32:32

 方法为:

public class BoolVisibleConvert : IValueConverter

    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return StringHelper.IsEmpty(value) ? Visibility.Collapsed : Visibility.Visible;
        }


        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return string.Empty;
        }

    }

前台代码绑定字段代码为:

 <StackPanel Orientation="Horizontal" Visibility="{Binding Class,Converter={StaticResource BoolVisibleConvert}}" >