private static SplineDoubleKeyFrame CreateFrame(double value, double duration) { SplineDoubleKeyFrame frame = new SplineDoubleKeyFrame(); frame.Value = value; frame.KeyTime = TimeSpan.FromMilliseconds(duration); return frame; }
public void InitializeComponent() { if (_contentLoaded) { return; } _contentLoaded = true; System.Windows.Application.LoadComponent(this, new System.Uri("/VideoRSSViewer;component/VideoPanelEntry.xaml", System.UriKind.Relative)); this.rootScaleTransform = ((System.Windows.Media.ScaleTransform)(this.FindName("rootScaleTransform"))); this.vi = ((System.Windows.Controls.Canvas)(this.FindName("vi"))); this.MouseEnterStoryboard = ((System.Windows.Media.Animation.Storyboard)(this.FindName("MouseEnterStoryboard"))); this.MouseLeaveStoryboard = ((System.Windows.Media.Animation.Storyboard)(this.FindName("MouseLeaveStoryboard"))); this.HorizontalScrollStoryboard = ((System.Windows.Media.Animation.Storyboard)(this.FindName("HorizontalScrollStoryboard"))); this.HorizontalScrollKeyFrame = ((System.Windows.Media.Animation.SplineDoubleKeyFrame)(this.FindName("HorizontalScrollKeyFrame"))); this.VerticalScrollStoryboard = ((System.Windows.Media.Animation.Storyboard)(this.FindName("VerticalScrollStoryboard"))); this.VerticalScrollKeyFrame = ((System.Windows.Media.Animation.SplineDoubleKeyFrame)(this.FindName("VerticalScrollKeyFrame"))); this.MouseDownStoryboard = ((System.Windows.Media.Animation.Storyboard)(this.FindName("MouseDownStoryboard"))); this.MouseUpStoryboard = ((System.Windows.Media.Animation.Storyboard)(this.FindName("MouseUpStoryboard"))); this.ShowDragAndDropButtonStoryboard = ((System.Windows.Media.Animation.Storyboard)(this.FindName("ShowDragAndDropButtonStoryboard"))); this.HideDragAndDropButtonStoryboard = ((System.Windows.Media.Animation.Storyboard)(this.FindName("HideDragAndDropButtonStoryboard"))); this.AddDragAndDropButtonFaceStoryboard = ((System.Windows.Media.Animation.Storyboard)(this.FindName("AddDragAndDropButtonFaceStoryboard"))); this.MoveDragAndDropButtonFaceStoryboard = ((System.Windows.Media.Animation.Storyboard)(this.FindName("MoveDragAndDropButtonFaceStoryboard"))); this.entryImage = ((System.Windows.Controls.Image)(this.FindName("entryImage"))); this.rectangle = ((System.Windows.Shapes.Rectangle)(this.FindName("rectangle"))); this.titleTextShadow = ((System.Windows.Controls.TextBlock)(this.FindName("titleTextShadow"))); this.titleText = ((System.Windows.Controls.TextBlock)(this.FindName("titleText"))); this.backgroundRect_Copy = ((System.Windows.Shapes.Rectangle)(this.FindName("backgroundRect_Copy"))); this.dragAndDropButton = ((System.Windows.Controls.Canvas)(this.FindName("dragAndDropButton"))); this.addButtonFace = ((System.Windows.Shapes.Path)(this.FindName("addButtonFace"))); this.moveButtonFace = ((System.Windows.Shapes.Path)(this.FindName("moveButtonFace"))); }
/// <summary> /// 空间扭曲波动 /// </summary> public void Wave(Point center) { DoubleAnimationUsingKeyFrames d0 = new DoubleAnimationUsingKeyFrames(); SplineDoubleKeyFrame s0 = new SplineDoubleKeyFrame() { KeyTime = TimeSpan.Zero, Value = 70 }; EasingDoubleKeyFrame e0 = new EasingDoubleKeyFrame() { EasingFunction = new SineEase() { EasingMode = EasingMode.EaseOut }, KeyTime = TimeSpan.FromMilliseconds(300), Value = 0 }; d0.KeyFrames.Add(s0); d0.KeyFrames.Add(e0); Storyboard.SetTarget(d0, this); Storyboard.SetTargetProperty(d0, new PropertyPath("(UIElement.Effect).(RippleEffect.Frequency)")); DoubleAnimationUsingKeyFrames d1 = new DoubleAnimationUsingKeyFrames(); SplineDoubleKeyFrame s1 = new SplineDoubleKeyFrame() { KeyTime = TimeSpan.Zero, Value = 0 }; EasingDoubleKeyFrame e1 = new EasingDoubleKeyFrame() { KeyTime = TimeSpan.FromMilliseconds(150), Value = 0.01 }; EasingDoubleKeyFrame e11 = new EasingDoubleKeyFrame() { EasingFunction = new SineEase() { EasingMode = EasingMode.EaseOut }, KeyTime = TimeSpan.FromMilliseconds(300), Value = 0 }; d1.KeyFrames.Add(s1); d1.KeyFrames.Add(e1); d1.KeyFrames.Add(e11); Storyboard.SetTarget(d1, this); Storyboard.SetTargetProperty(d1, new PropertyPath("(UIElement.Effect).(RippleEffect.Amplitude)")); if (waveStoryboard != null) { Wave_Completed(waveStoryboard, null); } center.X = (center.X + offset.X) / mapRoot.BodyWidth; center.Y = (center.Y + offset.Y) / mapRoot.BodyHeight; this.Effect = new WaveRipple() { Phase = 0, Amplitude = 0, Frequency = 0, Center = center }; waveStoryboard = new Storyboard(); waveStoryboard.Children.Add(d0); waveStoryboard.Children.Add(d1); waveStoryboard.Completed += new EventHandler(Wave_Completed); waveStoryboard.Begin(); }
public void InitializeComponent() { if (_contentLoaded) { return; } _contentLoaded = true; System.Windows.Application.LoadComponent(this, new System.Uri("/VideoRSSViewer;component/VideoPanel.xaml", System.UriKind.Relative)); this.LayoutRoot = ((System.Windows.Controls.Canvas)(this.FindName("LayoutRoot"))); this.idleMouseTimer = ((System.Windows.Media.Animation.Storyboard)(this.FindName("idleMouseTimer"))); this.RefreshButtonStoryboard = ((System.Windows.Media.Animation.Storyboard)(this.FindName("RefreshButtonStoryboard"))); this.HorizontalScrollStoryboard = ((System.Windows.Media.Animation.Storyboard)(this.FindName("HorizontalScrollStoryboard"))); this.HorizontalScrollKeyFrame = ((System.Windows.Media.Animation.SplineDoubleKeyFrame)(this.FindName("HorizontalScrollKeyFrame"))); this.HideScrollLeftButtonStoryboard = ((System.Windows.Media.Animation.Storyboard)(this.FindName("HideScrollLeftButtonStoryboard"))); this.ShowScrollLeftButtonStoryboard = ((System.Windows.Media.Animation.Storyboard)(this.FindName("ShowScrollLeftButtonStoryboard"))); this.HideScrollRightButtonStoryboard = ((System.Windows.Media.Animation.Storyboard)(this.FindName("HideScrollRightButtonStoryboard"))); this.ShowScrollRightButtonStoryboard = ((System.Windows.Media.Animation.Storyboard)(this.FindName("ShowScrollRightButtonStoryboard"))); this.backgroundRectangle = ((System.Windows.Shapes.Rectangle)(this.FindName("backgroundRectangle"))); this.entryContainerClip = ((System.Windows.Controls.Canvas)(this.FindName("entryContainerClip"))); this.entryContainer = ((System.Windows.Controls.Canvas)(this.FindName("entryContainer"))); this.dbgText = ((System.Windows.Controls.TextBlock)(this.FindName("dbgText"))); this.scrollLeftButton = ((System.Windows.Controls.Canvas)(this.FindName("scrollLeftButton"))); this.moveButtonFace = ((System.Windows.Shapes.Path)(this.FindName("moveButtonFace"))); this.scrollRightButton = ((System.Windows.Controls.Canvas)(this.FindName("scrollRightButton"))); this.moveButtonFace1 = ((System.Windows.Shapes.Path)(this.FindName("moveButtonFace1"))); this.refreshButton = ((System.Windows.Controls.Canvas)(this.FindName("refreshButton"))); this.refreshButtonRotate = ((System.Windows.Media.RotateTransform)(this.FindName("refreshButtonRotate"))); this.refreshButtonFace1_Copy = ((System.Windows.Shapes.Path)(this.FindName("refreshButtonFace1_Copy"))); this.refreshButtonFace1 = ((System.Windows.Shapes.Path)(this.FindName("refreshButtonFace1"))); }
public static DoubleAnimationUsingKeyFrames GetSmoothAnimation(double start, double end, double duration) { DoubleAnimationUsingKeyFrames anim = new DoubleAnimationUsingKeyFrames(); anim.Duration = new Duration(TimeSpan.FromSeconds(duration)); SplineDoubleKeyFrame p1 = new SplineDoubleKeyFrame(start, KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0.0)), splineStart); anim.KeyFrames.Add(p1); SplineDoubleKeyFrame p2 = new SplineDoubleKeyFrame(end, KeyTime.FromTimeSpan(TimeSpan.FromSeconds(duration)), splineEnd); anim.KeyFrames.Add(p2); return anim; }
public static StoryBoard GetAnimation(ToasterAnimation animation, ref Grid toaster) { Storyboard story = new Storyboard(); SplineDoubleKeyFrame frame = new SplineDoubleKeyFrame(); DoubleAnimation fadein = new DoubleAnimation(0, 1, TimeSpan.FromSeconds(1)); fadein.BeginTime = TimeSpan.FromSeconds(0); Storyboard.SetTargetProperty(fadein, new PropertyPath("(UIElement.Opacity)")); story.Children.Add(fadein); DoubleAnimation fadeout = new DoubleAnimation(1, 0, TimeSpan.FromSeconds(1)); fadeout.BeginTime = TimeSpan.FromSeconds(7); Storyboard.SetTargetProperty(fadeout, new PropertyPath("(UIElement.Opacity)")); story.Children.Add(fadeout); return story; }
public AlertWindow() { InitializeComponent(); // init animation SplineDoubleKeyFrame frame1 = new SplineDoubleKeyFrame(0, KeyTime.FromTimeSpan(TimeSpan.Parse("0:0:0"))); SplineDoubleKeyFrame frame2 = new SplineDoubleKeyFrame(1, KeyTime.FromTimeSpan(TimeSpan.Parse("0:0:1"))); SplineDoubleKeyFrame frame3 = new SplineDoubleKeyFrame(1, KeyTime.FromTimeSpan(TimeSpan.Parse("0:0:1.5"))); _animation = new DoubleAnimationUsingKeyFrames(); _animation.KeyFrames.Add(frame1); _animation.KeyFrames.Add(frame2); _animation.KeyFrames.Add(frame3); _animation.AutoReverse = true; _animation.FillBehavior = FillBehavior.Stop; }
public AnimatedHeaderedContentControl() { DoubleAnimationUsingKeyFrames timeline = new DoubleAnimationUsingKeyFrames(); Storyboard.SetTarget(timeline, this); Storyboard.SetTargetProperty(timeline, new PropertyPath("(FrameworkElement.Width)", new object[0])); this.sizeAnimationWidthKeyFrame = new SplineDoubleKeyFrame(); this.sizeAnimationWidthKeyFrame.KeySpline = new KeySpline { ControlPoint1 = new Point(0.528, 0.0), ControlPoint2 = new Point(0.142, 0.847) }; this.sizeAnimationWidthKeyFrame.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(500.0)); this.sizeAnimationWidthKeyFrame.Value = 0.0; timeline.KeyFrames.Add(this.sizeAnimationWidthKeyFrame); DoubleAnimationUsingKeyFrames frames2 = new DoubleAnimationUsingKeyFrames(); Storyboard.SetTarget(frames2, this); Storyboard.SetTargetProperty(frames2, new PropertyPath("(FrameworkElement.Height)", new object[0])); this.sizeAnimationHeightKeyFrame = new SplineDoubleKeyFrame(); this.sizeAnimationHeightKeyFrame.KeySpline = new KeySpline { ControlPoint1 = new Point(0.528, 0.0), ControlPoint2 = new Point(0.142, 0.847) }; this.sizeAnimationHeightKeyFrame.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(500.0)); this.sizeAnimationHeightKeyFrame.Value = 0.0; frames2.KeyFrames.Add(this.sizeAnimationHeightKeyFrame); this.sizeAnimation.Children.Add(timeline); this.sizeAnimation.Children.Add(frames2); this.sizeAnimation.Completed += new EventHandler(this.SizeAnimation_Completed); this.positionAnimation = new Storyboard(); DoubleAnimationUsingKeyFrames frames3 = new DoubleAnimationUsingKeyFrames(); Storyboard.SetTarget(frames3, this); Storyboard.SetTargetProperty(frames3, new PropertyPath("(Canvas.Left)", new object[0])); this.positionAnimationXKeyFrame = new SplineDoubleKeyFrame(); this.positionAnimationXKeyFrame.KeySpline = new KeySpline { ControlPoint1 = new Point(0.528, 0.0), ControlPoint2 = new Point(0.142, 0.847) }; this.positionAnimationXKeyFrame.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(500.0)); this.positionAnimationXKeyFrame.Value = 0.0; frames3.KeyFrames.Add(this.positionAnimationXKeyFrame); DoubleAnimationUsingKeyFrames frames4 = new DoubleAnimationUsingKeyFrames(); Storyboard.SetTarget(frames4, this); Storyboard.SetTargetProperty(frames4, new PropertyPath("(Canvas.Top)", new object[0])); this.positionAnimationYKeyFrame = new SplineDoubleKeyFrame(); this.positionAnimationYKeyFrame.KeySpline = new KeySpline { ControlPoint1 = new Point(0.528, 0.0), ControlPoint2 = new Point(0.142, 0.847) }; this.positionAnimationYKeyFrame.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(500.0)); this.positionAnimationYKeyFrame.Value = 0.0; frames4.KeyFrames.Add(this.positionAnimationYKeyFrame); this.positionAnimation.Children.Add(frames3); this.positionAnimation.Children.Add(frames4); this.positionAnimation.Completed += new EventHandler(this.PositionAnimation_Completed); }
/// <summary> /// Applies the mouse down behavior. /// </summary> /// <param name="selectedIndex">The selected item index.</param> /// <param name="element">The element of concern.</param> public virtual void ApplyMouseDownBehavior(int selectedIndex, CoolMenuItem element) { if (!BounceEnabled) return; m_mouseCaptured = element.CaptureMouse(); var da = new DoubleAnimationUsingKeyFrames(); var k1 = new SplineDoubleKeyFrame { KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(100)), Value = this.MaxItemHeight * 0.30 }; da.KeyFrames.Add(k1); Storyboard sb = new Storyboard(); Storyboard.SetTarget(da, element); Storyboard.SetTargetProperty(da, new PropertyPath("(UIElement.RenderTransform).(TransformGroup.Children)[0].(TranslateTransform.Y)")); sb.Children.Add(da); sb.Begin(); }
void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target) { switch (connectionId) { case 1: this.ExampleBeginStoryboard = ((System.Windows.Media.Animation.BeginStoryboard)(target)); return; case 2: this.ExampleStoryboard = ((System.Windows.Media.Animation.Storyboard)(target)); return; case 3: this.mySplineKeyFrame = ((System.Windows.Media.Animation.SplineDoubleKeyFrame)(target)); return; case 4: this.myVector3DSplineKeyFrame = ((System.Windows.Media.Animation.SplineDoubleKeyFrame)(target)); return; case 5: this.thePanel = ((System.Windows.Controls.StackPanel)(target)); return; case 6: this.SliderControlPoint1X = ((System.Windows.Controls.Slider)(target)); #line 404 "..\..\..\..\Examples\BezierTimeExample\BezierTimeExample.xaml" this.SliderControlPoint1X.ValueChanged += new System.Windows.RoutedPropertyChangedEventHandler <double>(this.OnSliderChanged); #line default #line hidden return; case 7: this.SliderControlPoint1Y = ((System.Windows.Controls.Slider)(target)); #line 408 "..\..\..\..\Examples\BezierTimeExample\BezierTimeExample.xaml" this.SliderControlPoint1Y.ValueChanged += new System.Windows.RoutedPropertyChangedEventHandler <double>(this.OnSliderChanged); #line default #line hidden return; case 8: this.SliderControlPoint2X = ((System.Windows.Controls.Slider)(target)); #line 412 "..\..\..\..\Examples\BezierTimeExample\BezierTimeExample.xaml" this.SliderControlPoint2X.ValueChanged += new System.Windows.RoutedPropertyChangedEventHandler <double>(this.OnSliderChanged); #line default #line hidden return; case 9: this.SliderControlPoint2Y = ((System.Windows.Controls.Slider)(target)); #line 417 "..\..\..\..\Examples\BezierTimeExample\BezierTimeExample.xaml" this.SliderControlPoint2Y.ValueChanged += new System.Windows.RoutedPropertyChangedEventHandler <double>(this.OnSliderChanged); #line default #line hidden return; case 10: this.keySplineText = ((System.Windows.Controls.TextBlock)(target)); return; case 11: this.SplineIllustrationSegment = ((System.Windows.Media.BezierSegment)(target)); return; case 12: this.SplineControlPoint1Marker = ((System.Windows.Media.EllipseGeometry)(target)); return; case 13: this.SplineControlPoint2Marker = ((System.Windows.Media.EllipseGeometry)(target)); return; case 14: this.SplineProgressTransform = ((System.Windows.Media.TranslateTransform)(target)); return; case 15: this.TimeProgressTransform = ((System.Windows.Media.TranslateTransform)(target)); return; case 16: this.myPerspectiveCamera = ((System.Windows.Media.Media3D.PerspectiveCamera)(target)); return; case 17: this.myHorizontalRotation = ((System.Windows.Media.Media3D.AxisAngleRotation3D)(target)); return; case 18: this.myVerticalRotation = ((System.Windows.Media.Media3D.AxisAngleRotation3D)(target)); return; case 19: this.myTranslateTransform3D = ((System.Windows.Media.Media3D.TranslateTransform3D)(target)); return; } this._contentLoaded = true; }
/// <summary> /// アニメーションを更新します。 /// </summary> private void UpdateAnimation() { _storyboard.Stop(); if (this.Ellipse1 == null) return; if (double.IsNaN(this.ActualWidth)) return; _initialKeyFrame = new DiscreteDoubleKeyFrame(-this.Ellipse1.ActualWidth, KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(0))); var splineDoubleKeyFrame = new SplineDoubleKeyFrame(this.ActualWidth, KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(3000)), new KeySpline(0.3, 0.85, 0.7, 0.15)); _animation0_1.KeyFrames.Clear(); _animation0_2.KeyFrames.Clear(); _animation0_3.KeyFrames.Clear(); _animation0_4.KeyFrames.Clear(); _animation0_5.KeyFrames.Clear(); _animation0_1.KeyFrames.Add(_initialKeyFrame); _animation0_2.KeyFrames.Add(_initialKeyFrame); _animation0_3.KeyFrames.Add(_initialKeyFrame); _animation0_4.KeyFrames.Add(_initialKeyFrame); _animation0_5.KeyFrames.Add(_initialKeyFrame); _animation1.KeyFrames.Clear(); _animation2.KeyFrames.Clear(); _animation3.KeyFrames.Clear(); _animation4.KeyFrames.Clear(); _animation5.KeyFrames.Clear(); _animation1.KeyFrames.Add(splineDoubleKeyFrame); _animation2.KeyFrames.Add(splineDoubleKeyFrame); _animation3.KeyFrames.Add(splineDoubleKeyFrame); _animation4.KeyFrames.Add(splineDoubleKeyFrame); _animation5.KeyFrames.Add(splineDoubleKeyFrame); _storyboard.Begin(); }
private void _AddStoryboard(UIElement panel, double value) { TransformGroup tGroup = new TransformGroup(); TranslateTransform translate = new TranslateTransform(); translate.Y = 0; tGroup.Children.Add(translate); panel.RenderTransform = tGroup; string sbName = (panel as FrameworkElement).Name + "Animation"; if (Resources.Contains(sbName)) { Storyboard sb = Resources[sbName] as Storyboard; DoubleAnimationUsingKeyFrames anim = sb.Children[0] as DoubleAnimationUsingKeyFrames; SplineDoubleKeyFrame keyFrame = anim.KeyFrames[0] as SplineDoubleKeyFrame; keyFrame.Value = -(value); } else { Storyboard sb = new Storyboard(); sb.SetValue(NameProperty, sbName); DoubleAnimationUsingKeyFrames anim = new DoubleAnimationUsingKeyFrames(); sb.Children.Add(anim); Storyboard.SetTargetName(anim, (panel as FrameworkElement).Name); Storyboard.SetTargetProperty(anim, new PropertyPath("(UIElement.RenderTransform).(TransformGroup.Children)[0].(TranslateTransform.Y)")); anim.BeginTime = new TimeSpan(0, 0, 0); SplineDoubleKeyFrame keyFrame = new SplineDoubleKeyFrame(); KeySpline spline = new KeySpline(); spline.ControlPoint1 = new Point(0, 1); spline.ControlPoint2 = new Point(1, 1); keyFrame.KeySpline = spline; keyFrame.KeyTime = new TimeSpan(0, 0, 1); keyFrame.Value = -(value); anim.KeyFrames.Add(keyFrame); Resources.Add(sbName, sb); } }
private void AnimateNow() { if (AnimateScroll && Animation.ShouldAnimate) { KeyTime targetKeyTime = AnimateDuration; KeySpline targetKeySpline = AnimateSpline; DoubleAnimationUsingKeyFrames animateHScrollKeyFramed = new DoubleAnimationUsingKeyFrames(); animateHScrollKeyFramed.Completed += (s, e) => { _isHAnimating = false; }; DoubleAnimationUsingKeyFrames animateVScrollKeyFramed = new DoubleAnimationUsingKeyFrames(); animateVScrollKeyFramed.Completed += (s, e) => { _isVAnimating = false; }; SplineDoubleKeyFrame HScrollKey1 = new SplineDoubleKeyFrame(TargetHorizontalOffset, targetKeyTime, targetKeySpline); SplineDoubleKeyFrame VScrollKey1 = new SplineDoubleKeyFrame(TargetVerticalOffset, targetKeyTime, targetKeySpline); animateHScrollKeyFramed.KeyFrames.Add(HScrollKey1); animateVScrollKeyFramed.KeyFrames.Add(VScrollKey1); _isHAnimating = true; BeginAnimation(HorizontalScrollOffsetProperty, animateHScrollKeyFramed); _isVAnimating = true; BeginAnimation(VerticalScrollOffsetProperty, animateVScrollKeyFramed); //CommandBindingCollection testCollection = CommandBindings; //int blah = testCollection.Count; } else { _isHAnimating = true; HorizontalScrollOffset = TargetHorizontalOffset; _isHAnimating = false; _isVAnimating = true; VerticalScrollOffset = TargetVerticalOffset; _isVAnimating = false; } }
private static void TranslateItem(FrameworkElement element, double delta, int milliseconds, Orientation orientation) { var storyboard = (Storyboard)element.GetValue(s_dragPreviewStoryboardProperty); SplineDoubleKeyFrame keyframe; if (storyboard == null) { var t = new TranslateTransform(); element.RenderTransform = t; keyframe = new SplineDoubleKeyFrame { KeySpline = new KeySpline(0, 0.7, 0.7, 1) }; var animation = new DoubleAnimationUsingKeyFrames(); animation.KeyFrames.Add(keyframe); Storyboard.SetTarget(animation, element); PropertyPath propertyPath; if (orientation == Orientation.Vertical) { propertyPath = new PropertyPath("(RenderTransform).(TranslateTransform.Y)"); } else { propertyPath = new PropertyPath("(RenderTransform).(TranslateTransform.X)"); } Storyboard.SetTargetProperty(animation, propertyPath); storyboard = new Storyboard(); storyboard.Children.Add(animation); element.SetValue(s_dragPreviewStoryboardProperty, storyboard); } else { keyframe = storyboard.Children.Cast<DoubleAnimationUsingKeyFrames>().Single().KeyFrames.Cast<SplineDoubleKeyFrame>().Single(); } keyframe.Value = delta; keyframe.KeyTime = TimeSpan.FromMilliseconds(milliseconds); element.BeginStoryboard(storyboard); }
/// <summary> /// Gets the template parts from the template. /// </summary> public override void OnApplyTemplate() { base.OnApplyTemplate(); FrameworkElement layoutRoot = this.GetTemplateChild(AnimatedExpander.ElementLayoutRoot) as FrameworkElement; if (layoutRoot != null) { if (layoutRoot.Resources.Contains(AnimatedExpander.ElementExpandStoryboard)) { this.expandStoryboard = layoutRoot.Resources[AnimatedExpander.ElementExpandStoryboard] as Storyboard; } if (layoutRoot.Resources.Contains(AnimatedExpander.ElementCollapseStoryboard)) { this.collapseStoryboard = layoutRoot.Resources[AnimatedExpander.ElementCollapseStoryboard] as Storyboard; } this.expandKeyFrame = layoutRoot.FindName(AnimatedExpander.ElementExpandKeyFrame) as SplineDoubleKeyFrame; } this.expandToggleButton = this.GetTemplateChild(AnimatedExpander.ElementExpandToggleButton) as ToggleButton; if (this.expandToggleButton != null) { this.expandToggleButton.Checked += new RoutedEventHandler(this.ExpandToggleButton_Checked); this.expandToggleButton.Unchecked += new RoutedEventHandler(this.ExpandToggleButton_Unchecked); } ContentPresenter contentContentPresenter = this.GetTemplateChild(AnimatedExpander.ElementContentContentPresenter) as ContentPresenter; if (contentContentPresenter != null) { contentContentPresenter.SizeChanged += new SizeChangedEventHandler(this.ContentContentPresenter_SizeChanged); } }
/// <summary> /// Blank Constructor /// </summary> public AnimatedHeaderedContentControl() { this.sizeAnimation = new Storyboard(); DoubleAnimationUsingKeyFrames widthAnimation = new DoubleAnimationUsingKeyFrames(); Storyboard.SetTarget(widthAnimation, this); Storyboard.SetTargetProperty(widthAnimation, new System.Windows.PropertyPath("(FrameworkElement.Width)")); this.sizeAnimationWidthKeyFrame = new SplineDoubleKeyFrame(); this.sizeAnimationWidthKeyFrame.KeySpline = new KeySpline() { ControlPoint1 = new Point(0.528, 0), ControlPoint2 = new Point(0.142, 0.847) }; this.sizeAnimationWidthKeyFrame.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(500)); this.sizeAnimationWidthKeyFrame.Value = 0; widthAnimation.KeyFrames.Add(this.sizeAnimationWidthKeyFrame); DoubleAnimationUsingKeyFrames heightAnimation = new DoubleAnimationUsingKeyFrames(); Storyboard.SetTarget(heightAnimation, this); Storyboard.SetTargetProperty(heightAnimation, new System.Windows.PropertyPath("(FrameworkElement.Height)")); this.sizeAnimationHeightKeyFrame = new SplineDoubleKeyFrame(); this.sizeAnimationHeightKeyFrame.KeySpline = new KeySpline() { ControlPoint1 = new Point(0.528, 0), ControlPoint2 = new Point(0.142, 0.847) }; this.sizeAnimationHeightKeyFrame.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(500)); this.sizeAnimationHeightKeyFrame.Value = 0; heightAnimation.KeyFrames.Add(this.sizeAnimationHeightKeyFrame); this.sizeAnimation.Children.Add(widthAnimation); this.sizeAnimation.Children.Add(heightAnimation); this.sizeAnimation.Completed += new EventHandler(this.SizeAnimation_Completed); this.positionAnimation = new Storyboard(); DoubleAnimationUsingKeyFrames positionXAnimation = new DoubleAnimationUsingKeyFrames(); Storyboard.SetTarget(positionXAnimation, this); Storyboard.SetTargetProperty(positionXAnimation, new System.Windows.PropertyPath("(Canvas.Left)")); this.positionAnimationXKeyFrame = new SplineDoubleKeyFrame(); this.positionAnimationXKeyFrame.KeySpline = new KeySpline() { ControlPoint1 = new Point(0.528, 0), ControlPoint2 = new Point(0.142, 0.847) }; this.positionAnimationXKeyFrame.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(500)); this.positionAnimationXKeyFrame.Value = 0; positionXAnimation.KeyFrames.Add(this.positionAnimationXKeyFrame); DoubleAnimationUsingKeyFrames positionYAnimation = new DoubleAnimationUsingKeyFrames(); Storyboard.SetTarget(positionYAnimation, this); Storyboard.SetTargetProperty(positionYAnimation, new System.Windows.PropertyPath("(Canvas.Top)")); this.positionAnimationYKeyFrame = new SplineDoubleKeyFrame(); this.positionAnimationYKeyFrame.KeySpline = new KeySpline() { ControlPoint1 = new Point(0.528, 0), ControlPoint2 = new Point(0.142, 0.847) }; this.positionAnimationYKeyFrame.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(500)); this.positionAnimationYKeyFrame.Value = 0; positionYAnimation.KeyFrames.Add(this.positionAnimationYKeyFrame); positionXAnimation.FillBehavior = FillBehavior.Stop; positionYAnimation.FillBehavior = FillBehavior.Stop; widthAnimation.FillBehavior = FillBehavior.Stop; heightAnimation.FillBehavior = FillBehavior.Stop; this.positionAnimation.Children.Add(positionXAnimation); this.positionAnimation.Children.Add(positionYAnimation); this.positionAnimation.Completed += new EventHandler(this.PositionAnimation_Completed); }
public override void OnApplyTemplate() { base.OnApplyTemplate(); this.flyoutRoot = this.GetTemplateChild("PART_Root") as Grid; if (this.flyoutRoot == null) { return; } this.flyoutHeader = this.GetTemplateChild("PART_Header") as FrameworkElement; this.flyoutHeader?.ApplyTemplate(); this.flyoutContent = this.GetTemplateChild("PART_Content") as FrameworkElement; this.windowTitleThumb = this.GetTemplateChild("PART_WindowTitleThumb") as Thumb; if (this.windowTitleThumb != null) { this.windowTitleThumb.DragStarted -= this.WindowTitleThumbOnDragStarted; this.windowTitleThumb.DragCompleted -= this.WindowTitleThumbOnDragCompleted; this.windowTitleThumb.PreviewMouseLeftButtonUp -= this.WindowTitleThumbOnPreviewMouseLeftButtonUp; this.windowTitleThumb.DragDelta -= this.WindowTitleThumbMoveOnDragDelta; this.windowTitleThumb.MouseDoubleClick -= this.WindowTitleThumbChangeWindowStateOnMouseDoubleClick; this.windowTitleThumb.MouseRightButtonUp -= this.WindowTitleThumbSystemMenuOnMouseRightButtonUp; var flyoutsControl = this.TryFindParent<FlyoutsControl>(); if (flyoutsControl != null) { this.windowTitleThumb.DragStarted += this.WindowTitleThumbOnDragStarted; this.windowTitleThumb.DragCompleted += this.WindowTitleThumbOnDragCompleted; this.windowTitleThumb.PreviewMouseLeftButtonUp += this.WindowTitleThumbOnPreviewMouseLeftButtonUp; this.windowTitleThumb.DragDelta += this.WindowTitleThumbMoveOnDragDelta; this.windowTitleThumb.MouseDoubleClick += this.WindowTitleThumbChangeWindowStateOnMouseDoubleClick; this.windowTitleThumb.MouseRightButtonUp += this.WindowTitleThumbSystemMenuOnMouseRightButtonUp; } } var thumbContentControl = this.flyoutHeader as IMetroThumb; if (thumbContentControl != null) { thumbContentControl.DragStarted -= this.WindowTitleThumbOnDragStarted; thumbContentControl.DragCompleted -= this.WindowTitleThumbOnDragCompleted; thumbContentControl.PreviewMouseLeftButtonUp -= this.WindowTitleThumbOnPreviewMouseLeftButtonUp; thumbContentControl.DragDelta -= this.WindowTitleThumbMoveOnDragDelta; thumbContentControl.MouseDoubleClick -= this.WindowTitleThumbChangeWindowStateOnMouseDoubleClick; thumbContentControl.MouseRightButtonUp -= this.WindowTitleThumbSystemMenuOnMouseRightButtonUp; var flyoutsControl = this.TryFindParent<FlyoutsControl>(); if (flyoutsControl != null) { thumbContentControl.DragStarted += this.WindowTitleThumbOnDragStarted; thumbContentControl.DragCompleted += this.WindowTitleThumbOnDragCompleted; thumbContentControl.PreviewMouseLeftButtonUp += this.WindowTitleThumbOnPreviewMouseLeftButtonUp; thumbContentControl.DragDelta += this.WindowTitleThumbMoveOnDragDelta; thumbContentControl.MouseDoubleClick += this.WindowTitleThumbChangeWindowStateOnMouseDoubleClick; thumbContentControl.MouseRightButtonUp += this.WindowTitleThumbSystemMenuOnMouseRightButtonUp; } } this.hideStoryboard = this.GetTemplateChild("HideStoryboard") as Storyboard; this.hideFrame = this.GetTemplateChild("hideFrame") as SplineDoubleKeyFrame; this.hideFrameY = this.GetTemplateChild("hideFrameY") as SplineDoubleKeyFrame; this.showFrame = this.GetTemplateChild("showFrame") as SplineDoubleKeyFrame; this.showFrameY = this.GetTemplateChild("showFrameY") as SplineDoubleKeyFrame; this.fadeOutFrame = this.GetTemplateChild("fadeOutFrame") as SplineDoubleKeyFrame; if (this.hideFrame == null || this.showFrame == null || this.hideFrameY == null || this.showFrameY == null || this.fadeOutFrame == null) { return; } this.ApplyAnimation(this.Position, this.AnimateOpacity); }
/// <summary> /// Create DoubleAnimation /// </summary> /// <param name="parentObj">Storyboard parent object</param> /// <param name="target">Animation target object</param> /// <param name="property">Property path to animate</param> /// <param name="beginTime">Animation begin time</param> /// <param name="frameTime">Frame time collection</param> /// <param name="values">Target value collection</param> /// <param name="splines">List of KeySpline</param> /// <returns>DoubleAnimationUsingKeyFrames</returns> internal static DoubleAnimationUsingKeyFrames CreateDoubleAnimation(FrameworkElement parentObj, DependencyObject target, String property, Double beginTime, DoubleCollection frameTime, DoubleCollection values, List<KeySpline> splines) { DoubleAnimationUsingKeyFrames da = new DoubleAnimationUsingKeyFrames(); #if WPF String name = target.GetType().Name + Guid.NewGuid().ToString().Replace('-', '_'); target.SetValue(FrameworkElement.NameProperty, name); Storyboard.SetTargetName(da, target.GetValue(FrameworkElement.NameProperty).ToString()); if (parentObj.GetType().Equals(typeof(DataPoint))) parentObj = (parentObj as DataPoint).Parent; (parentObj as ObservableObject).Chart._rootElement.RegisterName(name, target); #else Storyboard.SetTarget(da, target); #endif Storyboard.SetTargetProperty(da, new PropertyPath(property)); da.BeginTime = TimeSpan.FromSeconds(beginTime); for (Int32 index = 0; index < values.Count; index++) { SplineDoubleKeyFrame keyFrame = new SplineDoubleKeyFrame(); if (splines != null) keyFrame.KeySpline = splines[index]; keyFrame.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(frameTime[index])); keyFrame.Value = values[index]; da.KeyFrames.Add(keyFrame); } return da; }
private static void TranslateItem(FrameworkElement f, double yDelta, int milliseconds) { Storyboard sb = (Storyboard)f.GetValue(s_dragPreviewStoryboardProperty); SplineDoubleKeyFrame k; if (sb == null) { TranslateTransform t; DoubleAnimationUsingKeyFrames d; t = new TranslateTransform(); f.RenderTransform = t; sb = new Storyboard(); k = new SplineDoubleKeyFrame(); k.KeySpline = new KeySpline(0, 0.7, 0.7, 1); d = new DoubleAnimationUsingKeyFrames(); d.KeyFrames.Add(k); Storyboard.SetTarget(d, f); Storyboard.SetTargetProperty(d, new PropertyPath("(RenderTransform).(TranslateTransform.Y)")); sb.Children.Add(d); f.SetValue(s_dragPreviewStoryboardProperty, sb); } else { k = (sb.Children[0] as DoubleAnimationUsingKeyFrames).KeyFrames[0] as SplineDoubleKeyFrame; } k.Value = yDelta; k.KeyTime = TimeSpan.FromMilliseconds(milliseconds); f.BeginStoryboard(sb); }
public override void OnApplyTemplate() { base.OnApplyTemplate(); _root = (Grid) GetTemplateChild("_root"); if (_root == null) return; _header = (ContentPresenter) GetTemplateChild("_header"); _content = (ContentPresenter) GetTemplateChild("_content"); _windowTitleThumb = GetTemplateChild("PART_WindowTitleThumb") as Thumb; if (_windowTitleThumb != null) { _windowTitleThumb.DragDelta -= WindowTitleThumbMoveOnDragDelta; _windowTitleThumb.MouseDoubleClick -= WindowTitleThumbChangeWindowStateOnMouseDoubleClick; _windowTitleThumb.MouseRightButtonUp -= WindowTitleThumbSystemMenuOnMouseRightButtonUp; _windowTitleThumb.DragDelta += WindowTitleThumbMoveOnDragDelta; _windowTitleThumb.MouseDoubleClick += WindowTitleThumbChangeWindowStateOnMouseDoubleClick; _windowTitleThumb.MouseRightButtonUp += WindowTitleThumbSystemMenuOnMouseRightButtonUp; } _hideStoryboard = (Storyboard) GetTemplateChild("HideStoryboard"); _hideFrame = (SplineDoubleKeyFrame) GetTemplateChild("_hideFrame"); _hideFrameY = (SplineDoubleKeyFrame) GetTemplateChild("_hideFrameY"); _showFrame = (SplineDoubleKeyFrame) GetTemplateChild("_showFrame"); _showFrameY = (SplineDoubleKeyFrame) GetTemplateChild("_showFrameY"); _fadeOutFrame = (SplineDoubleKeyFrame) GetTemplateChild("_fadeOutFrame"); if (_hideFrame == null || _showFrame == null || _hideFrameY == null || _showFrameY == null || _fadeOutFrame == null) return; ApplyAnimation(Position, AnimateOpacity); }
private static DoubleKeyFrame CreateDoubleKeyFrmas(KeyFrames<double> Model) { DoubleKeyFrame frame = null; switch (Model.Type) { case KeyFramesType.Spline: frame = new SplineDoubleKeyFrame() { KeySpline = Model.Spline }; break; case KeyFramesType.Linear: frame = new LinearDoubleKeyFrame(); break; case KeyFramesType.Easing: frame = new EasingDoubleKeyFrame() { EasingFunction = Model.EasingFunction }; break; case KeyFramesType.Discrete: frame = new DiscreteDoubleKeyFrame(); break; default: break; } frame.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(Model.KeyTime)); frame.Value = Model.Value; return frame; }
public override void OnApplyTemplate() { base.OnApplyTemplate(); root = (Grid)GetTemplateChild("root"); if (root == null) return; hideStoryboard = (Storyboard)GetTemplateChild("HideStoryboard"); hideFrame = (SplineDoubleKeyFrame)GetTemplateChild("hideFrame"); hideFrameY = (SplineDoubleKeyFrame)GetTemplateChild("hideFrameY"); showFrame = (SplineDoubleKeyFrame)GetTemplateChild("showFrame"); showFrameY = (SplineDoubleKeyFrame)GetTemplateChild("showFrameY"); fadeOutFrame = (SplineDoubleKeyFrame)GetTemplateChild("fadeOutFrame"); if (hideFrame == null || showFrame == null || hideFrameY == null || showFrameY == null || fadeOutFrame == null) return; ApplyAnimation(Position, AnimateOpacity); }
/** * Animation nach einer entfernten Zeile * * Fast wie die animateRemovedLinesHard, nur nicht explosiv. */ private void animateRemovedLinesSoft(List<int> removedLines) { Storyboard sb = new Storyboard(); List<Rectangle> animatedRectangled = new List<Rectangle>(); foreach (int y in removedLines) { for (int i = 0; i < boardModel.getColumns(); i++) { Rectangle rectOnBoard = getRectangleAt(i, y); Rectangle rect = new Rectangle(); rect.Height = rectOnBoard.ActualHeight; rect.Width = rectOnBoard.ActualWidth; rect.Fill = rectOnBoard.Fill; System.Windows.Point p = rectOnBoard.TransformToVisual(this.LayoutRoot).Transform(new System.Windows.Point(0, 0)); canvas.Children.Add(rect); Canvas.SetLeft(rect, p.X + Canvas.GetLeft(LayoutRoot)); Canvas.SetTop(rect, p.Y + Canvas.GetTop(LayoutRoot)); CompositeTransform ct = new CompositeTransform(); ct.CenterX = rect.ActualWidth / 2; ct.CenterY = rect.ActualHeight / 2; rect.RenderTransform = ct; //Bewegung DoubleAnimationUsingKeyFrames dauk = new DoubleAnimationUsingKeyFrames(); Storyboard.SetTargetProperty(dauk, new PropertyPath("(UIElement.RenderTransform).(CompositeTransform.TranslateY)")); Storyboard.SetTarget(dauk, rect); SplineDoubleKeyFrame sdk = new SplineDoubleKeyFrame(); sdk.SetValue(SplineDoubleKeyFrame.ValueProperty, (double)(-1 * rnd.Next(10))); sdk.KeyTime = TimeSpan.FromMilliseconds(rnd.Next(400)); KeySpline ks = new KeySpline(); ks.ControlPoint1 = new System.Windows.Point(0, 1); ks.ControlPoint2 = new System.Windows.Point(1, 1); sdk.KeySpline = ks; dauk.KeyFrames.Add(sdk); SplineDoubleKeyFrame sdk0 = new SplineDoubleKeyFrame(); sdk0.SetValue(SplineDoubleKeyFrame.ValueProperty, (double)rnd.Next(474)); sdk0.KeyTime = TimeSpan.FromMilliseconds(1000); KeySpline ks0 = new KeySpline(); ks0.ControlPoint1 = new System.Windows.Point(1, 0); ks0.ControlPoint2 = new System.Windows.Point(1, 1); sdk0.KeySpline = ks0; dauk.KeyFrames.Add(sdk0); //Drehung //------------------------------- DoubleAnimation da = new DoubleAnimation(); Storyboard.SetTargetProperty(da, new PropertyPath("(UIElement.RenderTransform).(CompositeTransform.Rotation)")); Storyboard.SetTarget(da, rect); da.Duration = new Duration(TimeSpan.FromMilliseconds(1000)); int fac = rnd.Next(2) == 0 ? -1 : 1; da.To = fac * 360.0; da.RepeatBehavior = RepeatBehavior.Forever; //--Opacity DoubleAnimationUsingKeyFrames dauk2 = new DoubleAnimationUsingKeyFrames(); Storyboard.SetTarget(dauk2, rect); Storyboard.SetTargetProperty(dauk2, new PropertyPath("Opacity")); SplineDoubleKeyFrame sdk3 = new SplineDoubleKeyFrame(); sdk3.SetValue(SplineDoubleKeyFrame.ValueProperty, 0.0); KeySpline ks3 = new KeySpline(); ks3.ControlPoint1 = new System.Windows.Point(0, 0.5); ks3.ControlPoint2 = new System.Windows.Point(1, 0.5); sdk3.KeySpline = ks3; sdk3.KeyTime = TimeSpan.FromMilliseconds(1000); dauk2.KeyFrames.Add(sdk3); sb.Children.Add(dauk); sb.Children.Add(da); sb.Children.Add(dauk2); animatedRectangled.Add(rect); } } if (!LayoutRoot.Resources.Contains("unique_id")) { LayoutRoot.Resources.Add("unique_id", sb); } sb.Duration = TimeSpan.FromMilliseconds(1000); sb.Completed += new EventHandler((a, b) => { foreach (var rect in animatedRectangled) { canvas.Children.Remove(rect); } }); sb.Begin(); }
void _SetupYTranslationStoryboard(TranslateTransform transform, string sbName, double translation) { if (Resources.Contains(sbName)) { Storyboard sb = Resources[sbName] as Storyboard; DoubleAnimationUsingKeyFrames anim = sb.Children[0] as DoubleAnimationUsingKeyFrames; SplineDoubleKeyFrame keyFrame = anim.KeyFrames[0] as SplineDoubleKeyFrame; keyFrame.Value = translation; } else { Storyboard sb = new Storyboard(); sb.SetValue(FrameworkElement.NameProperty, sbName); DoubleAnimationUsingKeyFrames anim = new DoubleAnimationUsingKeyFrames(); sb.Children.Add(anim); Storyboard.SetTarget(anim, transform); Storyboard.SetTargetProperty(anim, new PropertyPath("Y")); anim.BeginTime = new TimeSpan(0, 0, 0); SplineDoubleKeyFrame keyFrame = new SplineDoubleKeyFrame(); KeySpline spline = new KeySpline(); spline.ControlPoint1 = new Point(0, 1); spline.ControlPoint2 = new Point(1, 1); keyFrame.KeySpline = spline; keyFrame.KeyTime = new TimeSpan(0, 0, 1); keyFrame.Value = translation; anim.KeyFrames.Add(keyFrame); Resources.Add(sbName, sb); } }
private void ResetRotation_Click(object sender, RoutedEventArgs e) { Storyboard s = new Storyboard(); s.Duration = TimeSpan.FromMilliseconds(500); DoubleAnimationUsingKeyFrames anim = new DoubleAnimationUsingKeyFrames(); SplineDoubleKeyFrame spline = new SplineDoubleKeyFrame() { KeyTime = s.Duration.TimeSpan, Value = 0, KeySpline = new KeySpline() { ControlPoint1 = new System.Windows.Point(0, 0.1), ControlPoint2 = new System.Windows.Point(0.1, 1) } }; anim.KeyFrames.Add(spline); spline.Value = 0; anim.SetValue(Storyboard.TargetPropertyProperty, new PropertyPath("Rotation")); s.Children.Add(anim); Storyboard.SetTarget(anim, Map); s.Completed += (sender2, e2) => { s.Stop(); Map.Rotation = 0; }; s.Begin(); }
/// <summary> /// Create DoubleAnimation /// </summary> /// <param name="target">Animation target object</param> /// <param name="property">Animation target property</param> /// <param name="beginTime">Animation begin time</param> /// <param name="frameTime">Frame time collection</param> /// <param name="values">Target value collection</param> /// <param name="splines">List of KeySpline</param> /// <returns>DoubleAnimationUsingKeyFrames</returns> internal static DoubleAnimationUsingKeyFrames CreateDoubleAnimation(DataSeries dataSeries, DataPoint dataPoint, DependencyObject target, String property, Double beginTime, DoubleCollection frameTime, DoubleCollection values, List<KeySpline> splines) { DoubleAnimationUsingKeyFrames da = new DoubleAnimationUsingKeyFrames(); #if WPF target.SetValue(FrameworkElement.NameProperty, target.GetType().Name + Guid.NewGuid().ToString().Replace('-', '_')); Storyboard.SetTargetName(da, target.GetValue(FrameworkElement.NameProperty).ToString()); dataSeries.Chart._rootElement.RegisterName((string)target.GetValue(FrameworkElement.NameProperty), target); dataPoint.Chart._rootElement.RegisterName((string)target.GetValue(FrameworkElement.NameProperty), target); #else Storyboard.SetTarget(da, target); #endif Storyboard.SetTargetProperty(da, new PropertyPath(property)); da.BeginTime = TimeSpan.FromSeconds(beginTime); for (Int32 index = 0; index < splines.Count; index++) { SplineDoubleKeyFrame keyFrame = new SplineDoubleKeyFrame(); keyFrame.KeySpline = splines[index]; keyFrame.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(frameTime[index])); keyFrame.Value = values[index]; da.KeyFrames.Add(keyFrame); } return da; }
/// <summary> /// Blank Constructor /// </summary> public AnimatedHeaderedContentControl() { _sizeAnimation = new Storyboard(); var widthAnimation = new DoubleAnimationUsingKeyFrames(); Storyboard.SetTarget(widthAnimation, this); Storyboard.SetTargetProperty(widthAnimation, new PropertyPath("(FrameworkElement.Width)")); _sizeAnimationWidthKeyFrame = new SplineDoubleKeyFrame { KeySpline = new KeySpline { ControlPoint1 = new Point(0.528, 0), ControlPoint2 = new Point(0.142, 0.847) }, KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(500)), Value = 0 }; widthAnimation.KeyFrames.Add(_sizeAnimationWidthKeyFrame); var heightAnimation = new DoubleAnimationUsingKeyFrames(); Storyboard.SetTarget(heightAnimation, this); Storyboard.SetTargetProperty(heightAnimation, new PropertyPath("(FrameworkElement.Height)")); _sizeAnimationHeightKeyFrame = new SplineDoubleKeyFrame { KeySpline = new KeySpline { ControlPoint1 = new Point(0.528, 0), ControlPoint2 = new Point(0.142, 0.847) }, KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(500)), Value = 0 }; heightAnimation.KeyFrames.Add(_sizeAnimationHeightKeyFrame); _sizeAnimation.Children.Add(widthAnimation); _sizeAnimation.Children.Add(heightAnimation); _sizeAnimation.Completed += SizeAnimationCompleted; _positionAnimation = new Storyboard(); var positionXAnimation = new DoubleAnimationUsingKeyFrames(); Storyboard.SetTarget(positionXAnimation, this); Storyboard.SetTargetProperty(positionXAnimation, new PropertyPath("(Canvas.Left)")); _positionAnimationXKeyFrame = new SplineDoubleKeyFrame { KeySpline = new KeySpline { ControlPoint1 = new Point(0.528, 0), ControlPoint2 = new Point(0.142, 0.847) }, KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(500)), Value = 0 }; /*EasingDoubleKeyFrame easy = new EasingDoubleKeyFrame() { Value = 1, KeyTime = TimeSpan.FromSeconds(1) }; BounceEase cubic = new BounceEase() { EasingMode = EasingMode.EaseOut, Bounces = 2, Bounciness = 2}; easy.EasingFunction = cubic; positionXAnimation.KeyFrames.Add(easy);*/ positionXAnimation.KeyFrames.Add(_positionAnimationXKeyFrame); var positionYAnimation = new DoubleAnimationUsingKeyFrames(); Storyboard.SetTarget(positionYAnimation, this); Storyboard.SetTargetProperty(positionYAnimation, new PropertyPath("(Canvas.Top)")); _positionAnimationYKeyFrame = new SplineDoubleKeyFrame { KeySpline = new KeySpline { ControlPoint1 = new Point(0.528, 0), ControlPoint2 = new Point(0.142, 0.847) }, KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(500)), Value = 0 }; positionYAnimation.KeyFrames.Add(_positionAnimationYKeyFrame); _positionAnimation.Children.Add(positionXAnimation); _positionAnimation.Children.Add(positionYAnimation); _positionAnimation.Completed += PositionAnimationCompleted; }
/// <summary> /// Generates a Double animation sequence with fixed parameters /// </summary> /// <param name="target">Animation target object</param> /// <param name="property">Animation target property</param> /// <param name="from">Start value</param> /// <param name="to">End value</param> /// <param name="begin">Animation begin time</param> /// <param name="duration">Animation duration</param> /// <returns>DoubleAnimationUsingKeyFrames</returns> private DoubleAnimationUsingKeyFrames CreateDoubleAnimation(DependencyObject target, String property, Double from, Double to, Double begin, Double duration) { DoubleAnimationUsingKeyFrames da = new DoubleAnimationUsingKeyFrames(); da.BeginTime = TimeSpan.FromSeconds(begin); #if WPF target.SetValue(NameProperty, target.GetType().Name + Guid.NewGuid().ToString().Replace('-', '_')); Storyboard.SetTargetName(da, target.GetValue(NameProperty).ToString()); Chart._rootElement.RegisterName((string)target.GetValue(NameProperty), target); #else Storyboard.SetTarget(da, target); #endif Storyboard.SetTargetProperty(da, new PropertyPath(property)); SplineDoubleKeyFrame keyFrame = new SplineDoubleKeyFrame(); keyFrame.KeySpline = new KeySpline() { ControlPoint1 = new Point(0, 0), ControlPoint2 = new Point(1, 1) }; keyFrame.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0)); keyFrame.Value = from; da.KeyFrames.Add(keyFrame); keyFrame = new SplineDoubleKeyFrame(); keyFrame.KeySpline = new KeySpline() { ControlPoint1 = new Point(0.5, 0), ControlPoint2 = new Point(0.5, 1) }; keyFrame.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(duration)); keyFrame.Value = to; da.KeyFrames.Add(keyFrame); return da; }
private void ApplyBounceEffect(FrameworkElement e) { var da = new DoubleAnimationUsingKeyFrames(); var k1 = new SplineDoubleKeyFrame { KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(100)), Value = this.MaxItemHeight * 0.30 }; var k2 = new SplineDoubleKeyFrame { KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(200)), Value = 0 }; var k3 = new SplineDoubleKeyFrame { KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(300)), Value = this.MaxItemHeight * 0.10 }; var k4 = new SplineDoubleKeyFrame { KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(350)), Value = 0 }; da.KeyFrames.Add(k1); da.KeyFrames.Add(k2); da.KeyFrames.Add(k3); da.KeyFrames.Add(k4); Storyboard sb = new Storyboard(); Storyboard.SetTarget(da, e); Storyboard.SetTargetProperty(da, new PropertyPath("(UIElement.RenderTransform).(TransformGroup.Children)[0].(TranslateTransform.Y)")); sb.Children.Add(da); sb.Begin(); }
private void ResetNorth( ) { Storyboard sb = new Storyboard(); sb.Duration = TimeSpan.FromMilliseconds(500.0); DoubleAnimationUsingKeyFrames frames= new DoubleAnimationUsingKeyFrames(); SplineDoubleKeyFrame frame2 = new SplineDoubleKeyFrame(); frame2.KeyTime = sb.Duration.TimeSpan; frame2.Value = 0.0; KeySpline spline = new KeySpline(); spline.ControlPoint1 = new Point(0.0 , 0.1); spline.ControlPoint2 = new Point(0.1 , 1.0); frame2.KeySpline = spline; SplineDoubleKeyFrame frame = frame2; frames.KeyFrames.Add(frame); if (this.Map.Angle > 180) { frame.Value = 360.0; }//正转到北 if (this.Map.Angle <= 180) { frame.Value = 0.0; }//转回去 frames.SetValue(Storyboard.TargetPropertyProperty , new PropertyPath("Angle")); sb.Children.Add(frames); Storyboard.SetTarget(frames , this.Map); sb.Begin(); }
private void ResetRotation_Click(object sender, RoutedEventArgs e) { Storyboard s = new Storyboard { Duration = TimeSpan.FromMilliseconds(500.0) }; DoubleAnimationUsingKeyFrames frames = new DoubleAnimationUsingKeyFrames(); SplineDoubleKeyFrame frame2 = new SplineDoubleKeyFrame { KeyTime = s.Duration.TimeSpan, Value = 0.0 }; KeySpline spline = new KeySpline { ControlPoint1 = new Point(0.0, 0.1), ControlPoint2 = new Point(0.1, 1.0) }; frame2.KeySpline = spline; SplineDoubleKeyFrame keyFrame = frame2; frames.KeyFrames.Add(keyFrame); keyFrame.Value = 0.0; frames.SetValue(Storyboard.TargetPropertyProperty, new PropertyPath("Rotation", new object[0])); s.Children.Add(frames); Storyboard.SetTarget(frames, this.Map); s.Completed += delegate (object sender2, EventArgs e2) { s.Stop(); this.Map.Rotation = 0.0; }; s.Begin(); }
public override void OnApplyTemplate() { base.OnApplyTemplate(); root = (Grid)GetTemplateChild("root"); if (root == null) return; PART_Header = (ContentPresenter)GetTemplateChild("PART_Header"); PART_Content = (ContentPresenter)GetTemplateChild("PART_Content"); this.windowTitleThumb = GetTemplateChild("PART_WindowTitleThumb") as Thumb; if (this.windowTitleThumb != null) { this.windowTitleThumb.PreviewMouseLeftButtonUp -= WindowTitleThumbOnPreviewMouseLeftButtonUp; this.windowTitleThumb.DragDelta -= this.WindowTitleThumbMoveOnDragDelta; this.windowTitleThumb.MouseDoubleClick -= this.WindowTitleThumbChangeWindowStateOnMouseDoubleClick; this.windowTitleThumb.MouseRightButtonUp -= this.WindowTitleThumbSystemMenuOnMouseRightButtonUp; this.windowTitleThumb.PreviewMouseLeftButtonUp += WindowTitleThumbOnPreviewMouseLeftButtonUp; this.windowTitleThumb.DragDelta += this.WindowTitleThumbMoveOnDragDelta; this.windowTitleThumb.MouseDoubleClick += this.WindowTitleThumbChangeWindowStateOnMouseDoubleClick; this.windowTitleThumb.MouseRightButtonUp += this.WindowTitleThumbSystemMenuOnMouseRightButtonUp; } hideStoryboard = (Storyboard)GetTemplateChild("HideStoryboard"); hideFrame = (SplineDoubleKeyFrame)GetTemplateChild("hideFrame"); hideFrameY = (SplineDoubleKeyFrame)GetTemplateChild("hideFrameY"); showFrame = (SplineDoubleKeyFrame)GetTemplateChild("showFrame"); showFrameY = (SplineDoubleKeyFrame)GetTemplateChild("showFrameY"); fadeOutFrame = (SplineDoubleKeyFrame)GetTemplateChild("fadeOutFrame"); if (hideFrame == null || showFrame == null || hideFrameY == null || showFrameY == null || fadeOutFrame == null) return; ApplyAnimation(Position, AnimateOpacity); }
private void MoveOneControl(UIElement c, bool setHandle) { double current = Canvas.GetLeft(c); double future = current + _between; if (future > _lastPos) { future = _startPos; } // Set up the animation to layout in grid Storyboard moveStoryboardX = new Storyboard(); // Create Animation DoubleAnimationUsingKeyFrames moveAnimation = new DoubleAnimationUsingKeyFrames(); moveAnimation.Duration = TimeSpan.FromSeconds(1); // Create Keyframe SplineDoubleKeyFrame startKeyframe = new SplineDoubleKeyFrame(); startKeyframe.Value = current; startKeyframe.KeyTime = KeyTime.FromTimeSpan(TimeSpan.Zero); moveAnimation.KeyFrames.Add(startKeyframe); startKeyframe = new SplineDoubleKeyFrame(); if (future > current) { startKeyframe.Value = current + (future - current) / 2; } else { startKeyframe.Value = future + (current - future) / 2; } startKeyframe.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(500)); KeySpline ks = new KeySpline(); ks.ControlPoint1 = new Point(0, 1); ks.ControlPoint2 = new Point(1, 1); startKeyframe.KeySpline = ks; moveAnimation.KeyFrames.Add(startKeyframe); startKeyframe = new SplineDoubleKeyFrame(); startKeyframe.Value = future; startKeyframe.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(800)); moveAnimation.KeyFrames.Add(startKeyframe); Storyboard.SetTarget(moveAnimation, (UIElement)c); Storyboard.SetTargetProperty(moveAnimation, new PropertyPath("(Canvas.Left)")); moveStoryboardX.Children.Add(moveAnimation); canvasCts.Resources.Add(Convert.ToString(_index), moveStoryboardX); _index++; // Play Storyboard moveStoryboardX.Begin(); if (setHandle) { moveStoryboardX.Completed += new EventHandler(sb_Completed); } canvasCts.Resources.Clear(); }