开发者

silverlight textblock animation style

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开发者_StackOverflow attach the storyboard to the textblock in a style.

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

Thanks!


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜