views:

385

answers:

1

I want to make a Style that can be applied to a TextBlock to create a loading text control. All I want is for the text's opacity to pulse from 0 to 1 and back until I hide the control.

I know how to set up the double animation on the opacity, but I don't know how to attach the storyboard to the textblock in a style.

Can this be done? If so, how would you do it?

Thanks!

+1  A: 

Here is a simple example (although ordinarily I'd put storyboards in a resource).

<TextBlock x:Name="txt" Text="Hello World">
  <TextBlock.Triggers>
     <EventTrigger RoutedEvent="TextBlock.Loaded">
       <BeginStoryboard>
         <Storyboard>
           <DoubleAnimation Storyboard.TargetName="txt"  
             Storyboard.TargetProperty="Opacity"  
             From="1.0" To="0.0" Duration="0:0:1" AutoReverse="True"  
             RepeatBehavior="Forever"
           />
         </Storyboard>       
       </BeginStoryboard>
     </EventTrigger>
   </TextBlock.Triggers>
 </TextBlock>

BTW, Just in case, yes general richness of Triggers as found in WPF is not supported in Silverlight but the Loaded event is a special case.

AnthonyWJones