/// <summary> /// Show or expand popup</summary> /// <param name="dockContent">Dock content</param> internal void ShowPopup(DockContent dockContent) { if (PART_Popup.IsOpen) { if (!((DockedWindow)PART_Popup.Content).HasChild(dockContent)) { ClosePopup(); } else { return; } } ContentSettings settings = dockContent.Settings; switch (Orientation) { case Orientation.Horizontal: PART_Popup.MaxWidth = RenderSize.Width; PART_Popup.MaxHeight = 0.75 * Math.Min(Root.RenderSize.Height, System.Windows.SystemParameters.PrimaryScreenHeight); PART_Popup.Width = RenderSize.Width; PART_Popup.Height = Math.Min(settings.Size.Height + 25, PART_Popup.MaxHeight); break; case Orientation.Vertical: PART_Popup.MaxWidth = 0.75 * Math.Min(Root.RenderSize.Width, System.Windows.SystemParameters.PrimaryScreenWidth); PART_Popup.MaxHeight = RenderSize.Height; PART_Popup.Width = Math.Min(settings.Size.Width + 7, PART_Popup.MaxWidth); PART_Popup.Height = RenderSize.Height; break; } DockedWindow window = new DockedWindow(Root, dockContent); window.Closing += Window_Closing; window.Focused = true; window.IsCollapsed = true; PART_Popup.Content = window; PART_Popup.Tag = dockContent; BooleanAnimationUsingKeyFrames booleanAnimation = new BooleanAnimationUsingKeyFrames(); booleanAnimation.Duration = TimeSpan.FromSeconds(0.1); booleanAnimation.KeyFrames.Add( new DiscreteBooleanKeyFrame( false, // Target value (KeyValue) KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0.0))) // KeyTime ); booleanAnimation.KeyFrames.Add( new DiscreteBooleanKeyFrame( true, // Target value (KeyValue) KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0.1))) // KeyTime ); PART_Popup.IsOpen = true; Root.Focus(dockContent); m_timer.Start(); }
private static void CreateRecoverStoryboard(FrameworkElement element) { var delay = GetWaitForRecover(element); if (delay > TimeSpan.Zero) { var key = element.GetHashCode(); var mt = (element.RenderTransform as MatrixTransform); var to = _origin.ContainsKey(key) ? _origin[key] : new Matrix(); var speed = 10 * 96.0 / 1000.0;//速度 var time = Math.Sqrt(Math.Pow(mt.Matrix.OffsetX - to.OffsetX, 2) + Math.Pow(mt.Matrix.OffsetY - to.OffsetY, 2)) / speed; var animation = new MatrixAnimation() { From = mt.Matrix, To = to, FillBehavior = FillBehavior.HoldEnd, Duration = new Duration(TimeSpan.FromMilliseconds(time)), EasingFunction = new BackEase() { EasingMode = EasingMode.EaseInOut } }; Storyboard.SetTarget(animation, element); Storyboard.SetTargetProperty(animation, new PropertyPath("(0).(1)", FrameworkElement.RenderTransformProperty, MatrixTransform.MatrixProperty)); var booleanAnimation = new BooleanAnimationUsingKeyFrames() { FillBehavior = FillBehavior.Stop }; booleanAnimation.KeyFrames.Add(new DiscreteBooleanKeyFrame(false, TimeSpan.Zero)); booleanAnimation.KeyFrames.Add(new DiscreteBooleanKeyFrame(true, animation.Duration.TimeSpan)); Storyboard.SetTarget(booleanAnimation, element); Storyboard.SetTargetProperty(booleanAnimation, new PropertyPath(UIElement.IsHitTestVisibleProperty)); var opacityAnimation = new DoubleAnimation(0.7, 1, animation.Duration, FillBehavior.Stop); Storyboard.SetTarget(opacityAnimation, element); Storyboard.SetTargetProperty(opacityAnimation, new PropertyPath(UIElement.OpacityProperty)); var s = new Storyboard() { BeginTime = delay }; s.Children.Add(animation); s.Children.Add(booleanAnimation); s.Children.Add(opacityAnimation); s.Completed += (ss, ee) => { _currentScale[key] = 1.0; _recoverStoryboard.Remove(key); }; s.Freeze(); s.Begin(); _recoverStoryboard[key] = s; } }
//public static void AnimateDoubleCubicEase(this Animatable target, DependencyProperty propdp, double toVal, int ms, EasingMode ease, // HandoffBehavior handOff = HandoffBehavior.Compose, int begin = 0) //{ // var anim = new DoubleAnimation(toVal, new Duration(TimeSpan.FromMilliseconds(ms))) { EasingFunction = new CubicEase { EasingMode = ease } }; // if (begin > 0) anim.BeginTime = TimeSpan.FromMilliseconds(begin); // target.BeginAnimation(propdp, anim, handOff); //} public static void AnimateBool(this UIElement target, DependencyProperty propdp, bool fromVal, bool toVal, int ms, HandoffBehavior handOff = HandoffBehavior.Compose) { var anim = new BooleanAnimationUsingKeyFrames(); if (ms > 0) { anim.KeyFrames.Add(new DiscreteBooleanKeyFrame(fromVal, KeyTime.FromTimeSpan(TimeSpan.Zero))); } anim.KeyFrames.Add(new DiscreteBooleanKeyFrame(toVal, KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(ms)))); target.BeginAnimation(propdp, anim, handOff); }
void AnimateClick(Button b) { b.Background = (Brush)Resources["SimulateDownBrush"]; BooleanAnimationUsingKeyFrames a = new BooleanAnimationUsingKeyFrames(); a.Duration = TimeSpan.FromSeconds(0.1); a.KeyFrames.Add(new DiscreteBooleanKeyFrame(true, KeyTime.FromPercent(0))); a.Completed += new EventHandler((s, e) => { b.BeginAnimation(SimulateDownProperty, null); b.ClearValue(Button.BackgroundProperty); }); b.BeginAnimation(SimulateDownProperty, a); }
/// <summary> /// ControlGrid显示与隐藏 /// </summary> /// <param name="isControlPop">是否打开</param> /// <param name="times">动画时间</param> private void CollapsedControl(bool isControlPop, double times = 3.0) { //ObjectAnimationUsingKeyFrames objectAnimationUsingKeyFrames = new ObjectAnimationUsingKeyFrames(); //Duration duration = new Duration(TimeSpan.FromSeconds(3)); //DiscreteObjectKeyFrame discreteObjectKeyFrame = new DiscreteObjectKeyFrame(Visibility.Collapsed); //objectAnimationUsingKeyFrames.Duration = duration; //objectAnimationUsingKeyFrames.KeyFrames.Add(discreteObjectKeyFrame); //AnimationClock clock = objectAnimationUsingKeyFrames.CreateClock(); //ControlGrid.ApplyAnimationClock(VisibilityProperty, clock); BooleanAnimationUsingKeyFrames booleanAnimationUsingKeyFrames = new BooleanAnimationUsingKeyFrames(); Duration duration = new Duration(TimeSpan.FromSeconds(times)); DiscreteBooleanKeyFrame discreteBooleanKeyFrame = new DiscreteBooleanKeyFrame(isControlPop); booleanAnimationUsingKeyFrames.Duration = duration; booleanAnimationUsingKeyFrames.KeyFrames.Add(discreteBooleanKeyFrame); AnimationClock clock = booleanAnimationUsingKeyFrames.CreateClock(); //ControlPop.ApplyAnimationClock(CustomPopupEx.IsOpenProperty, clock); }
public BooleanAnimationUsingKeyFramesExample() { Title = "BooleanAnimationUsingKeyFrames Example"; Background = Brushes.White; Margin = new Thickness(20); // Create a NameScope for this page so that // Storyboards can be used. NameScope.SetNameScope(this, new NameScope()); StackPanel myStackPanel = new StackPanel(); myStackPanel.Orientation = Orientation.Vertical; myStackPanel.Margin = new Thickness(20); // Create a TextBlock to introduce the example. TextBlock myTextBlock = new TextBlock(); myTextBlock.Text = "Click the button to animate its IsEnabled property" + " with aBooleanAnimationUsingKeyFrames animation."; myStackPanel.Children.Add(myTextBlock); // Create the Button that is the target of the animation. Button myButton = new Button(); myButton.Margin = new Thickness(200); myButton.Content = "Click Me"; myStackPanel.Children.Add(myButton); // Assign the Button a name so that // it can be targeted by a Storyboard. this.RegisterName( "AnimatedButton", myButton); // Create a BooleanAnimationUsingKeyFrames to // animate the IsEnabled property of the Button. BooleanAnimationUsingKeyFrames booleanAnimation = new BooleanAnimationUsingKeyFrames(); booleanAnimation.Duration = TimeSpan.FromSeconds(4); // All the key frames defined below are DiscreteBooleanKeyFrames. // Discrete key frames create sudden "jumps" between values // (no interpolation). Only discrete key frames can be used // for Boolean key frame animations. // Value at the beginning is false booleanAnimation.KeyFrames.Add( new DiscreteBooleanKeyFrame( false, // Target value (KeyValue) KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0.0))) // KeyTime ); // Value becomes true after the first second. booleanAnimation.KeyFrames.Add( new DiscreteBooleanKeyFrame( true, // Target value (KeyValue) KeyTime.FromTimeSpan(TimeSpan.FromSeconds(1.0))) // KeyTime ); // Value becomes false after the 2nd second. booleanAnimation.KeyFrames.Add( new DiscreteBooleanKeyFrame( false, // Target value (KeyValue) KeyTime.FromTimeSpan(TimeSpan.FromSeconds(2.0))) // KeyTime ); // Value becomes true after the third second. booleanAnimation.KeyFrames.Add( new DiscreteBooleanKeyFrame( true, // Target value (KeyValue) KeyTime.FromTimeSpan(TimeSpan.FromSeconds(3.0))) // KeyTime ); // Value becomes false after 3 and half seconds. booleanAnimation.KeyFrames.Add( new DiscreteBooleanKeyFrame( false, // Target value (KeyValue) KeyTime.FromTimeSpan(TimeSpan.FromSeconds(3.5))) // KeyTime ); // Value becomes true after the fourth second. booleanAnimation.KeyFrames.Add( new DiscreteBooleanKeyFrame( true, // Target value (KeyValue) KeyTime.FromTimeSpan(TimeSpan.FromSeconds(4.0))) // KeyTime ); // Set the animation to target the IsEnabled property // of the object named "AnimatedButton". Storyboard.SetTargetName(booleanAnimation, "AnimatedButton"); Storyboard.SetTargetProperty( booleanAnimation, new PropertyPath(Button.IsEnabledProperty)); // Create a storyboard to apply the animation. Storyboard myStoryboard = new Storyboard(); myStoryboard.Children.Add(booleanAnimation); // Start the storyboard when the button is clicked. myButton.Click += delegate(object sender, RoutedEventArgs e) { myStoryboard.Begin(this); }; Content = myStackPanel; }