2012-02-13 92 views
0

我想在我的一個應用程序中創建一個動畫。動畫UserControl:StoryBoard無法啓動?

該動畫是一個控件,它的資源中定義了一個StoryBoard,並在加載後啓動該StoryBoard。這裏的(有點剝離)XAML:

<UserControl x:Class="LernInsel.Resources.Assets.Water" x:Name="UserControl"> 
    <UserControl.Resources> 
    <Storyboard x:Key="BaseAnimation" x:Name="BaseAnimation" RepeatBehavior="Forever"> 
     <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="waveLeft"> 
      <EasingDoubleKeyFrame KeyTime="0:0:0.3" Value="0"/> 
      <EasingDoubleKeyFrame KeyTime="0:0:1.3" Value="0.45"/> 
      <EasingDoubleKeyFrame KeyTime="0:0:2.3" Value="0"/> 
     </DoubleAnimationUsingKeyFrames> 
     <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="waveRight"> 
      <EasingDoubleKeyFrame KeyTime="0:0:0.3" Value="0"/> 
      <EasingDoubleKeyFrame KeyTime="0:0:1.3" Value="0.45"/> 
      <EasingDoubleKeyFrame KeyTime="0:0:2.3" Value="0"/> 
     </DoubleAnimationUsingKeyFrames> 
     <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="waveLeft_Copy"> 
      <EasingDoubleKeyFrame KeyTime="0" Value="0"/> 
      <EasingDoubleKeyFrame KeyTime="0:0:1" Value="0.39"/> 
      <EasingDoubleKeyFrame KeyTime="0:0:2" Value="0"/> 
     </DoubleAnimationUsingKeyFrames> 
     <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="waveRight_Copy"> 
      <EasingDoubleKeyFrame KeyTime="0" Value="0"/> 
      <EasingDoubleKeyFrame KeyTime="0:0:1" Value="0.39"/> 
      <EasingDoubleKeyFrame KeyTime="0:0:2" Value="0"/> 
     </DoubleAnimationUsingKeyFrames> 
     <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="waveLeft_Copy1"> 
      <EasingDoubleKeyFrame KeyTime="0:0:0.5" Value="0"/> 
      <EasingDoubleKeyFrame KeyTime="0:0:1.5" Value="0.41"/> 
      <EasingDoubleKeyFrame KeyTime="0:0:2.5" Value="0"/> 
     </DoubleAnimationUsingKeyFrames> 
     <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="waveRight_Copy1"> 
      <EasingDoubleKeyFrame KeyTime="0:0:0.5" Value="0"/> 
      <EasingDoubleKeyFrame KeyTime="0:0:1.5" Value="0.41"/> 
      <EasingDoubleKeyFrame KeyTime="0:0:2.5" Value="0"/> 
     </DoubleAnimationUsingKeyFrames> 
     <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="waveLeft_Copy2"> 
      <EasingDoubleKeyFrame KeyTime="0:0:0.9" Value="0"/> 
      <EasingDoubleKeyFrame KeyTime="0:0:1.9" Value="0.35"/> 
      <EasingDoubleKeyFrame KeyTime="0:0:2.9" Value="0"/> 
     </DoubleAnimationUsingKeyFrames> 
     <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="waveRight_Copy2"> 
      <EasingDoubleKeyFrame KeyTime="0:0:0.9" Value="0"/> 
      <EasingDoubleKeyFrame KeyTime="0:0:1.9" Value="0.35"/> 
      <EasingDoubleKeyFrame KeyTime="0:0:2.9" Value="0"/> 
     </DoubleAnimationUsingKeyFrames> 
    </Storyboard> 
    </UserControl.Resources> 
<UserControl.Triggers> 
    <EventTrigger RoutedEvent="FrameworkElement.Loaded"> 
     <BeginStoryboard Storyboard="{StaticResource BaseAnimation}"/> 
    </EventTrigger> 
</UserControl.Triggers> 
    <Grid> 
    <Rectangle x:Name="Background" Fill="#FF0B5FBC" Height="88" VerticalAlignment="Top"/> 
    <Rectangle x:Name="waveLeft" Fill="{DynamicResource ResourceKey=waveBright}" Height="60" Margin="25.5,6,286.5,0" VerticalAlignment="Top" Opacity="0" RenderTransformOrigin="0.5,0.5"/> 
    <Rectangle x:Name="waveRight" Fill="{DynamicResource ResourceKey=waveBright}" Height="60" Margin="308.5,6,3.5,0" VerticalAlignment="Top" Opacity="0" RenderTransformOrigin="0.5,0.5"/> 
    <Rectangle x:Name="waveLeft_Copy" Fill="{DynamicResource ResourceKey=waveBright}" Height="60" Margin="-3.5,15,315.5,0" VerticalAlignment="Top" Opacity="0" RenderTransformOrigin="0.5,0.5"/> 
    <Rectangle x:Name="waveRight_Copy" Fill="{DynamicResource ResourceKey=waveBright}" Height="60" Margin="279.5,15,32.5,0" VerticalAlignment="Top" Opacity="0" RenderTransformOrigin="0.5,0.5"/> 
    <Rectangle x:Name="waveLeft_Copy1" Fill="{DynamicResource ResourceKey=waveBright}" Height="60" Margin="45.5,25,266.5,0" VerticalAlignment="Top" Opacity="0" RenderTransformOrigin="0.5,0.5"/> 
    <Rectangle x:Name="waveRight_Copy1" Fill="{DynamicResource ResourceKey=waveBright}" Height="60" Margin="0,25,-16.5,0" VerticalAlignment="Top" Opacity="0" RenderTransformOrigin="0.5,0.5"/> 
    <Rectangle x:Name="waveLeft_Copy2" Fill="{DynamicResource ResourceKey=waveBright}" Height="60" Margin="-3.5,38,315.5,0" VerticalAlignment="Top" Opacity="0" RenderTransformOrigin="0.5,0.5"/> 
    <Rectangle x:Name="waveRight_Copy2" Fill="{DynamicResource ResourceKey=waveBright}" Height="60" Margin="279.5,38,32.5,0" VerticalAlignment="Top" Opacity="0" RenderTransformOrigin="0.5,0.5"/> 
    </Grid> 
</UserControl> 

當我在我的窗口中創建一個這樣的例子,這看起來很好的設計師,正在顯示甚至動畫。運行時,控件顯示爲單色框(背景色),但動畫從不開始。你看到Blend創建觸發器的方式有什麼問題可能導致它無法工作?

非常感謝!

塞比

+0

我沒有看到任何關鍵幀... – 2012-02-13 13:38:28

+0

對不起,這就是我的意思是剝離...我會更新帖子 – 2012-02-13 13:38:58

回答

0

無法重現此,考慮到waveBright在您UserControl可達的範圍實際上被定義。這可能是該代碼的唯一弱點。

+0

謝謝,這似乎是如此。有時你會遇到最愚蠢的陷阱...... – 2012-02-13 14:06:27