2017-09-01 118 views
0

我想在使用DoubleAnimationUsingKeyFrames和StoryBoard的wpf中創建一個加載器圖像,但我得到這個錯誤 無法解析屬性路徑'(0)中的所有屬性引用。(1)[ 0]。(RotateTransform)」。驗證適用的對象是否支持這些屬性。wpf使用TransformGroup和故事板的圖像動畫

這是我的代碼

<UserControl.Resources> 
    <Storyboard x:Key="LoaderAnimation"> 
     <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(RotateTransform)" 
            Storyboard.TargetName="canvas" 
            RepeatBehavior="Forever"> 
      <EasingDoubleKeyFrame KeyTime="0" Value="0"/> 
      <EasingDoubleKeyFrame KeyTime="0:0:3" Value="360"/> 
     </DoubleAnimationUsingKeyFrames> 
    </Storyboard> 
</UserControl.Resources> 
<i:Interaction.Triggers> 
    <i:EventTrigger EventName="Loaded"> 
     <ei:ControlStoryboardAction Storyboard="{StaticResource LoaderAnimation}"/> 
    </i:EventTrigger> 
</i:Interaction.Triggers> 

<Viewbox x:Name="LayoutRoot" HorizontalAlignment="Left" VerticalAlignment="Top"> 
    <Canvas x:Name="canvas" Height="323" Width="308" RenderTransformOrigin="0.5,0.5"> 
     <Canvas.RenderTransform> 
      <TransformGroup></TransformGroup> 
     </Canvas.RenderTransform> 
     <Ellipse Fill="{Binding Foreground, ElementName=ProgressRing}" 
      Height="71" Canvas.Left="121" Canvas.Top="21" Width="69" Opacity="0.3"/> 
     <Ellipse Fill="{Binding Foreground, ElementName=userControl}" 
      Height="71" Width="69" Canvas.Left="194" Canvas.Top="52" Opacity="0.4"/> 
     <Ellipse Fill="{Binding Foreground, ElementName=userControl}" 
      Width="69" Height="71" Canvas.Left="221" Canvas.Top="123" Opacity="0.5"/> 
     <Ellipse Fill="{Binding Foreground, ElementName=userControl}" 
      Width="69" Height="71" Canvas.Left="190" Canvas.Top="198" Opacity="0.6"/> 
     <Ellipse Fill="{Binding Foreground, ElementName=userControl}" 
      Height="71" Canvas.Left="121" Canvas.Top="226" Width="69" Opacity="0.7"/> 
     <Ellipse Fill="{Binding Foreground, ElementName=userControl}" 
      Width="69" Height="71" Canvas.Left="48" Canvas.Top="194" Opacity="0.8"/> 
     <Ellipse Fill="{Binding Foreground, ElementName=userControl}" 
      Height="71" Width="69" Canvas.Left="17" Canvas.Top="123" Opacity="0.9"/> 
     <Ellipse Fill="{Binding Foreground, ElementName=userControl}" 
      Height="71" Width="69" Canvas.Left="48" Canvas.Top="52" Opacity="1.0"/> 
    </Canvas> 
</Viewbox> 

回答

1

既然要動畫RotateTransform的Angle屬性,目標屬性路徑應該是這樣的:

Storyboard.TargetProperty= 
    "(UIElement.RenderTransform).(TransformGroup.Children)[0].(RotateTransform.Angle)" 

或更短:

Storyboard.TargetProperty="RenderTransform.Children[0].Angle" 

然而,你將不得不添加一個實際的RotateTransform實例e將的TransformGroup:

<Canvas.RenderTransform> 
    <TransformGroup> 
     <RotateTransform /> 
    </TransformGroup> 
</Canvas.RenderTransform> 

如果你沒有在組中的任何其它變換,你不妨這樣寫:

<Canvas.RenderTransform> 
    <RotateTransform /> 
</Canvas.RenderTransform> 

並更改目標屬性路徑:

Storyboard.TargetProperty="RenderTransform.Angle" 
+0

裏面加入去掉了錯誤謝謝@Clemens – Shelly