2016-09-12 162 views
1

我一些谷歌搜索,如果有漫遊周圍也許故事板XAML代碼轉換爲C#的工具後,不知道,或是否有另一種方式來達到我的目標:將XAML Storyboard轉換爲C#?

我需要後面的代碼,因爲我需要可以控制「財富之輪」將會登上的哪個值,但是用計時器和旋轉事件創建動畫太過於緊張和生澀。

任何關於如何從XAML Blend Storyboards中獲得流暢動畫的建議,但是對於這種類型的事物來說,控制C#是否合適?

<Storyboard x:Key="OnMouseLeftButtonDown1"> 
     <PointAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransformOrigin)" Storyboard.TargetName="DailySpinColoursText_png"> 
      <EasingPointKeyFrame KeyTime="0" Value="0.5,0.5"/> 
      <EasingPointKeyFrame KeyTime="0:0:0.3" Value="0.5,0.5"/> 
      <EasingPointKeyFrame KeyTime="0:0:0.6" Value="0.5,0.5"/> 
      <EasingPointKeyFrame KeyTime="0:0:1" Value="0.5,0.5"/> 
      <EasingPointKeyFrame KeyTime="0:0:1.4" Value="0.5,0.5"/> 
      <EasingPointKeyFrame KeyTime="0:0:1.8" Value="0.5,0.5"/> 
      <EasingPointKeyFrame KeyTime="0:0:2.2" Value="0.5,0.5"/> 
      <EasingPointKeyFrame KeyTime="0:0:2.6" Value="0.5,0.5"/> 
      <EasingPointKeyFrame KeyTime="0:0:3" Value="0.5,0.5"/> 
      <EasingPointKeyFrame KeyTime="0:0:3.4" Value="0.5,0.5"/> 
      <EasingPointKeyFrame KeyTime="0:0:3.8" Value="0.5,0.5"/> 
      <EasingPointKeyFrame KeyTime="0:0:4.2" Value="0.5,0.5"/> 
      <EasingPointKeyFrame KeyTime="0:0:4.6" Value="0.5,0.5"/> 
      <EasingPointKeyFrame KeyTime="0:0:5" Value="0.5,0.5"/> 
     </PointAnimationUsingKeyFrames> 
     <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[2].(RotateTransform.Angle)" Storyboard.TargetName="DailySpinColoursText_png"> 
      <EasingDoubleKeyFrame KeyTime="0" Value="0"/> 
      <EasingDoubleKeyFrame KeyTime="0:0:0.3" Value="100"/> 
      <EasingDoubleKeyFrame KeyTime="0:0:0.6" Value="400"/> 
      <EasingDoubleKeyFrame KeyTime="0:0:1" Value="1100"/> 
      <EasingDoubleKeyFrame KeyTime="0:0:1.4" Value="2600"/> 
      <EasingDoubleKeyFrame KeyTime="0:0:1.8" Value="4600"/> 
      <EasingDoubleKeyFrame KeyTime="0:0:2.2" Value="6100"/> 
      <EasingDoubleKeyFrame KeyTime="0:0:2.6" Value="7300"/> 
      <EasingDoubleKeyFrame KeyTime="0:0:3" Value="8300"/> 
      <EasingDoubleKeyFrame KeyTime="0:0:3.4" Value="8800"/> 
      <EasingDoubleKeyFrame KeyTime="0:0:3.8" Value="9000"/> 
      <EasingDoubleKeyFrame KeyTime="0:0:4.2" Value="9100"/> 
      <EasingDoubleKeyFrame KeyTime="0:0:4.6" Value="9150"/> 
      <EasingDoubleKeyFrame KeyTime="0:0:5" Value="9200"/> 
      <EasingDoubleKeyFrame KeyTime="0:0:5.4" Value="9220"/> 
      <EasingDoubleKeyFrame KeyTime="0:0:5.8" Value="9225"/> 
     </DoubleAnimationUsingKeyFrames> 
    </Storyboard> 

預先感謝您!

PS。我在C#中找到了一些在線旋轉動畫的例子,但我需要它慢慢旋轉起來,然後在動畫開始的中間旋轉得非常快,然後最終進入緩慢而懸疑的結局。隨着我在互聯網上看到的東西,我不知道如何做到這一點。

+0

第一件事是砸RenderTranformOrigin的動畫。它什麼也沒做。 – Clemens

回答

1

您可以在後面的代碼中爲後面的RotateTransform的Angle屬性設置動畫,如下所示。相反,有很多EasingDoubleKeyFrames的,你可能會也可能使用單一的easingFunction:

element.RenderTransformOrigin = new Point(0.5, 0.5); 
element.RenderTransform = new RotateTransform(); 

var animation = new DoubleAnimation 
{ 
    To = 9225, 
    Duration = TimeSpan.FromSeconds(5.8), 
    EasingFunction = new CubicEase { EasingMode = EasingMode.EaseInOut } 
}; 

element.RenderTransform.BeginAnimation(RotateTransform.AngleProperty, animation); 
+0

你真的是最好的,非常感謝你!我將使用你的代碼和難題來理解它的功能,即使它看起來非常簡單。我非常喜歡WPF的這些動畫功能。 –