我发现下面的代码可以让我的图像(Indicator1)旋转。
但我按下按钮就什么都没发生了。
有人知道怎么解决吗?
private void Button_Click(object sender, RoutedEventArgs e)
{
RotateTransform rotateTransform = indicator1.RenderTransform as RotateTransform;
DoubleAnimation doubleAnimation = new DoubleAnimation();
doubleAnimation.From = 0;
doubleAnimation.To = 360;
doubleAnimation.Duration = new Duration(TimeSpan.FromMilliseconds(10000));
Storyboard.SetTarget(doubleAnimation, rotateTransform);
Storyboard.SetTargetProperty(doubleAnimation, new PropertyPath(RotateTransform.AngleProperty));
Storyboard storyboard = new Storyboard();
storyboard.RepeatBehavior = RepeatBehavior.Forever;
storyboard.Children.Add(doubleAnimation);
storyboard.Begin(this);
}发布于 2017-05-03 15:12:06
你不需要Storyboard。使用Storyboard来自requires a workaround to get the target name lookup to to work后面的代码。我没有研究这件事的确切原因,也不知道这是否一直是个问题。下面的代码有效。
请注意,您现在将在RepeatBehavior上设置DoubleAnimation。
private void Button_Click(object sender, RoutedEventArgs e)
{
RotateTransform rotateTransform = indicator1.RenderTransform as RotateTransform;
DoubleAnimation doubleAnimation = new DoubleAnimation();
doubleAnimation.From = 0;
doubleAnimation.To = 360;
doubleAnimation.Duration = new Duration(TimeSpan.FromMilliseconds(10000));
doubleAnimation.RepeatBehavior = RepeatBehavior.Forever;
rotateTransform.BeginAnimation(RotateTransform.AngleProperty, doubleAnimation);
}https://stackoverflow.com/questions/43763771
复制相似问题