wpf旋转

    技术2022-05-20  46

    Storyboard myStoryboard; Rectangle rect = new Rectangle(); rect.Width = 50; rect.Height = 50; rect.RadiusX = 5; rect.RadiusY = 5; rect.Margin = new Thickness(10); rect.Fill = Brushes.Red; DoubleAnimation myDoubleAnimation = new DoubleAnimation(); myDoubleAnimation.Name = "fan"; myDoubleAnimation.From = 0; myDoubleAnimation.To = 359; myDoubleAnimation.Duration = new Duration(TimeSpan.FromSeconds(5)); myDoubleAnimation.RepeatBehavior = RepeatBehavior.Forever; RotateTransform rotateTransform2 = new RotateTransform(0); rotateTransform2.CenterX = 25; rotateTransform2.CenterY = 25; rect.RenderTransform = rotateTransform2; this.stack.Children.Add(rect); myStoryboard = new Storyboard(); myStoryboard.Children.Add(myDoubleAnimation); Storyboard.SetTargetName(rect, "fan"); Storyboard.SetTargetProperty(myDoubleAnimation, new PropertyPath("(UIElement.RenderTransform).(RotateTransform.Angle)")); rect.Loaded += delegate(object sender, RoutedEventArgs args) { myStoryboard.Begin(rect); };


    最新回复(0)