Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TargetNullValue for Visibility that's bound to a boolean

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?

like image 347
jebar8 Avatar asked Jan 31 '13 18:01

jebar8


1 Answers

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.

like image 132
jebar8 Avatar answered Sep 20 '22 06:09

jebar8