public void InitializeParent(UIElement parent, IProtoService protoService) { _protoService = protoService; _parent = parent; ElementCompositionPreview.SetIsTranslationEnabled(parent, true); }
public static void StartTranslationAnimation(this UIElement element, Vector3?from = null, Vector3?to = null, double duration = 800, int delay = 0, CompositionEasingFunction easing = null, Action completed = null, AnimationIterationBehavior iterationBehavior = AnimationIterationBehavior.Count) { CompositionScopedBatch batch = null; ElementCompositionPreview.SetIsTranslationEnabled(element, true); var visual = element.Visual(); var compositor = visual.Compositor; if (completed != null) { batch = compositor.CreateScopedBatch(CompositionBatchTypes.Animation); batch.Completed += (s, e) => completed(); } if (to == null) { to = Vector3.Zero; } visual.StartAnimation("Translation", compositor.CreateVector3KeyFrameAnimation(from, to.Value, duration, delay, easing, iterationBehavior)); batch?.End(); }
public static void TranslationAnimation(Compositor _compositor, UIElement _element, bool isExit) { try { if (!isExit) { var topBorderOffsetAnimation = _compositor.CreateScalarKeyFrameAnimation(); topBorderOffsetAnimation.Duration = TimeSpan.FromSeconds(0.4); topBorderOffsetAnimation.Target = "Translation.Y"; topBorderOffsetAnimation.InsertKeyFrame(0, 100.0f); topBorderOffsetAnimation.InsertKeyFrame(1, 0); ElementCompositionPreview.SetIsTranslationEnabled(_element, true); ElementCompositionPreview.GetElementVisual(_element); ElementCompositionPreview.SetImplicitShowAnimation(_element, topBorderOffsetAnimation); } else { var mainContentExitAnimation = _compositor.CreateScalarKeyFrameAnimation(); mainContentExitAnimation.Target = "Translation.Y"; mainContentExitAnimation.InsertKeyFrame(1, 30); mainContentExitAnimation.Duration = TimeSpan.FromSeconds(0.4); ElementCompositionPreview.SetIsTranslationEnabled(_element, true); ElementCompositionPreview.SetImplicitHideAnimation(_element, mainContentExitAnimation); } } catch (Exception) { } }
public static Task StartTranslationAnimationAsync(this UIElement element, AnimationAxis axis, float?from = null, float to = 0, double duration = 800, int delay = 0, CompositionEasingFunction easing = null, AnimationIterationBehavior iterationBehavior = AnimationIterationBehavior.Count) { CompositionScopedBatch batch; ElementCompositionPreview.SetIsTranslationEnabled(element, true); var visual = element.Visual(); var compositor = visual.Compositor; var taskSource = new TaskCompletionSource <bool>(); void Completed(object o, CompositionBatchCompletedEventArgs e) { batch.Completed -= Completed; taskSource.SetResult(true); } batch = compositor.CreateScopedBatch(CompositionBatchTypes.Animation); batch.Completed += Completed; visual.StartAnimation($"Translation.{axis}", compositor.CreateScalarKeyFrameAnimation(from, to, duration, delay, easing, iterationBehavior)); batch.End(); return(taskSource.Task); }
private void Animate(Windows.UI.Composition.AnimationDirection direction) { double height = Root.ActualHeight + Root.Margin.Top + Root.Margin.Bottom; ElementCompositionPreview.SetIsTranslationEnabled(Root, true); Visual visual = ElementCompositionPreview.GetElementVisual(Root); visual.Offset = new Vector3(0, VerticalAlignment == VerticalAlignment.Top ? (float)-height : (float)height, 0); visual.Opacity = 0; Compositor compositor = visual.Compositor; Vector3KeyFrameAnimation vfa = compositor.CreateVector3KeyFrameAnimation(); vfa.InsertKeyFrame(1f, new Vector3(0, 0, 0)); vfa.Duration = TimeSpan.FromMilliseconds(250); vfa.Direction = direction; vfa.IterationCount = 1; ScalarKeyFrameAnimation sfa = compositor.CreateScalarKeyFrameAnimation(); sfa.InsertKeyFrame(1, 1); sfa.Duration = TimeSpan.FromMilliseconds(250); sfa.Direction = direction; sfa.IterationCount = 1; visual.StartAnimation("Offset", vfa); visual.StartAnimation("Opacity", sfa); }
//Green rectangle animation using the new Translation property inserted into the Visual's PropertySet void StartAnimationTranslation() { //Get the compositor from the current Window. This is new in the Creator's Update. var compositor = Window.Current.Compositor; var animation = compositor.CreateScalarKeyFrameAnimation(); //Enable The new Translation property ElementCompositionPreview.SetIsTranslationEnabled(Rectangle1, true); //now intialize the Value of Translation in the Popertyset to Zero for first use to avoid timing issues. This ensures that //the property is ready for use immediately. var rect1VisaulPropertySet = ElementCompositionPreview.GetElementVisual(Rectangle1).Properties; rect1VisaulPropertySet.InsertVector3("Translation", Vector3.Zero); //Animation animation.InsertExpressionKeyFrame(0, "this.StartingValue"); animation.InsertExpressionKeyFrame(0.5f, "this.StartingValue - 120"); animation.InsertExpressionKeyFrame(1, "this.StartingValue"); animation.StopBehavior = AnimationStopBehavior.SetToInitialValue; animation.IterationBehavior = AnimationIterationBehavior.Forever; animation.Duration = TimeSpan.FromSeconds(1.5); StartAnimation1(Rectangle1, animation); }
/// <summary> /// Creates and starts an animation on the target element that binds either the X or Y axis of the source <see cref="ScrollViewer"/> /// </summary> /// <param name="scroller">The source <see cref="ScrollViewer"/> control to use</param> /// <param name="target">The target <see cref="UIElement"/> that will be animated</param> /// <param name="sourceAxis">The scrolling axis of the source <see cref="ScrollViewer"/></param> /// <param name="targetAxis">The optional scrolling axis of the target element, if <see langword="null"/> the source axis will be used</param> /// <param name="property">The target <see cref="Visual"/> property to animate.</param> /// <returns>An <see cref="ExpressionAnimation"/> instance that represents an already running animation.</returns> public static ExpressionAnimation StartExpressionAnimation( this ScrollViewer scroller, UIElement target, Axis sourceAxis, Axis targetAxis, VisualProperty property = VisualProperty.Translation) { CompositionPropertySet scrollSet = ElementCompositionPreview.GetScrollViewerManipulationPropertySet(scroller); ExpressionAnimation animation = scrollSet.Compositor.CreateExpressionAnimation($"{nameof(scroller)}.{nameof(UIElement.Translation)}.{sourceAxis}"); animation.SetReferenceParameter(nameof(scroller), scrollSet); Visual visual = ElementCompositionPreview.GetElementVisual(target); switch (property) { case VisualProperty.Translation: ElementCompositionPreview.SetIsTranslationEnabled(target, true); visual.StartAnimation($"{nameof(Matrix4x4.Translation)}.{targetAxis}", animation); break; case VisualProperty.Offset: visual.StartAnimation($"{nameof(Visual.Offset)}.{targetAxis}", animation); break; default: throw new ArgumentException($"Invalid target property: {property}", nameof(property)); } return(animation); }
private void CreateIcon() { if (Icon != null || !_isSelectionEnabled) { return; } Icon = GetTemplateChild(nameof(Icon)) as AnimatedIcon; ElementCompositionPreview.SetIsTranslationEnabled(Icon, true); RegisterPropertyChangedCallback(BackgroundProperty, OnBackgroundChanged); OnBackgroundChanged(this, BackgroundProperty); if (IsAlbumChild) { if (_message.Content is MessagePhoto or MessageVideo) { Icon.VerticalAlignment = VerticalAlignment.Top; Icon.HorizontalAlignment = HorizontalAlignment.Right; Icon.Margin = new Thickness(0, 4, 6, 0); } else { Icon.VerticalAlignment = VerticalAlignment.Bottom; Icon.HorizontalAlignment = HorizontalAlignment.Left; Icon.Margin = new Thickness(28, 0, 0, 4); } Grid.SetColumn(Icon, 1); }
public static void StartGridViewItemAnimation(Grid grid, int relativeIndex) { var itemVisual = ElementCompositionPreview.GetElementVisual(grid); ElementCompositionPreview.SetIsTranslationEnabled(grid, true); var easingFunction = Window.Current.Compositor.CreateCubicBezierEasingFunction(new Vector2(0.1f, 0.9f), new Vector2(0.2f, 1f)); var offsetAnimation = Window.Current.Compositor.CreateScalarKeyFrameAnimation(); offsetAnimation.InsertKeyFrame(0f, 100); offsetAnimation.InsertKeyFrame(1f, 0, easingFunction); offsetAnimation.Target = "Translation.X"; offsetAnimation.DelayBehavior = AnimationDelayBehavior.SetInitialValueBeforeDelay; offsetAnimation.Duration = TimeSpan.FromMilliseconds(700); offsetAnimation.DelayTime = TimeSpan.FromMilliseconds(relativeIndex * 100); var fadeAnimation = Window.Current.Compositor.CreateScalarKeyFrameAnimation(); fadeAnimation.InsertExpressionKeyFrame(0f, "0"); fadeAnimation.InsertExpressionKeyFrame(1f, "1"); fadeAnimation.DelayBehavior = AnimationDelayBehavior.SetInitialValueBeforeDelay; fadeAnimation.Duration = TimeSpan.FromMilliseconds(700); fadeAnimation.DelayTime = TimeSpan.FromMilliseconds(relativeIndex * 100); itemVisual.StartAnimation("Translation.X", offsetAnimation); itemVisual.StartAnimation("Opacity", fadeAnimation); }
public void EnableFluidVisibilityAnimation(UIElement element) { var elementVisual = ElementCompositionPreview.GetElementVisual(element); var compositor = elementVisual.Compositor; ElementCompositionPreview.SetIsTranslationEnabled(element, true); ScalarKeyFrameAnimation hideOpacityAnimation = compositor.CreateScalarKeyFrameAnimation(); hideOpacityAnimation.InsertKeyFrame(1.0f, 0.0f); hideOpacityAnimation.Duration = TimeSpan.FromMilliseconds(2000); hideOpacityAnimation.Target = "Opacity"; var hideAnimationGroup = compositor.CreateAnimationGroup(); hideAnimationGroup.Add(hideOpacityAnimation); ElementCompositionPreview.SetImplicitHideAnimation(element, hideAnimationGroup); ScalarKeyFrameAnimation showOpacityAnimation = compositor.CreateScalarKeyFrameAnimation(); showOpacityAnimation.InsertKeyFrame(1.0f, 1.0f); showOpacityAnimation.Duration = TimeSpan.FromMilliseconds(2000); showOpacityAnimation.Target = "Opacity"; var showAnimationGroup = compositor.CreateAnimationGroup(); showAnimationGroup.Add(showOpacityAnimation); ElementCompositionPreview.SetImplicitShowAnimation(element, showAnimationGroup); }
private void SetupCompositor() { if (DesignMode.DesignModeEnabled) { return; } Compositor = ElementCompositionPreview.GetElementVisual(this).Compositor; if (BorderBackground != null) { BorderBackgroundVisual = ElementCompositionPreview.GetElementVisual(BorderBackground); } if (ContentBorder != null) { ElementCompositionPreview.SetIsTranslationEnabled(ContentBorder, true); ContentBorderVisual = ElementCompositionPreview.GetElementVisual(ContentBorder); } if (ShadowHost != null) { var shadow = Compositor.CreateDropShadow(); shadow.Color = Colors.Black; shadow.Opacity = 0.4f; shadow.BlurRadius = 8f; shadow.Offset = new Vector3(2f, 2f, 0f); if (BorderBackground != null) { shadow.Mask = BorderBackground.GetAlphaMask(); } ShadowVisual = Compositor.CreateSpriteVisual(); ShadowVisual.Size = new Vector2((float)ShadowHost.ActualWidth, (float)ShadowHost.ActualHeight); ShadowVisual.Shadow = shadow; ElementCompositionPreview.SetElementChildVisual(ShadowHost, ShadowVisual); } }
private void PaneRoot_Loaded(object sender, RoutedEventArgs e) { var f = (UIElement)sender; ElementCompositionPreview.SetIsTranslationEnabled(f, true); Visual v = ElementCompositionPreview.GetElementVisual(f); var o = v.Compositor.CreateVector3KeyFrameAnimation(); o.Target = "Translation"; o.InsertExpressionKeyFrame(0, "this.StartingValue"); o.InsertKeyFrame(1, new System.Numerics.Vector3(-256, 0, 0)); o.Duration = TimeSpan.FromSeconds(Composition.DefaultOffsetDuration); ElementCompositionPreview.SetImplicitHideAnimation(f, o); var o2 = v.Compositor.CreateVector3KeyFrameAnimation(); o2.Target = "Translation"; o2.InsertExpressionKeyFrame(0, "this.StartingValue"); o2.InsertKeyFrame(1, new System.Numerics.Vector3(0, 0, 0)); o2.Duration = TimeSpan.FromSeconds(Composition.DefaultOffsetDuration); ElementCompositionPreview.SetImplicitShowAnimation(f, o2); }
private void SetupAnimations() { _compositor = ElementCompositionPreview.GetElementVisual(this).Compositor; ElementCompositionPreview.SetIsTranslationEnabled(lblPageName, true); #region Top Bar var topBarHide = _compositor.CreateScalarKeyFrameAnimation(); topBarHide.Duration = TimeSpan.FromMilliseconds(300); topBarHide.InsertKeyFrame(1, -100f); topBarHide.Target = "Translate.Y"; ElementCompositionPreview.SetImplicitHideAnimation(lblPageName, topBarHide); var topBarShow = _compositor.CreateScalarKeyFrameAnimation(); topBarShow.Duration = TimeSpan.FromMilliseconds(300); topBarShow.InsertKeyFrame(0, -100f); topBarShow.InsertKeyFrame(1, 0f); topBarShow.Target = "Translate.Y"; ElementCompositionPreview.SetImplicitShowAnimation(lblPageName, topBarShow); #endregion #region New Question Button #endregion }
private void ConfigSpringBasedTracker(UIElement element, double periodInMs, float dampingRatio, float finalValue = 0.0f, double delayInMs = 0.0f) { ElementCompositionPreview.SetIsTranslationEnabled(element, true); var tracker = InteractionTracker.Create(_compositor); tracker.InteractionSources.Add(_interactionSource); tracker.MaxPosition = new Vector3(Root.RenderSize.ToVector2(), 0.0f); tracker.MinPosition = -tracker.MaxPosition; var modifier = InteractionTrackerInertiaNaturalMotion.Create(_compositor); var springAnimation = _compositor.CreateSpringScalarAnimation(); springAnimation.Period = TimeSpan.FromMilliseconds(periodInMs); springAnimation.DampingRatio = dampingRatio; springAnimation.FinalValue = finalValue; // This will cause a black screen for a few seconds. Bug?? springAnimation.DelayTime = TimeSpan.FromMilliseconds(delayInMs); modifier.Condition = _compositor.CreateExpressionAnimation("true"); modifier.NaturalMotion = springAnimation; tracker.ConfigurePositionXInertiaModifiers(new InteractionTrackerInertiaModifier[] { modifier }); tracker.ConfigurePositionYInertiaModifiers(new InteractionTrackerInertiaModifier[] { modifier }); var imageVisual = ElementCompositionPreview.GetElementVisual(element); imageVisual.StartAnimation("Translation", -tracker.GetReference().Position); }
private void AnimationSetup() { _compositor = Window.Current.Compositor; _visual = ElementCompositionPreview.GetElementVisual(Rectangle); _pause = true; _interval = TimeSpan.FromMilliseconds(16); // based on 60f/sec var linear = _compositor.CreateLinearEasingFunction(); int animationDuration = 4; float animationMax = 250f; // set up main animation ElementCompositionPreview.SetIsTranslationEnabled(Rectangle, true); _animation = _compositor.CreateVector3KeyFrameAnimation(); _animation.InsertKeyFrame(0.25f, new Vector3(animationMax, (float)Canvas.GetTop(Rectangle), 0f), linear); _animation.InsertKeyFrame(0.5f, new Vector3(animationMax, animationMax, 0f), linear); _animation.InsertKeyFrame(0.75f, new Vector3((float)Canvas.GetLeft(Rectangle), animationMax, 0f), linear); _animation.InsertKeyFrame(1f, new Vector3((float)Canvas.GetLeft(Rectangle), (float)Canvas.GetTop(Rectangle), 0f), linear); _animation.Duration = TimeSpan.FromSeconds(animationDuration); _animation.IterationBehavior = AnimationIterationBehavior.Forever; // set up dispatcher timer to animate slider _sliderAnimator = new DispatcherTimer(); _sliderAnimator.Tick += SliderBehavior; _sliderAnimator.Interval = _interval; // initialize amount to change slider value per tick _delta = (slider.Maximum / _animation.Duration.TotalMilliseconds) * _interval.TotalMilliseconds; // add pointer listeners to slider for smooth scrubbing action slider.AddHandler(PointerPressedEvent, new PointerEventHandler(PressedThumb), true); slider.AddHandler(PointerReleasedEvent, new PointerEventHandler(ReleasedThumb), true); }
private void UpdateToolbar(bool collapse = false) { if (Toolbar.SelectedItem == null != _emojiCollapsed || collapse) { _emojiCollapsed = Toolbar.SelectedItem == null; var show = !_emojiCollapsed; var toolbar = ElementCompositionPreview.GetElementVisual(Toolbar); var pill = ElementCompositionPreview.GetElementVisual(ToolbarPill); var panel = ElementCompositionPreview.GetElementVisual(Toolbar2.ItemsPanelRoot); ElementCompositionPreview.SetIsTranslationEnabled(Toolbar2.ItemsPanelRoot, true); var clip = toolbar.Compositor.CreateInsetClip(); var offset = 144 - 32; var ellipse = toolbar.Compositor.CreateRoundedRectangleGeometry(); ellipse.CornerRadius = new Vector2(4); pill.Clip = toolbar.Compositor.CreateGeometricClip(ellipse); toolbar.Clip = clip; Toolbar.Width = 144; var animClip = toolbar.Compositor.CreateScalarKeyFrameAnimation(); animClip.InsertKeyFrame(show ? 1 : 0, 0); animClip.InsertKeyFrame(show ? 0 : 1, offset); var animOffset = toolbar.Compositor.CreateScalarKeyFrameAnimation(); animOffset.InsertKeyFrame(show ? 0 : 1, -offset); animOffset.InsertKeyFrame(show ? 1 : 0, 0); var animSize = toolbar.Compositor.CreateVector2KeyFrameAnimation(); animSize.InsertKeyFrame(show ? 0 : 1, new Vector2(32, 32)); animSize.InsertKeyFrame(show ? 1 : 0, new Vector2(32 + offset, 32)); var animOpacity = toolbar.Compositor.CreateScalarKeyFrameAnimation(); animOpacity.InsertKeyFrame(show ? 0 : 1, 0); animOpacity.InsertKeyFrame(show ? 1 : 0, 1); var batch = toolbar.Compositor.CreateScopedBatch(CompositionBatchTypes.Animation); batch.Completed += (s, args) => { panel.Properties.InsertVector3("Translation", Vector3.Zero); toolbar.Clip = null; Toolbar.Width = show ? 144 : 32; Toolbar.ScrollIntoView(Toolbar2.SelectedItem == null && Toolbar.Items.Count > 0 ? Toolbar.Items[0] : Toolbar.Items.LastOrDefault()); }; clip.StartAnimation("RightInset", animClip); panel.StartAnimation("Translation.X", animOffset); ellipse.StartAnimation("Size", animSize); pill.StartAnimation("Opacity", animOpacity); batch.End(); } }
private void SetupAnimations(Object item) { var shadow = GetShadowFromContent(item); var content = ElementCompositionPreview.GetElementVisual(item as UIElement); ElementCompositionPreview.SetIsTranslationEnabled((UIElement)item, true); var ContentProperties = ElementCompositionPreview.GetElementVisual(item as UIElement).Properties; ContentProperties.InsertVector3("Translation", Vector3.Zero); var compositor = content.Compositor; var implicitAnimationShadow = compositor.CreateImplicitAnimationCollection(); var implicitAnimationVisual = compositor.CreateImplicitAnimationCollection(); //Translation Animation var translationAnimation = compositor.CreateVector3KeyFrameAnimation(); translationAnimation.InsertExpressionKeyFrame(1.0f, "this.FinalValue"); translationAnimation.Duration = TimeSpan.FromSeconds(1); translationAnimation.Target = "Translation"; //Scale Animation Shadow var shadowScaleAnimation = compositor.CreateVector3KeyFrameAnimation(); shadowScaleAnimation.InsertExpressionKeyFrame(1.0f, "this.FinalValue"); shadowScaleAnimation.Duration = TimeSpan.FromSeconds(1); shadowScaleAnimation.Target = "Scale"; // Animate shadow (change opacity) var shadowOpacityAnimation = compositor.CreateScalarKeyFrameAnimation(); shadowOpacityAnimation.InsertExpressionKeyFrame(1.0f, "this.FinalValue"); shadowOpacityAnimation.Duration = TimeSpan.FromSeconds(1); shadowOpacityAnimation.Target = "Opacity"; //BlurRadius Animation var shadowBlurAnimation = compositor.CreateScalarKeyFrameAnimation(); shadowBlurAnimation.InsertExpressionKeyFrame(1.0f, "this.FinalValue"); shadowBlurAnimation.Duration = TimeSpan.FromSeconds(1); shadowBlurAnimation.Target = "BlurRadius"; //Associating animations with triggers implicitAnimationShadow["BlurRadius"] = shadowBlurAnimation; implicitAnimationShadow["Opacity"] = shadowOpacityAnimation; implicitAnimationShadow["Scale"] = shadowScaleAnimation; implicitAnimationVisual["Translation"] = translationAnimation; //Applying Implicit Animations to objects content.Properties.ImplicitAnimations = implicitAnimationVisual; shadow.Visual.ImplicitAnimations = implicitAnimationShadow; shadow.DropShadow.ImplicitAnimations = implicitAnimationShadow; }
/// <summary> /// Enable translation. /// </summary> /// <param name="uix"></param> public static void EnableTranslation(UIElement uix) { if (!IsSupported) { return; } ElementCompositionPreview.SetIsTranslationEnabled(uix, true); }
private void TranslationSetup(UIElement element) { // Activate Translation property on the UIElement images ElementCompositionPreview.SetIsTranslationEnabled(element, true); var visual = ElementCompositionPreview.GetElementVisual(element); visual.Properties.InsertVector3("Translation", new Vector3(0)); }
public ArticlePage() { InitializeComponent(); EnsureAnimation(); _articleVisual = ElementCompositionPreview.GetElementVisual(ArticlePagePanel); ElementCompositionPreview.SetIsTranslationEnabled(ArticlePagePanel, true); _articleVisual.Opacity = 0; }
public static Visual GetVisual(this UIElement element) { var visual = ElementCompositionPreview.GetElementVisual(element); ElementCompositionPreview.SetIsTranslationEnabled(element, true); visual.Properties.InsertVector3(TRANSLATION, Vector3.Zero); return(visual); }
private static ImplicitAnimationCollection GetImplicitAnimationCollection(CAnimationCollection collection, UIElement element) { if (collection.ContainsTranslationAnimation) { ElementCompositionPreview.SetIsTranslationEnabled(element, true); } return(collection.GetImplicitAnimationCollection(element)); }
private static ImplicitAnimationCollection GetImplicitAnimationCollection(AnimationCollection collection, UIElement element) { if (ApiInformationHelper.IsCreatorsUpdateOrAbove && collection.ContainsTranslationAnimation) { ElementCompositionPreview.SetIsTranslationEnabled(element, true); } return(collection.GetImplicitAnimationCollection(element)); }
private void CreateThumbAnimation() { if (HorizontalThumb != null) { // // 平移动画 由于动画是上推Thumb操作带动Track弯曲,正确的行为是Thumb始终跟手,所以移除了平移动画 //var imp = Window.Current.Compositor.CreateImplicitAnimationCollection(); //var offsetAnimation = Window.Current.Compositor.CreateVector3KeyFrameAnimation(); //offsetAnimation.InsertExpressionKeyFrame(0f, "(abs(this.FinalValue.X - this.StartingValue.X) > 80) ? this.StartingValue : this.FinalValue"); //offsetAnimation.InsertExpressionKeyFrame(1f, "this.FinalValue"); //offsetAnimation.Duration = TimeSpan.FromSeconds(0.1d); //offsetAnimation.Target = "Offset"; //imp["Offset"] = offsetAnimation; //ElementCompositionPreview.GetElementVisual(HorizontalThumb).ImplicitAnimations = imp; //if (CurveHost != null) //{ // ElementCompositionPreview.GetElementVisual(CurveHost).ImplicitAnimations = imp; //} horizontalThumbContent = VisualTreeHelper.GetChild(HorizontalThumb, 0) as Ellipse; if (horizontalThumbContent == null) { HorizontalThumb.Loaded += HorizontalThumb_Loaded; } else { CreateAnimation(); } void HorizontalThumb_Loaded(object sender, RoutedEventArgs e) { HorizontalThumb.Loaded -= HorizontalThumb_Loaded; horizontalThumbContent = VisualTreeHelper.GetChild(HorizontalThumb, 0) as Ellipse; if (horizontalThumbContent != null) { CreateAnimation(); } } void CreateAnimation() { ElementCompositionPreview.SetIsTranslationEnabled(horizontalThumbContent, true); pressedThumbAnimation = Window.Current.Compositor.CreateScalarKeyFrameAnimation(); pressedThumbAnimation.InsertKeyFrame(1f, -8f); pressedThumbAnimation.Duration = TimeSpan.FromSeconds(0.05d); releasedThumbAnimation = Window.Current.Compositor.CreateSpringScalarAnimation(); releasedThumbAnimation.DampingRatio = 0.25f; releasedThumbAnimation.Period = TimeSpan.FromSeconds(0.01d); releasedThumbAnimation.FinalValue = 0f; } } }
private void ConfigureAnimations() { ElementCompositionPreview.SetIsTranslationEnabled(paraimage, true); ElementCompositionPreview.SetImplicitShowAnimation(paraimage, VisualHelpers.CreateVerticalOffsetAnimationFrom(0.55, -150)); ElementCompositionPreview.SetImplicitHideAnimation(paraimage, VisualHelpers.CreateVerticalOffsetAnimationTo(0.55, -150)); ElementCompositionPreview.SetImplicitHideAnimation(paraimage, VisualHelpers.CreateOpacityAnimation(0.4, 0)); Canvas.SetZIndex(this, 1); ElementCompositionPreview.SetImplicitHideAnimation(this, VisualHelpers.CreateOpacityAnimation(0.4, 0)); }
private void ConfigureAnimations() { // TODO: collapse all this into a single helper method ElementCompositionPreview.SetIsTranslationEnabled(HostElement, true); ElementCompositionPreview.SetImplicitShowAnimation(HostElement, VisualHelpers.CreateAnimationGroup( VisualHelpers.CreateVerticalOffsetAnimationFrom(0.45, -50f), VisualHelpers.CreateOpacityAnimation(0.5))); ElementCompositionPreview.SetImplicitHideAnimation(HostElement, VisualHelpers.CreateOpacityAnimation(0.8, 0)); }
private void InitVisual() { // TODO 14393 15063 var compositor = ElementCompositionPreview.GetElementVisual(this).Compositor; // 动画结束后要盖一层图片,不然会闪 var coverImageCoverOpacityAnimation = compositor.CreateScalarKeyFrameAnimation(); coverImageCoverOpacityAnimation.DelayTime = TimeSpan.FromSeconds(0.5); coverImageCoverOpacityAnimation.Duration = TimeSpan.FromMilliseconds(1); coverImageCoverOpacityAnimation.Target = "Opacity"; coverImageCoverOpacityAnimation.InsertKeyFrame(0, 0); coverImageCoverOpacityAnimation.InsertKeyFrame(1, 1); ElementCompositionPreview.SetIsTranslationEnabled(CoverImageCover, true); ElementCompositionPreview.GetElementVisual(CoverImageCover); ElementCompositionPreview.SetImplicitShowAnimation(CoverImageCover, coverImageCoverOpacityAnimation); // Add a translation animation that will play when this element is shown var topBorderOpacityAnimation = compositor.CreateScalarKeyFrameAnimation(); topBorderOpacityAnimation.DelayTime = TimeSpan.FromSeconds(0.5); topBorderOpacityAnimation.Duration = TimeSpan.FromSeconds(1); topBorderOpacityAnimation.Target = "Opacity"; topBorderOpacityAnimation.InsertKeyFrame(0, 0); topBorderOpacityAnimation.InsertKeyFrame(1, 1); ElementCompositionPreview.SetIsTranslationEnabled(TopBorder, true); ElementCompositionPreview.GetElementVisual(TopBorder); ElementCompositionPreview.SetImplicitShowAnimation(TopBorder, topBorderOpacityAnimation); // Add an opacity and translation animation that will play when this element is shown var mainContentTranslationAnimation = compositor.CreateScalarKeyFrameAnimation(); mainContentTranslationAnimation.DelayBehavior = AnimationDelayBehavior.SetInitialValueBeforeDelay; mainContentTranslationAnimation.DelayTime = TimeSpan.FromSeconds(0.2); mainContentTranslationAnimation.Duration = TimeSpan.FromSeconds(0.45); mainContentTranslationAnimation.Target = "Translation.Y"; mainContentTranslationAnimation.InsertKeyFrame(0, 50.0f); mainContentTranslationAnimation.InsertKeyFrame(1, 0); var mainContentOpacityAnimation = compositor.CreateScalarKeyFrameAnimation(); mainContentOpacityAnimation.Duration = TimeSpan.FromSeconds(0.4); mainContentOpacityAnimation.Target = "Opacity"; mainContentOpacityAnimation.InsertKeyFrame(0, 0); mainContentOpacityAnimation.InsertKeyFrame(0.25f, 0); mainContentOpacityAnimation.InsertKeyFrame(1, 1); var mainContentShowAnimations = compositor.CreateAnimationGroup(); mainContentShowAnimations.Add(mainContentTranslationAnimation); mainContentShowAnimations.Add(mainContentOpacityAnimation); ElementCompositionPreview.SetIsTranslationEnabled(MainContent, true); ElementCompositionPreview.GetElementVisual(MainContent); ElementCompositionPreview.SetImplicitShowAnimation(MainContent, mainContentShowAnimations); }
private TextBlock GetPart(char part, int index) { var textBlock = new TextBlock { Text = $"{part}", Style = TextStyle }; Grid.SetColumn(textBlock, index); ElementCompositionPreview.SetIsTranslationEnabled(textBlock, true); return(textBlock); }
public static FrameworkElement EnableCompositionTranslation(this FrameworkElement element, Vector3?defaultTranslation) { ElementCompositionPreview.SetIsTranslationEnabled(element, true); Visual visual = element.GetVisual(); if (defaultTranslation.HasValue) { visual.Properties.InsertVector3(CompositionProperty.Translation, defaultTranslation.Value); } return(element); }
static public void StopElementAtOffset(this ScrollViewer scrollViewer, UIElement element, float offset) { var compositor = Window.Current.Compositor; var propertySet = ElementCompositionPreview.GetScrollViewerManipulationPropertySet(scrollViewer); ElementCompositionPreview.SetIsTranslationEnabled(element, true); compositor.CreateExpressionWrapper("Max(0, -scroller.Translation.Y-offset)") .Parameter("scroller", propertySet) .Parameter("offset", offset) .Start(element, "Translation.Y"); }