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

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

问题描述

有没有一种方法使用现有的WPF BooleanToVisibilityConverter转换器,但有假值转换为隐藏,而不是崩溃了默认值,或应我只是写我自己?我在一个项目中,这是巨大的开销,像这样简单的东西(共享的东西进入一个单独的解决方案,并重建/签/合并的过程是一个过程的一个杂草丛生的变异巨兽),所以我倒是preFER如果我能一个参数仅仅传递给现有的,而不是通过跳箍刚才提到的。

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.

推荐答案

不幸的是,它只能转换为可见或折叠,所以你必须写自己的。下面是根据反射转换方法:

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.Hidden);
}

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

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