Reputation: 491
I have the following problem,
I have a cascade of Items that can be selected by a user.
So for example I have an list of items A, an item from this list can be selected and is available via the property SelectedA.
Each A holds a list of items B. Each of those can selected, thus A provides a property SelectedB.
An item B then has a property which is boolean value C
Now I can bind directly to C by doing somthing like this.
Visibility="{Binding SelectedA.SelectedB.C, Converter={StaticResource BooleanToVisibilityConverter}}"
Now as you can see I use a converter to set the visibility. The problem is however, as long as there is no A and B selected, the converter will not be used. Therefor the Visibiltiy will still be set to visible.
To prevent that I would be forced to wrap the items in another GUI item so that I can then check for null values of the selected Items.
So I would have to make to wrap elements in this case for SelectedA to check if that is null and have a visibility to boolean converter and then another wrap element for SelectedB to see of that is also null. Only then could I use the actual element and the binding.
Is there anyway to force the converter to trigger with a null value, so the visibility will be set correctly ?
Upvotes: 0
Views: 59
Reputation: 5944
You can use TargetNullValue
on the binding to provide a default value when the binded value is null
. You can use FallbackValue
to provide a value when the binding fails. Set either one or both to Visibility.Collapsed
or Visibility.Hidden
according to your requirements.
Upvotes: 1