绑定到布尔值的可见性的 TargetNullValue [英] TargetNullValue for Visibility that's bound to a boolean

查看:42
本文介绍了绑定到布尔值的可见性的 TargetNullValue的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 Grid,它的 Visibility 属性使用 Converter 绑定到某个模型的布尔属性:

<Grid Visibility="{Binding ElementName=MyTreeView, Path=SelectedItem.MyBoolProperty, Converter={StaticResource boolToVisConverter}}"><!-- 子元素--></网格>

当我的 TreeView 中的一个元素被选中时效果很好,但如果没有选择任何内容或 TreeView 为空,它默认为可见.我需要默认隐藏它.我试过使用 TargetNullValue=Hidden 但它不起作用.我想我只是不明白 TargetNullValue 属性在这种情况下应该如何工作.

有人知道如何获得我正在寻找的功能吗?

解决方案

我花了几个小时试图解决这个问题.然后,当然,在我发布问题之后,我在 GridBinding 属性上使用 FallbackValue=Hidden 让它工作.>

I have a Grid whose Visibility property is bound to a boolean property of a certain model using a Converter:

<Grid Visibility="{Binding ElementName=MyTreeView, Path=SelectedItem.MyBoolProperty, Converter={StaticResource boolToVisConverter}}">
    <!-- child elements -->
</Grid>

It works great when an element in my TreeView is selected, but if nothing is selected or the TreeView is empty it defaults to being visible. I need it to be hidden by default. I've tried using TargetNullValue=Hidden but it isn't working. I guess I just don't understand how the TargetNullValue property is supposed to work in this situation.

Does anybody have any ideas how to get the functionality I am looking for?

解决方案

I spent hours trying to figure this out. Then, of course, right after I post the question I get it working using FallbackValue=Hidden on the Binding property of the Grid.

这篇关于绑定到布尔值的可见性的 TargetNullValue的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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