TargetNullValue for Visibility that's bound to a boolean

安稳与你 提交于 2019-12-10 02:56:20

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/14632597/targetnullvalue-for-visibility-thats-bound-to-a-boolean

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!