WPF BooleanToVisibilityConverter 在 false 时转换为隐藏而不是折叠? [英] WPF BooleanToVisibilityConverter that converts to Hidden instead of Collapsed when false?

查看:45
本文介绍了WPF BooleanToVisibilityConverter 在 false 时转换为隐藏而不是折叠?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法使用现有的 WPF BooleanToVisibilityConverter 转换器,但将 False 值转换为 Hidden 而不是默认的 Collapsed,还是我应该自己编写?我在一个项目中,做这样简单的事情会产生巨大的开销(共享的东西进入一个单独的解决方案,重建/签入/合并过程是一个过度生长的变异过程的庞然大物),所以我更喜欢如果我可以只将一个参数传递给现有的参数,而不是跳过刚才提到的圈套.

Is there a way to use the existing WPF BooleanToVisibilityConverter converter but have False values convert to Hidden instead of the default Collapsed, or should I just write my own? I'm on a project where it's tremendous overhead to do something simple like this (shared stuff goes into a separate solution, and the rebuild/checkin/merge process is an overgrown mutated behemoth of a process), so I'd prefer if I could just pass a parameter to the existing one than to jump through the hoops just mentioned.

推荐答案

不幸的是,它只能转换为 Visible 或 Collapsed,因此您必须自己编写.这是根据Reflector的Convert方法:

Unfortunately, it only converts to Visible or Collapsed, so you'll have to write your own. Here is the Convert method according to Reflector:

public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
    bool flag = false;
    if (value is bool)
    {
        flag = (bool)value;
    }
    else if (value is bool?)
    {
        bool? nullable = (bool?)value;
        flag = nullable.HasValue ? nullable.Value : false;
    }
    return (flag ? Visibility.Visible : Visibility.Collapsed);
}

这篇关于WPF BooleanToVisibilityConverter 在 false 时转换为隐藏而不是折叠?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆