views:

338

answers:

2

I Have a TextBlock on Silverlight Page.

XAML

 <TextBlock Text="*"  x:Name="HasChangesTextBlock" Foreground="Red" FontSize="14" Visibility="{Binding Path=HasChanges, Converter={StaticResource BooleanToVisibilityConverter}}"
                           Margin="5,0,0,0">

 </TextBlock>

Page loading takes few moments. And before binding is applied I want TextBlock to be collapsed, but default value of Visibility Property is Visible.

Is there way to make TextBlock to be collapsed before binding is applied?

A: 

How about in the constructor of the page, after you've called InitalizeComponent()? Something like this:

public MyClass() 
{
  InitalizeComponent();
  HasChangesTextBlock.Visibility = Visiblility.Collapsed;
}
Gergely Orosz
if we do like that, than binding won't work, cause it will be erased by the new value.
terkri
+2  A: 

I found the solution.

we should just add FallbackValue=Collapsed to the binding expression

That is a breaking change that was introduced in Silverlight 4.

XAML

   <TextBlock Text="*"  x:Name="HasPlayListChangesTextBlock" Foreground="Red" FontSize="14" 
                               Visibility="{Binding Path=HasChanges, Converter={StaticResource BooleanToVisibilityConverter},FallbackValue=Collapsed}">

   </TextBlock>
terkri
In what way is this change a "breaking change"? Its just an improvement in SL4 I don't see how this change breaks any existing code?
AnthonyWJones