public static void StartHideMenuAnimation(UIElement animatableElement, DependencyProperty dependencyProperty, Thickness toValue, Thickness fromValue, double animationDurationSeconds, EventHandler completedEvent) { ThicknessAnimation animation = new ThicknessAnimation(); animation.From = (fromValue); animation.To = (toValue); animation.Duration = TimeSpan.FromSeconds(animationDurationSeconds); animation.DecelerationRatio = 0.9; animation.FillBehavior = FillBehavior.HoldEnd; animation.Completed += delegate(object sender, EventArgs e) { // // When the animation has completed bake final value of the animation // into the property. // // animatableElement.SetValue(dependencyProperty, animatableElement.GetValue(dependencyProperty)); if (completedEvent != null) { completedEvent(sender, e); } }; animation.Freeze(); animatableElement.BeginAnimation(dependencyProperty, animation); }
/// <summary>Gridを表示する</summary> private void VisibleGrid() { // アニメーションの初期設定 var animation = new ThicknessAnimation(); Storyboard.SetTarget(animation, AssociatedObject); Storyboard.SetTargetProperty(animation, new PropertyPath(Grid.MarginProperty)); // マウスが移動してきた時に0.5秒ほどで表示するようにMarginを調整する animation.From = AssociatedObject.Margin; animation.To = new Thickness(0, 0, 0, 0); animation.Duration = TimeSpan.FromMilliseconds(500); animation.Freeze(); // アニメーションをストーリーボードに登録し、処理開始 var story = new Storyboard(); story.Children.Add(animation); story.Begin(); }