How to Set TargetNullValue to Visibility.Collapsed in Binding
Asked Answered
D

1

8

I'm binding TextBlock.Visiblitiy to something, and I want to set the Binding.TargetNullValue to Collapsed, how can I do it in XAML?

This one How do I set TargetNullValue to a date? does not work in Silverlight. (No x:Static).

Dishonest answered 1/1, 2012 at 11:24 Comment(0)
F
7

This is working for me in SL4:

<TextBlock Text="Text" Visibility="{Binding Foo, TargetNullValue=Collapsed}"/>

Where Foo:

public Visibility? Foo { get; set; }
Falstaffian answered 1/1, 2012 at 12:5 Comment(3)
Hmmm, this is a workaround though it works. As you know, Visibility.Collapsed is a constant, so there should be no instance to refer to it.Dishonest
@PeterLee Well... ok. But maybe I don't fully understand your problem. Why is it just a workaround for you? Could you please update your question with some sample code, XAML to be clear what you are trying to achieve?Falstaffian
I tried your method before, but I misspelled the Collapsed . What a mistake! It's working. Forget my previous comment.Dishonest

© 2022 - 2024 — McMap. All rights reserved.