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).

Community
  • 1
  • 1
Peter Lee
  • 12,931
  • 11
  • 73
  • 100

1 Answers1

7

This is working for me in SL4:

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

Where Foo:

public Visibility? Foo { get; set; }
nemesv
  • 138,284
  • 16
  • 416
  • 359
  • 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. – Peter Lee Jan 01 '12 at 19:28
  • @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? – nemesv Jan 01 '12 at 20:58
  • 1
    I tried your method before, but I misspelled the `Collapsed` . What a mistake! It's working. Forget my previous comment. – Peter Lee Jan 01 '12 at 23:39