2016-09-12 217 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的这些动画功能。 –