2011-11-07 49 views
1

我有一個組件與我動畫來回的不透明度,用戶控件中的動畫

我該如何直接運行動畫?

這是我的動畫資源?

<RadioButton.Resources> 
    <Style x:Key="PhoneRadioButtonCheckBoxBase" TargetType="ToggleButton"> 
     <Setter Property="Background" Value="{StaticResource PhoneRadioCheckBoxBrush}"/> 
     <Setter Property="BorderBrush" Value="{StaticResource PhoneRadioCheckBoxBrush}"/> 
     <Setter Property="FontSize" Value="{StaticResource PhoneFontSizeMedium}"/> 
     <Setter Property="FontFamily" Value="{StaticResource PhoneFontFamilyNormal}"/> 
     <Setter Property="HorizontalContentAlignment" Value="Left"/> 
     <Setter Property="VerticalContentAlignment" Value="Center"/> 
     <Setter Property="Padding" Value="1"/> 
    </Style> 
    <Style x:Key="RectToggleButton" TargetType="RadioButton"> 
     <Setter Property="Template"> 
      <Setter.Value> 
       <ControlTemplate TargetType="RadioButton"> 
        <Grid x:Name="grid" Background="Transparent" Loaded="grid_Loaded"> 
         <Grid.Resources> 
          <Storyboard x:Name="Strobing" AutoReverse="True" RepeatBehavior="Forever"> 
           <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="HighlightedSprite"> 
            <EasingDoubleKeyFrame KeyTime="0:0:1" Value="0.495"/> 
            <EasingDoubleKeyFrame KeyTime="0:0:2" Value="1"/> 
           </DoubleAnimationUsingKeyFrames> 
          </Storyboard> 
         </Grid.Resources> 
+1

不知道你的 「運行動畫馬上」 的意思。你的意思是一旦控制立即運行動畫? – danbord

+0

是的,這就是我想要的 –

回答

1

這可能工作: -

    <Grid x:Name="grid" Background="Transparent" > 
         <Grid.Triggers> 
           <EventTrigger RoutedEvent="RadioButton.Loaded"> 
            <BeginStoryboard> 
          <Storyboard AutoReverse="True" RepeatBehavior="Forever"> 
           <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="HighlightedSprite"> 
            <EasingDoubleKeyFrame KeyTime="0:0:1" Value="0.495"/> 
            <EasingDoubleKeyFrame KeyTime="0:0:2" Value="1"/> 
           </DoubleAnimationUsingKeyFrames> 
          </Storyboard> 
            </BeginStoryboard> 
           </EventTrigger> 
         </Grid.Triggers> 

或者你可以試試這個: -

   <ControlTemplate TargetType="RadioButton"> 
        <Grid x:Name="grid" Background="Transparent"> 
         <VisualStateManger.VisualStateGroups> 
          <VisualStateGroup x:Name="CommonStates"> 
           <VisualState x:Name="Normal"> 
          <Storyboard AutoReverse="True" RepeatBehavior="Forever"> 
           <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="HighlightedSprite"> 
            <EasingDoubleKeyFrame KeyTime="0:0:1" Value="0.495"/> 
            <EasingDoubleKeyFrame KeyTime="0:0:2" Value="1"/> 
           </DoubleAnimationUsingKeyFrames> 
          </Storyboard> 
           </VisualState> 
         </VisualStateGroup> 
         </VisualStateManger.VisualStateGroups> 
+0

在WP7中沒有觸發器 –

+0

@Joseph:在Silverlight中沒有通用觸發器,但加載事件被視爲特例。據我可以在文檔中看到這個特殊的用法是由WP7 – AnthonyWJones

+0

支持,我解決了它不使用故事板,但使用按鈕的默認/禁用狀態,並右鍵單擊過渡並選擇重複和點擊永遠。 –