// Path 1.PathGeometry CompositionPathGeometry PathGeometry_2() { var result = _c.CreatePathGeometry(new CompositionPath(Geometry_2())); var propertySet = result.Properties; propertySet.InsertScalar("TStart", 1); propertySet.InsertScalar("TEnd", 1); _reusableExpressionAnimation.ClearAllParameters(); _reusableExpressionAnimation.Expression = "Min(my.TStart, my.TEnd)"; _reusableExpressionAnimation.SetReferenceParameter("my", result); result.StartAnimation("TrimStart", _reusableExpressionAnimation); _reusableExpressionAnimation.ClearAllParameters(); _reusableExpressionAnimation.Expression = "Max(my.TStart, my.TEnd)"; _reusableExpressionAnimation.SetReferenceParameter("my", result); result.StartAnimation("TrimEnd", _reusableExpressionAnimation); result.StartAnimation("TStart", TStartScalarAnimation_1_to_0_0()); var controller = result.TryGetAnimationController("TStart"); controller.Pause(); controller.StartAnimation("Progress", _scalarExpressionAnimation); result.StartAnimation("TEnd", TEndScalarAnimation_1_to_0_0()); controller = result.TryGetAnimationController("TEnd"); controller.Pause(); controller.StartAnimation("Progress", _scalarExpressionAnimation); return(result); }
private void _createAnimation(UIElement attachedElement, CompositionObject compositionObject) { _offsetAnimation = Window.Current.Compositor.CreateExpressionAnimation(OFFSET_ANIMATION_EXPRESSION); _offsetAnimation.SetReferenceParameter(OFFSET_ANIMATION_EXPRESSION_REFERENCE_PROPS, _offsetProps); var pointerProps = ElementCompositionPreview.GetPointerPositionPropertySet(attachedElement); _offsetAnimation.SetReferenceParameter(OFFSET_ANIMATION_EXPRESSION_REFERENCE_POINTER, pointerProps); compositionObject.StartAnimation("Offset", _offsetAnimation); }
private void SetupScrollbars() { this.fullLogs.Add("SetupScrollbars"); hScrollIndicatorVisual = ElementCompositionPreview.GetElementVisual(hScrollIndicator); vScrollIndicatorVisual = ElementCompositionPreview.GetElementVisual(vScrollIndicator); hScrollBarVisual = ElementCompositionPreview.GetElementVisual(hScrollBar); vScrollBarVisual = ElementCompositionPreview.GetElementVisual(vScrollBar); hScrollIndicatorSpriteVisual = hScrollIndicatorVisual.Compositor.CreateSpriteVisual(); vScrollIndicatorSpriteVisual = vScrollIndicatorVisual.Compositor.CreateSpriteVisual(); CompositionColorBrush brush = hScrollIndicatorVisual.Compositor.CreateColorBrush(Colors.Red); hScrollIndicatorSpriteVisual.Brush = brush; vScrollIndicatorSpriteVisual.Brush = brush; ElementCompositionPreview.SetElementChildVisual(hScrollIndicator, hScrollIndicatorSpriteVisual); ElementCompositionPreview.SetElementChildVisual(vScrollIndicator, vScrollIndicatorSpriteVisual); UpdateScrollbars(); hIndicatorWidthExpression = hScrollIndicatorVisual.Compositor.CreateExpressionAnimation( "Vector2(Max(20.0f, Min(hScrollBarVisual.Size.X , seas.Viewport.X * hScrollBarVisual.Size.X / Max(0.0001f, seas.Extent.X * seas.ZoomFactor))), 30.0f)"); vIndicatorHeightExpression = vScrollIndicatorVisual.Compositor.CreateExpressionAnimation( "Vector2(30.0f, Max(20.0f, Min(vScrollBarVisual.Size.Y, seas.Viewport.Y * vScrollBarVisual.Size.Y / Max(0.0001f, seas.Extent.Y * seas.ZoomFactor))))"); hIndicatorWidthExpression.SetReferenceParameter("seas", scrollPresenter.ExpressionAnimationSources); vIndicatorHeightExpression.SetReferenceParameter("seas", scrollPresenter.ExpressionAnimationSources); hIndicatorWidthExpression.SetReferenceParameter("hScrollBarVisual", hScrollBarVisual); vIndicatorHeightExpression.SetReferenceParameter("vScrollBarVisual", vScrollBarVisual); hIndicatorOffsetExpression = hScrollIndicatorVisual.Compositor.CreateExpressionAnimation( "Vector3(" + "Max(0.0f, Min(hScrollBarVisual.Size.X - hScrollIndicatorSpriteVisual.Size.X, " + "seas.Offset.X * (hScrollBarVisual.Size.X - hScrollIndicatorSpriteVisual.Size.X) / Max(1.0f, (seas.Extent.X * seas.ZoomFactor - seas.Viewport.X))))," + "0.0f," + "0.0f)"); vIndicatorOffsetExpression = vScrollIndicatorVisual.Compositor.CreateExpressionAnimation( "Vector3(" + "0.0f," + "Max(0.0f, Min(vScrollBarVisual.Size.Y - vScrollIndicatorSpriteVisual.Size.Y, " + "seas.Offset.Y * (vScrollBarVisual.Size.Y - vScrollIndicatorSpriteVisual.Size.Y) / Max(1.0f, (seas.Extent.Y * seas.ZoomFactor - seas.Viewport.Y))))," + "0.0f)"); hIndicatorOffsetExpression.SetReferenceParameter("seas", scrollPresenter.ExpressionAnimationSources); vIndicatorOffsetExpression.SetReferenceParameter("seas", scrollPresenter.ExpressionAnimationSources); hIndicatorOffsetExpression.SetReferenceParameter("hScrollBarVisual", hScrollBarVisual); vIndicatorOffsetExpression.SetReferenceParameter("vScrollBarVisual", vScrollBarVisual); hIndicatorOffsetExpression.SetReferenceParameter("hScrollIndicatorSpriteVisual", hScrollIndicatorSpriteVisual); vIndicatorOffsetExpression.SetReferenceParameter("vScrollIndicatorSpriteVisual", vScrollIndicatorSpriteVisual); hScrollIndicatorSpriteVisual.StartAnimation("Size", hIndicatorWidthExpression); vScrollIndicatorSpriteVisual.StartAnimation("Size", vIndicatorHeightExpression); hScrollIndicatorVisual.StartAnimation("Offset", hIndicatorOffsetExpression); vScrollIndicatorVisual.StartAnimation("Offset", vIndicatorOffsetExpression); }
void BindProperty( CompositionObject target, string animatedPropertyName, string expression, string referenceParameterName, CompositionObject referencedObject) { _reusableExpressionAnimation.ClearAllParameters(); _reusableExpressionAnimation.Expression = expression; _reusableExpressionAnimation.SetReferenceParameter(referenceParameterName, referencedObject); target.StartAnimation(animatedPropertyName, _reusableExpressionAnimation); }
private void SetupSkyVisualOffsetExpressionAnimation() { // Kick off an expression animation that links the roll & pitch degress to the -offset of the sky canvas visual // TODO: Need to constraint the offset (total offset < dimension * SkyVisualAreaRatio) with // CreateConditionalExpressionAnimation once the next mobile build is available. _skyViusalOffsetExpressionAnimation = _compositor.CreateExpressionAnimation( "Vector3(SkyVisual.Offset.X - Reading.Offset.X * Sensitivity, SkyVisual.Offset.Y - Reading.Offset.Y * Sensitivity, 0.0f)"); _skyViusalOffsetExpressionAnimation.SetReferenceParameter("SkyVisual", _skyVisual); _skyViusalOffsetExpressionAnimation.SetReferenceParameter("Reading", _reading); _skyViusalOffsetExpressionAnimation.SetScalarParameter("Sensitivity", 0.2f); //_skyViusalOffsetExpressionAnimation.SetScalarParameter("MaxDimension", SkyVisualRadius * 2 * SkyVisualAreaRatio); _skyVisual.StartAnimation("Offset", _skyViusalOffsetExpressionAnimation); }
private void UpdateTo() { if (host == null) { return; } propset.StopAnimation("offsetx"); propset.StopAnimation("offsety"); ExpressionAnimation an = null; switch (To) { case FlipTransitionMode.Left: an = host.Compositor.CreateExpressionAnimation("-host.Size.X"); an.SetReferenceParameter("host", host); propset.StartAnimation("offsetx", an); propset.InsertScalar("offsety", 0f); propset.InsertScalar("degress", 90f); propset.InsertVector3("axis", Vector3.UnitY); break; case FlipTransitionMode.Top: an = host.Compositor.CreateExpressionAnimation("-host.Size.Y"); an.SetReferenceParameter("host", host); propset.InsertScalar("offsetx", 0f); propset.StartAnimation("offsety", an); propset.InsertScalar("degress", 90f); propset.InsertVector3("axis", Vector3.UnitX); break; case FlipTransitionMode.Right: an = host.Compositor.CreateExpressionAnimation("host.Size.X"); an.SetReferenceParameter("host", host); propset.StartAnimation("offsetx", an); propset.InsertScalar("offsety", 0f); propset.InsertScalar("degress", -90f); propset.InsertVector3("axis", Vector3.UnitY); break; case FlipTransitionMode.Bottom: an = host.Compositor.CreateExpressionAnimation("host.Size.Y"); an.SetReferenceParameter("host", host); propset.InsertScalar("offsetx", 0f); propset.StartAnimation("offsety", an); propset.InsertScalar("degress", -90f); propset.InsertVector3("axis", Vector3.UnitX); break; } }
private void StartAnimation(UIElement element) { if (element != null) { if (exp == null) { var bottomExp = "(scroll.Translation.Y < prop.viewportheight - this.target.Size.Y ? (prop.viewportheight - this.target.Size.Y - scroll.Translation.Y) : 0)"; var topExp = $"scroll.Translation.Y > 0 ? (-scroll.Translation.Y) : {bottomExp}"; exp = Window.Current.Compositor.CreateExpressionAnimation($"{topExp}"); exp.SetReferenceParameter("prop", propSet); exp.SetReferenceParameter("scroll", scrollPropSet); } ElementCompositionPreview.GetElementVisual(element).StartAnimation("Offset.Y", exp); } }
private void OnLoaded(object sender, RoutedEventArgs e) { var scrollViewer = ScrollingHost as ScrollViewer; if (scrollViewer == null && ScrollingHost != null) { scrollViewer = ScrollingHost.Descendants <ScrollViewer>().FirstOrDefault() as ScrollViewer; } if (scrollViewer == null) { return; } var props = ElementCompositionPreview.GetScrollViewerManipulationPropertySet(scrollViewer); if (props == null) { return; } if (VerticalAlignment == VerticalAlignment.Top) { _animation = _compositor.CreateExpressionAnimation("Max(Scroll.Translation.Y, 0)"); _animation.SetReferenceParameter("Scroll", props); _visual.StopAnimation("Size.Y"); _visual.StartAnimation("Size.Y", _animation); } }
private void AssignParallax() { if (ParallaxContent == null) { return; } if (AssociatedObject == null) { return; } var scroller = AssociatedObject as ScrollViewer; if (scroller == null) { scroller = AssociatedObject.GetChildOfType <ScrollViewer>(); } if (scroller == null) { return; } CompositionPropertySet scrollerViewerManipulation = ElementCompositionPreview.GetScrollViewerManipulationPropertySet(scroller); Compositor compositor = scrollerViewerManipulation.Compositor; ExpressionAnimation expression = compositor.CreateExpressionAnimation("ScrollManipululation.Translation.Y * ParallaxMultiplier"); expression.SetScalarParameter("ParallaxMultiplier", (float)ParallaxMultiplier); expression.SetReferenceParameter("ScrollManipululation", scrollerViewerManipulation); Visual textVisual = ElementCompositionPreview.GetElementVisual(ParallaxContent); textVisual.StartAnimation("Offset.Y", expression); }
private void SetupVisual() { var hostVisual = ElementCompositionPreview.GetElementVisual(element: ShadowHost); var compositor = hostVisual.Compositor; // Create a drop shadow DropShadow dropShadow = compositor.CreateDropShadow(); dropShadow.Color = Color.FromArgb(255, 22, 33, 44); dropShadow.BlurRadius = 15.0f; dropShadow.Offset = new Vector3(12.5f, 2.5f, 0.0f); // Associate the shape of the shadow with the shape of the target element dropShadow.Mask = CircleImage.GetAlphaMask(); // Create a Visual to hold the shadow SpriteVisual shadowVisual = compositor.CreateSpriteVisual(); shadowVisual.Shadow = dropShadow; // Add the shadow as a child of the host (Ellipse) in the visual tree ElementCompositionPreview.SetElementChildVisual(element: ShadowHost, visual: shadowVisual); // Ensure the size of shadow host and shadow visual always stay in sync ExpressionAnimation bindSizeAnimation = compositor.CreateExpressionAnimation(expression: "hostVisual.Size"); bindSizeAnimation.SetReferenceParameter(key: "hostVisual", compositionObject: hostVisual); shadowVisual.StartAnimation(propertyName: nameof(shadowVisual.Size), animation: bindSizeAnimation); }
private void MainPage_Loaded(object sender, RoutedEventArgs e) { //Only run this code if the app is running on Windows 10 1511 or later because API not supported on earlier versions of Windows if (ApiInformation.IsApiContractPresent("Windows.Foundation.UniversalApiContract", 2)) { // Get a referece to a "propertyset" that contains the following keys // Translation (Vector3) // CenterPoint (Vector3) // Scale (Vector3) // Matrix (Matrix4x4) // that represent the state of the scrollview at any moment (i.e. as the user manipulates the scrollviewer with mouse, touch, touchpad) CompositionPropertySet scrollerManipProps = ElementCompositionPreview.GetScrollViewerManipulationPropertySet(myScroller); Compositor compositor = scrollerManipProps.Compositor; // Create the expression ExpressionAnimation expression = compositor.CreateExpressionAnimation("scroller.Translation.Y * parallaxFactor"); // wire the ParallaxMultiplier constant into the expression expression.SetScalarParameter("parallaxFactor", 0.3f); // set "dynamic" reference parameter that will be used to evaluate the current position of the scrollbar every frame expression.SetReferenceParameter("scroller", scrollerManipProps); // Get the background image and start animating it's offset using the expression Visual backgroundVisual = ElementCompositionPreview.GetElementVisual(background); backgroundVisual.StartAnimation("Offset.Y", expression); } }
protected override void OnConnected(UIElement newElement) { element = newElement; compositor = ElementCompositionPreview.GetElementVisual(Window.Current.Content).Compositor; var spotlight = compositor.CreateSpotLight(); spotlight.InnerConeAngleInDegrees = 10f; spotlight.OuterConeAngleInDegrees = 20f; spotlight.InnerConeColor = Colors.FloralWhite; spotlight.OuterConeColor = Colors.FloralWhite; spotlight.ConstantAttenuation = 0f; spotlight.LinearAttenuation = 0f; spotlight.QuadraticAttenuation = 0f; CompositionLight = spotlight; PropSet = compositor.CreatePropertySet(); PropSet.InsertScalar("OffsetX", 0f); PropSet.InsertScalar("OffsetY", 0f); PropSet.InsertScalar("OffsetZ", 300f); SpotLightOffsetAnimation = compositor.CreateExpressionAnimation("Vector3(PropSet.OffsetX ,PropSet.OffsetY ,PropSet.OffsetZ)"); SpotLightOffsetAnimation.SetReferenceParameter("PropSet", PropSet); CompositionLight.StartAnimation("Offset", SpotLightOffsetAnimation); cbEasing = compositor.CreateCubicBezierEasingFunction(new Vector2(0.42f, 0f), new Vector2(1f, 1f)); line = compositor.CreateLinearEasingFunction(); var an = compositor.CreateScalarKeyFrameAnimation(); an.InsertKeyFrame(0f, 0f, cbEasing); an.InsertKeyFrame(1f, 60f, cbEasing); an.Duration = TimeSpan.FromSeconds(10); an.IterationBehavior = AnimationIterationBehavior.Forever; }
private void PrepareAnimations() { _animation = _compositor.CreateExpressionAnimation("touch.Offset.X"); _animation.SetReferenceParameter("touch", _indicatorVisual); _animation_0 = _compositor.CreateExpressionAnimation("touch.Offset.X+self"); float offsestX_0 = _itemVisualList[0].Offset.X; _animation_0.SetScalarParameter("self", offsestX_0); _animation_0.SetReferenceParameter("touch", _indicatorVisual); _animation_1 = _compositor.CreateExpressionAnimation("touch.Offset.X+self"); float offsestX_1 = _itemVisualList[1].Offset.X; _animation_1.SetScalarParameter("self", offsestX_1); _animation_1.SetReferenceParameter("touch", _indicatorVisual); _animation_2 = _compositor.CreateExpressionAnimation("touch.Offset.X+self"); float offsestX_2 = _itemVisualList[2].Offset.X; _animation_2.SetScalarParameter("self", offsestX_2); _animation_2.SetReferenceParameter("touch", _indicatorVisual); _animation_3 = _compositor.CreateExpressionAnimation("touch.Offset.X+self"); float offsestX_3 = _itemVisualList[3].Offset.X; _animation_3.SetScalarParameter("self", offsestX_3); _animation_3.SetReferenceParameter("touch", _indicatorVisual); _animation_4 = _compositor.CreateExpressionAnimation("touch.Offset.X+self"); float offsestX_4 = _itemVisualList[4].Offset.X; _animation_4.SetScalarParameter("self", offsestX_4); _animation_4.SetReferenceParameter("touch", _indicatorVisual); }
/// <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 MainPage_Loaded(object sender, RoutedEventArgs e) { // Hide the refresh indicator (SV1 is the outer ScrollViewer) SV1.ChangeView(null, 100, null); ScrollViewer childScrollView = GetChildElement <ScrollViewer>(lv); if (childScrollView != null) { CompositionPropertySet scrollingProperties = ElementCompositionPreview.GetScrollViewerManipulationPropertySet(childScrollView); Compositor comp = scrollingProperties.Compositor; // // Set up the animation on the content of the main scroller. Animation will show a peek // of the refresh indicator when the child listview is bouncing. // MyPanel tempGrid = GetChildElement <MyPanel>(SV1); Visual elementVisual = ElementCompositionPreview.GetElementVisual(tempGrid); ExpressionAnimation elementAnimation = comp.CreateExpressionAnimation(@" max(scrollingProperties.Translation.Y, 0)"); elementAnimation.SetReferenceParameter("scrollingProperties", scrollingProperties); elementVisual.StartAnimation("Offset.Y", elementAnimation); // // Setup the animation to negate the bounce on the listView's scroller // Visual childVisual = ElementCompositionPreview.GetElementVisual(childScrollView); ExpressionAnimation childAnimation = comp.CreateExpressionAnimation(@" -max(scrollingProperties.Translation.Y, 0)"); childAnimation.SetReferenceParameter("scrollingProperties", scrollingProperties); childVisual.StartAnimation("Offset.Y", childAnimation); } }
private void AttachBlurAnimation() { GaussianBlurEffect blurEffect = new GaussianBlurEffect() { Name = "Blur", BlurAmount = 0.0f, BorderMode = EffectBorderMode.Hard, Optimization = EffectOptimization.Speed, Source = new CompositionEffectSourceParameter("Backdrop") }; var effectFactory = _compositor.CreateEffectFactory(blurEffect, new[] { "Blur.BlurAmount" }); var effectBrush = effectFactory.CreateBrush(); var destinationBrush = _compositor.CreateBackdropBrush(); effectBrush.SetSourceParameter("Backdrop", destinationBrush); var blurSprite = _compositor.CreateSpriteVisual(); blurSprite.Size = new Vector2((float)BackgroundImage.ActualWidth, (float)BackgroundImage.ActualHeight); blurSprite.Brush = effectBrush; ElementCompositionPreview.SetElementChildVisual(BackgroundImage, blurSprite); ExpressionAnimation backgroundBlurAnimation = _compositor.CreateExpressionAnimation( "Clamp(-scroller.Translation.Y / 10,0,100)"); backgroundBlurAnimation.SetReferenceParameter("scroller", _peopleScrollViewerPropertySet); blurSprite.Brush.Properties.StartAnimation("Blur.BlurAmount", backgroundBlurAnimation); }
private void InitShadow() { if (SelectedPie != null && PieShadowHost != null) { var compositor = ElementCompositionPreview.GetElementVisual(this).Compositor; SizeBind = compositor.CreateExpressionAnimation("host.Size"); SizeBind.SetReferenceParameter("host", ElementCompositionPreview.GetElementVisual(PieShadowHost)); ShadowVisual = compositor.CreateSpriteVisual(); ShadowVisual.StartAnimation("Size", SizeBind); Shadow = compositor.CreateDropShadow(); Shadow.Color = Colors.Black; Shadow.Opacity = 0.8f; Shadow.BlurRadius = 6f; Shadow.Mask = SelectedPie.GetAlphaMask(); ShadowVisual.Shadow = Shadow; if (IsShadowEnable) { if (ElementCompositionPreview.GetElementChildVisual(PieShadowHost) == null) { ElementCompositionPreview.SetElementChildVisual(PieShadowHost, ShadowVisual); } } } }
private void OnSizeChanged(object sender, Windows.UI.Xaml.SizeChangedEventArgs e) { Vector2 size = new System.Numerics.Vector2((float)this.ActualWidth, (float)this.ActualHeight); if (m_interactionTracker != null) { m_interactionTracker.MinPosition = new Vector3(-size.X, 0, 0); m_interactionTracker.MaxPosition = new Vector3(size.X, 0, 0); if (Content != null) { var positionExpression = m_compositor.CreateExpressionAnimation("-tracker.Position"); positionExpression.SetReferenceParameter("tracker", m_interactionTracker); m_contentVisual = ElementCompositionPreview.GetElementVisual(Content); m_contentVisual.StartAnimation("Offset", positionExpression); m_contentVisual.Size = size; if (m_setUpExpressions && m_progressAnimation == null) { m_progressAnimation = m_compositor.CreateExpressionAnimation( "clamp(visual.Offset.X / visual.Size.X, -1, 1)"); m_progressAnimation.SetReferenceParameter("visual", m_contentVisual); m_rootVisual.Properties.StartAnimation("NormalizedProgress", m_progressAnimation); } } } }
private void SetSharedParameters(ExpressionAnimation animation) { animation.SetReferenceParameter("ScrollingProperties", _scrollingProperties); animation.SetScalarParameter("FullWidth", ActualWidth.ToFloat()); animation.SetScalarParameter("SelectedIndex", SelectedIndex); animation.SetScalarParameter("UncheckedStateOpacity", 0.4f); }
private void LoadNowPlayingListAnimation() { _nowPlayingScrollViewer = NowPlayingList.GetScrollViewer(); _nowPlayingScrollViewer.DirectManipulationStarted += OnNowPlayingListManipulationStarted; _nowPlayingScrollViewer.DirectManipulationCompleted += OnNowPlayingListManipulationCompleted; _nowPlayingManipulation = ElementCompositionPreview.GetScrollViewerManipulationPropertySet(_nowPlayingScrollViewer); _nowPlayingCompositor = _nowPlayingManipulation.Compositor; _nowPlayingOpacityAnimation = _nowPlayingCompositor.CreateExpressionAnimation("min(max(0, -ScrollManipulation.Translation.X*4) / Divider, 1)"); _nowPlayingOpacityAnimation.SetScalarParameter("Divider", 95.0f); _nowPlayingOpacityAnimation.SetReferenceParameter("ScrollManipulation", _nowPlayingManipulation); _nowPlayingRefreshBorderOffsetAnimation = _nowPlayingCompositor.CreateExpressionAnimation(" ControlWidth+(max(min(0, ScrollManipulation.Translation.X*4) / Divider, -1)) * MaxOffsetX"); _nowPlayingRefreshBorderOffsetAnimation.SetScalarParameter("Divider", 95.0f); _nowPlayingRefreshBorderOffsetAnimation.SetScalarParameter("MaxOffsetX", 95.0f); _nowPlayingRefreshBorderOffsetAnimation.SetScalarParameter("ControlWidth", (float)(ActualWidth)); _nowPlayingRefreshBorderOffsetAnimation.SetReferenceParameter("ScrollManipulation", _nowPlayingManipulation); _nowPlayingBorderOffsetAnimation = _nowPlayingCompositor.CreateExpressionAnimation("(max(min(0, ScrollManipulation.Translation.X) / Divider, -1)) * MaxOffsetX"); _nowPlayingBorderOffsetAnimation.SetScalarParameter("Divider", 95.0f); _nowPlayingBorderOffsetAnimation.SetScalarParameter("MaxOffsetX", 95.0f); _nowPlayingBorderOffsetAnimation.SetReferenceParameter("ScrollManipulation", _nowPlayingManipulation); _nowPlayingResetAnimation = _nowPlayingCompositor.CreateScalarKeyFrameAnimation(); _nowPlayingResetAnimation.InsertKeyFrame(1.0f, 0.0f); _nowPlayingReleaseBorderVisual = ElementCompositionPreview.GetElementVisual(NowPlayingReleaseBorder); var border = (Border)VisualTreeHelper.GetChild(NowPlayingList, 0); _nowPlayingBorderVisual = ElementCompositionPreview.GetElementVisual(border); PrepareNowPlayingListExpressionAnimationsOnScroll(); }
private void AddPullRefreshEvents() { scrollViewer.DirectManipulationStarted += OnDirectManipulationStarted; scrollViewer.DirectManipulationCompleted += OnDirectManipulationCompleted; _scrollerViewerManipulation = ElementCompositionPreview.GetScrollViewerManipulationPropertySet(scrollViewer); var compositor = _scrollerViewerManipulation.Compositor; _rotationAnimation = compositor.CreateExpressionAnimation("min(max(0, ScrollManipulation.Translation.Y) * Multiplier, MaxDegree)"); _rotationAnimation.SetScalarParameter("Multiplier", 10.0f); _rotationAnimation.SetScalarParameter("MaxDegree", 400.0f); _rotationAnimation.SetReferenceParameter("ScrollManipulation", _scrollerViewerManipulation); _opacityAnimation = compositor.CreateExpressionAnimation("min(max(0, ScrollManipulation.Translation.Y) / Divider, 1)"); _opacityAnimation.SetScalarParameter("Divider", 30.0f); _opacityAnimation.SetReferenceParameter("ScrollManipulation", _scrollerViewerManipulation); _offsetAnimation = compositor.CreateExpressionAnimation("(min(max(0, ScrollManipulation.Translation.Y) / Divider, 1)) * MaxOffsetY"); _offsetAnimation.SetScalarParameter("Divider", 30.0f); _offsetAnimation.SetScalarParameter("MaxOffsetY", REFRESH_ICON_MAX_OFFSET_Y); _offsetAnimation.SetReferenceParameter("ScrollManipulation", _scrollerViewerManipulation); _refreshIconVisual = ElementCompositionPreview.GetElementVisual(RefreshIcon); _refreshIconVisual.CenterPoint = new Vector3(Convert.ToSingle(RefreshIcon.Width / 2), Convert.ToSingle(RefreshIcon.Height / 2), 0); _refreshSymbleVisual = ElementCompositionPreview.GetElementVisual(RefreshSymble); _refreshSymbleVisual.CenterPoint = new Vector3(Convert.ToSingle(RefreshSymble.Width / 2), Convert.ToSingle(RefreshSymble.Height / 2), 0); // Kick off the animations. OnRefreshComplete(); }
private void GridView_Loaded(object sender, RoutedEventArgs e) { var scroll = List.Descendants <ScrollViewer>().FirstOrDefault() as ScrollViewer; if (scroll != null) { _scrollingHost = scroll; _scrollingHost.ChangeView(null, 0, null, true); scroll.ViewChanged += Scroll_ViewChanged; Scroll_ViewChanged(scroll, null); _scrollingHost.Padding = new Thickness(0, Math.Max(0, BackgroundPanel.Margin.Top - _scrollingHost.VerticalOffset), 0, 0); var brush = App.Current.Resources["SystemControlBackgroundChromeMediumLowBrush"] as SolidColorBrush; var props = ElementCompositionPreview.GetScrollViewerManipulationPropertySet(scroll); if (_background == null) { _background = ElementCompositionPreview.GetElementVisual(BackgroundPanel).Compositor.CreateSpriteVisual(); ElementCompositionPreview.SetElementChildVisual(BackgroundPanel, _background); } _background.Brush = _background.Compositor.CreateColorBrush(brush.Color); _background.Size = new System.Numerics.Vector2((float)BackgroundPanel.ActualWidth, (float)BackgroundPanel.ActualHeight); _background.Clip = _background.Compositor.CreateInsetClip(); _groupHeader = ElementCompositionPreview.GetElementVisual(GroupHeader); _expression = _expression ?? _background.Compositor.CreateExpressionAnimation("Max(Maximum, Scrolling.Translation.Y)"); _expression.SetReferenceParameter("Scrolling", props); _expression.SetScalarParameter("Maximum", -(float)BackgroundPanel.Margin.Top + 1); _background.StopAnimation("Offset.Y"); _background.StartAnimation("Offset.Y", _expression); _expressionHeader = _expressionHeader ?? _background.Compositor.CreateExpressionAnimation("Max(0, Maximum - Scrolling.Translation.Y)"); _expressionHeader.SetReferenceParameter("Scrolling", props); _expressionHeader.SetScalarParameter("Maximum", -(float)BackgroundPanel.Margin.Top); _groupHeader.StopAnimation("Offset.Y"); _groupHeader.StartAnimation("Offset.Y", _expressionHeader); _expressionClip = _expressionClip ?? _background.Compositor.CreateExpressionAnimation("Min(0, Maximum - Scrolling.Translation.Y)"); _expressionClip.SetReferenceParameter("Scrolling", props); _expressionClip.SetScalarParameter("Maximum", -(float)BackgroundPanel.Margin.Top + 1); _background.Clip.StopAnimation("Offset.Y"); _background.Clip.StartAnimation("Offset.Y", _expressionClip); } var panel = List.ItemsPanelRoot as ItemsWrapGrid; if (panel != null) { panel.SizeChanged += (s, args) => { Scroll_ViewChanged(scroll, null); }; } }
// Layer (Shape): Shape Layer 1 CompositionContainerShape ContainerShape_3() { var result = _c.CreateContainerShape(); result.TransformMatrix = new Matrix3x2(0, 0, 0, 0, 0, 0); var shapes = result.Shapes; shapes.Add(SpriteShape_3()); result.StartAnimation("TransformMatrix._11", ScalarAnimation_1_to_0()); var controller = result.TryGetAnimationController("TransformMatrix._11"); controller.Pause(); controller.StartAnimation("Progress", _scalarExpressionAnimation); _reusableExpressionAnimation.ClearAllParameters(); _reusableExpressionAnimation.Expression = "my.TransformMatrix._11"; _reusableExpressionAnimation.SetReferenceParameter("my", result); result.StartAnimation("TransformMatrix._22", _reusableExpressionAnimation); return(result); }
/// <summary> /// Sets up the composition animations that position the Refresh Indicator and main content /// based on the overpan amount. /// </summary> private void UpdateCompositionAnimations() { if (m_root != null && m_scroller != null && m_scrollerContent != null && m_refreshIndicatorContainer != null) { if (m_scrollerContentAnimation == null) { CompositionPropertySet scrollingProperties = ElementCompositionPreview.GetScrollViewerManipulationPropertySet(m_scroller); Compositor compositor = scrollingProperties.Compositor; // Ensure that the maximum overpan amount corresponds to the Refresh Indicator's height. m_scrollerContentVisual = ElementCompositionPreview.GetElementVisual(m_scrollerContent); m_scrollerContentAnimation = compositor.CreateExpressionAnimation(@"overpanMultiplier * max(0, scrollingProperties.Translation.Y)"); m_scrollerContentAnimation.SetReferenceParameter("scrollingProperties", scrollingProperties); // Ensure that the Refresh Indicator is positioned on top of the main content. m_refreshIndicatorContainerVisual = ElementCompositionPreview.GetElementVisual(m_refreshIndicatorContainer); m_refreshIndicatorContainerAnimation = compositor.CreateExpressionAnimation(@"-refreshIndicatorContainerHeight"); // Create RefreshPropertySet and populate it with the PullRatio and PullProgress variables that vary from 0 to 1. this.RefreshPropertySet = compositor.CreatePropertySet(); m_pullRatioAnimation = compositor.CreateExpressionAnimation(@"clamp(max(0, scrollingProperties.Translation.Y) / maxOverpan + staticRatio, 0, 1)"); m_pullRatioAnimation.SetReferenceParameter("scrollingProperties", scrollingProperties); this.RefreshPropertySet.InsertScalar("PullRatio", 0); m_pullProgressAnimation = compositor.CreateExpressionAnimation(@"clamp(max(0, scrollingProperties.Translation.Y) / thresholdOverpan + staticProgress, 0, 1)"); m_pullProgressAnimation.SetReferenceParameter("scrollingProperties", scrollingProperties); this.RefreshPropertySet.InsertScalar("PullProgress", 0); } m_scrollerContentAnimation.SetScalarParameter("overpanMultiplier", (float)(m_refreshIndicatorContainer.ActualHeight / m_scroller.ActualHeight / MAX_SCROLLVIEWER_OVERPAN_RATIO - 1.0f / m_scroller.ZoomFactor)); m_scrollerContentVisual.StartAnimation("Offset.Y", m_scrollerContentAnimation); m_refreshIndicatorContainerAnimation.SetScalarParameter("refreshIndicatorContainerHeight", (float)m_refreshIndicatorContainer.ActualHeight); m_refreshIndicatorContainerVisual.StartAnimation("Offset.Y", m_refreshIndicatorContainerAnimation); float maxOverpan = (float)(m_scroller.ActualHeight * MAX_SCROLLVIEWER_OVERPAN_RATIO); m_pullRatioAnimation.SetScalarParameter("maxOverpan", maxOverpan); float staticRatio = (m_isAutoRefreshing || m_isSuppressingOverpan || m_scrollerContent.ManipulationMode == ManipulationModes.None) ? (float)DEFAULT_REFRESH_INDICATOR_THRESHOLD_RATIO : 0.0f; m_pullRatioAnimation.SetScalarParameter("staticRatio", staticRatio); this.RefreshPropertySet.StartAnimation("PullRatio", m_pullRatioAnimation); float thresholdOverpan = (float)(double.IsNaN(this.PullThreshold) ? (m_scroller.ActualHeight * MAX_SCROLLVIEWER_OVERPAN_RATIO * DEFAULT_REFRESH_INDICATOR_THRESHOLD_RATIO) : this.PullThreshold); m_pullProgressAnimation.SetScalarParameter("thresholdOverpan", thresholdOverpan); float staticProgress = (m_refreshActivated || m_isAutoRefreshing || m_isSuppressingOverpan || m_scrollerContent.ManipulationMode == ManipulationModes.None) ? 1.0f : 0.0f; m_pullProgressAnimation.SetScalarParameter("staticProgress", staticProgress); this.RefreshPropertySet.StartAnimation("PullProgress", m_pullProgressAnimation); } }
private void ConfigureGearAnimation(Visual currentGear, Visual previousGear) { // If rotation expression is null then create an expression of a gear rotating the opposite direction _rotationExpression = _rotationExpression ?? _compositor.CreateExpressionAnimation("-previousGear.RotationAngleInDegrees"); // put in placeholder parameters _rotationExpression.SetReferenceParameter("previousGear", previousGear); // Start the animation based on the Rotation Angle in Degrees. currentGear.StartAnimation("RotationAngleInDegrees", _rotationExpression); }
private void BackgroundController_AcrylicPresenterWasSet(object sender, EventArgs e) { Visual ElementVisual = ElementCompositionPreview.GetElementVisual(CompositionAcrylicPresenter); Compositor VisualCompositor = ElementVisual.Compositor; CompositionBackdropBrush BackdropBrush = VisualCompositor.CreateHostBackdropBrush(); float AcrylicAmount; if (double.TryParse(Convert.ToString(ApplicationData.Current.LocalSettings.Values["BackgroundTintLuminosity"]), out double TintLuminosity)) { AcrylicAmount = Convert.ToSingle(TintLuminosity); } else { AcrylicAmount = 0.8f; } GaussianBlurEffect BlurEffect = new GaussianBlurEffect() { BlurAmount = 10f, BorderMode = EffectBorderMode.Hard, Optimization = EffectOptimization.Balanced, Source = new ArithmeticCompositeEffect { Name = "Mix", MultiplyAmount = 0, Source1 = new CompositionEffectSourceParameter("backdropBrush"), Source2 = new ColorSourceEffect { Name = "Tint", Color = (Color)AcrylicBackgroundBrush.GetValue(AcrylicBrush.TintColorProperty) }, Source1Amount = AcrylicAmount, Source2Amount = 1 - AcrylicAmount } }; CompositionAcrylicBrush = VisualCompositor.CreateEffectFactory(BlurEffect, new[] { "Mix.Source1Amount", "Mix.Source2Amount", "Tint.Color" }).CreateBrush(); CompositionAcrylicBrush.SetSourceParameter("backdropBrush", BackdropBrush); SpriteVisual SpVisual = VisualCompositor.CreateSpriteVisual(); SpVisual.Brush = CompositionAcrylicBrush; ElementCompositionPreview.SetElementChildVisual(CompositionAcrylicPresenter, SpVisual); ExpressionAnimation bindSizeAnimation = VisualCompositor.CreateExpressionAnimation("ElementVisual.Size"); bindSizeAnimation.SetReferenceParameter("ElementVisual", ElementVisual); SpVisual.StartAnimation("Size", bindSizeAnimation); PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(TintLuminosityOpacity))); PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(AcrylicColor))); }
public static ExpressionAnimation StartExpressionAnimation( [NotNull] this ScrollViewer scroller, [NotNull] UIElement target, Axis sourceXY, Axis?targetXY = null, bool invertSourceAxis = false) { CompositionPropertySet scrollSet = ElementCompositionPreview.GetScrollViewerManipulationPropertySet(scroller); string sign = invertSourceAxis ? "-" : string.Empty; ExpressionAnimation animation = scrollSet.Compositor.CreateExpressionAnimation($"{sign}scroll.Translation.{sourceXY}"); animation.SetReferenceParameter("scroll", scrollSet); target.GetVisual().StartAnimation($"Offset.{targetXY ?? sourceXY}", animation); return(animation); }
protected override void OnConnected(UIElement targetElement) { if (targetElement == null) { return; } Compositor compositor = Window.Current.Compositor; // Create SpotLight and set its properties SpotLight spotLight = compositor.CreateSpotLight(); spotLight.InnerConeColor = Colors.FloralWhite; spotLight.OuterConeColor = Colors.FloralWhite; spotLight.InnerConeAngleInDegrees = 0f; spotLight.InnerConeIntensity = 4; //spotLight.OuterConeAngleInDegrees = 3f; spotLight.ConstantAttenuation = 1f; spotLight.LinearAttenuation = 0.253f; spotLight.QuadraticAttenuation = 0.58f; spotLight.Offset = new Vector3(0, 0, 0); // Associate CompositionLight with XamlLight this.CompositionLight = spotLight; // Define resting position Animation Vector3 restingPosition = new Vector3(200, 200, 400); CubicBezierEasingFunction cbEasing = compositor.CreateCubicBezierEasingFunction(new Vector2(0.3f, 0.7f), new Vector2(0.9f, 0.5f)); _offsetAnimation = compositor.CreateVector3KeyFrameAnimation(); _offsetAnimation.InsertKeyFrame(1, restingPosition, cbEasing); _offsetAnimation.Duration = TimeSpan.FromSeconds(0.5f); //spotLight.Offset = restingPosition; // Define expression animation that relates light's offset to pointer position CompositionPropertySet hoverPosition = ElementCompositionPreview.GetPointerPositionPropertySet(targetElement); _lightPositionExpression = compositor.CreateExpressionAnimation("Vector3(hover.Position.X, hover.Position.Y, height)"); _lightPositionExpression.SetReferenceParameter("hover", hoverPosition); _lightPositionExpression.SetScalarParameter("height", 150f); // Configure pointer entered/ exited events targetElement.PointerMoved += TargetElement_PointerMoved; targetElement.PointerExited += TargetElement_PointerExited; // Add UIElement to the Light's Targets HoverLight.AddTargetElement(GetId(), targetElement); //MoveToRestingPosition(); }
public void StartAnimation(bool update = false) { if (update || expression == null || visual == null) { visual = ElementCompositionPreview.GetElementVisual(VisualElement); //if (0 <= VisualElement.Margin.Top && VisualElement.Margin.Top <= ScrollViewer.ActualHeight) //{ // min = (float)-VisualElement.Margin.Top; // max = (float)ScrollViewer.ActualHeight + min; //} //else if (VisualElement.Margin.Top < 0) //{ //} //else if (VisualElement.Margin.Top > ScrollViewer.ActualHeight) //{ //} if (scrollViewerManipProps == null) { scrollViewerManipProps = ElementCompositionPreview.GetScrollViewerManipulationPropertySet(ScrollViewer); } Compositor compositor = scrollViewerManipProps.Compositor; // Create the expression //expression = compositor.CreateExpressionAnimation("min(max((ScrollViewerManipProps.Translation.Y + VerticalOffset), MinValue), MaxValue)"); ////Expression = compositor.CreateExpressionAnimation("ScrollViewerManipProps.Translation.Y +VerticalOffset"); //expression.SetScalarParameter("MinValue", min); //expression.SetScalarParameter("MaxValue", max); //expression.SetScalarParameter("VerticalOffset", (float)ScrollViewer.VerticalOffset); expression = compositor.CreateExpressionAnimation("ScrollViewerManipProps.Translation.Y + VerticalOffset"); ////Expression = compositor.CreateExpressionAnimation("ScrollViewerManipProps.Translation.Y +VerticalOffset"); //expression.SetScalarParameter("MinValue", min); //expression.SetScalarParameter("MaxValue", max); VerticalOffset = ScrollViewer.VerticalOffset; expression.SetScalarParameter("VerticalOffset", (float)ScrollViewer.VerticalOffset); // set "dynamic" reference parameter that will be used to evaluate the current position of the scrollbar every frame expression.SetReferenceParameter("ScrollViewerManipProps", scrollViewerManipProps); } visual.StartAnimation("Offset.Y", expression); IsActive = true; //Windows.UI.Xaml.Media.CompositionTarget.Rendering -= OnCompositionTargetRendering; //Windows.UI.Xaml.Media.CompositionTarget.Rendering += OnCompositionTargetRendering; }
public static ScalarExpressionAnimation StartExpressionAnimation( [NotNull] this ScrollViewer scroller, [NotNull] UIElement target, Axis sourceXY, float parameter, Axis?targetXY = null, bool invertSourceAxis = false) { // Get the property set and setup the scroller offset sign CompositionPropertySet scrollSet = ElementCompositionPreview.GetScrollViewerManipulationPropertySet(scroller); string sign = invertSourceAxis ? "-" : "+"; // Prepare the second property set to insert the additional parameter CompositionPropertySet properties = scroller.GetVisual().Compositor.CreatePropertySet(); properties.InsertScalar(nameof(parameter), parameter); // Create and start the animation ExpressionAnimation animation = scrollSet.Compositor.CreateExpressionAnimation($"{nameof(properties)}.{nameof(parameter)} {sign} scroll.Translation.{sourceXY}"); animation.SetReferenceParameter("scroll", scrollSet); animation.SetReferenceParameter(nameof(properties), properties); target.GetVisual().StartAnimation($"Offset.{targetXY ?? sourceXY}", animation); return(new ScalarExpressionAnimation(animation, properties, nameof(parameter))); }
private void CreateVisual() { visual = ElementCompositionPreview.GetElementVisual(currentTopGroupHeader); var scrollViewerManipProps = ElementCompositionPreview.GetScrollViewerManipulationPropertySet(scrollViewer); Compositor compositor = scrollViewerManipProps.Compositor; expression = compositor.CreateExpressionAnimation("max(0,ScrollViewerManipProps.Translation.Y)"); // set "dynamic" reference parameter that will be used to evaluate the current position of the scrollbar every frame expression.SetReferenceParameter("ScrollViewerManipProps", scrollViewerManipProps); visual.StartAnimation("Offset.Y", expression); //Windows.UI.Xaml.Media.CompositionTarget.Rendering += OnCompositionTargetRendering; }
public MainPage() { this.InitializeComponent(); ContactsCVS.Source = _list; this.Loaded += (s, e) => { _scrollViewer = ListView.GetScrollViewer(); _scrollViewer.DirectManipulationStarted += OnDirectManipulationStarted; _scrollViewer.DirectManipulationCompleted += OnDirectManipulationCompleted; // Retrieve the ScrollViewer manipulation and the Compositor. _scrollerViewerManipulation = ElementCompositionPreview.GetScrollViewerManipulationPropertySet(_scrollViewer); _compositor = _scrollerViewerManipulation.Compositor; // At the moment there are three things happening when pulling down the list - // 1. The Refresh Icon fades in. // 2. The Refresh Icon rotates (400°). // 3. The Refresh Icon gets pulled down a bit (REFRESH_ICON_MAX_OFFSET_Y) // QUESTION 5 // Can we also have Geometric Path animation so we can also draw the Refresh Icon along the way? // // Create a rotation expression animation based on the overpan distance of the ScrollViewer. _rotationAnimation = _compositor.CreateExpressionAnimation("min(max(0, ScrollManipulation.Translation.Y) * Multiplier, MaxDegree)"); _rotationAnimation.SetScalarParameter("Multiplier", 10.0f); _rotationAnimation.SetScalarParameter("MaxDegree", 400.0f); _rotationAnimation.SetReferenceParameter("ScrollManipulation", _scrollerViewerManipulation); // Create an opacity expression animation based on the overpan distance of the ScrollViewer. _opacityAnimation = _compositor.CreateExpressionAnimation("min(max(0, ScrollManipulation.Translation.Y) / Divider, 1)"); _opacityAnimation.SetScalarParameter("Divider", 30.0f); _opacityAnimation.SetReferenceParameter("ScrollManipulation", _scrollerViewerManipulation); // Create an offset expression animation based on the overpan distance of the ScrollViewer. _offsetAnimation = _compositor.CreateExpressionAnimation("(min(max(0, ScrollManipulation.Translation.Y) / Divider, 1)) * MaxOffsetY"); _offsetAnimation.SetScalarParameter("Divider", 30.0f); _offsetAnimation.SetScalarParameter("MaxOffsetY", REFRESH_ICON_MAX_OFFSET_Y); _offsetAnimation.SetReferenceParameter("ScrollManipulation", _scrollerViewerManipulation); // Create a keyframe animation to reset properties like Offset.Y, Opacity, etc. _resetAnimation = _compositor.CreateScalarKeyFrameAnimation(); _resetAnimation.InsertKeyFrame(1.0f, 0.0f); // Create a loading keyframe animation (in this case, a rotation animation). _loadingAnimation = _compositor.CreateScalarKeyFrameAnimation(); _loadingAnimation.InsertKeyFrame(1.0f, 360); _loadingAnimation.Duration = TimeSpan.FromMilliseconds(1200); _loadingAnimation.IterationBehavior = AnimationIterationBehavior.Forever; // Get the RefreshIcon's Visual. _refreshIconVisual = ElementCompositionPreview.GetElementVisual(RefreshIcon); // Set the center point for the rotation animation. _refreshIconVisual.CenterPoint = new Vector3(Convert.ToSingle(RefreshIcon.ActualWidth / 2), Convert.ToSingle(RefreshIcon.ActualHeight / 2), 0); // Get the ListView's inner Border's Visual. var border = (Border)VisualTreeHelper.GetChild(ListView, 0); _borderVisual = ElementCompositionPreview.GetElementVisual(border); PrepareExpressionAnimationsOnScroll(); }; this.Unloaded += (s, e) => { _scrollViewer.DirectManipulationStarted -= OnDirectManipulationStarted; _scrollViewer.DirectManipulationCompleted -= OnDirectManipulationCompleted; }; }
private void ScrollViewer_Loaded(object sender, RoutedEventArgs e) { _scrollViewer.DirectManipulationStarted += ScrollViewer_DirectManipulationStarted; _scrollViewer.DirectManipulationCompleted += ScrollViewer_DirectManipulationCompleted; var border = (Border)VisualTreeHelper.GetChild(_scrollViewer, 0); _scrollViewerBorder = border; _scrollerViewerManipulation = ElementCompositionPreview.GetScrollViewerManipulationPropertySet(_scrollViewer); _compositor = _scrollerViewerManipulation.Compositor; double ratio = 1.0; _header.Measure(new Size(this.ActualWidth, this.ActualHeight)); var headerHeight = _header.DesiredSize.Height; if (headerHeight == 0) { headerHeight = 50; } if (RefreshThreshold == 0.0) { RefreshThreshold = headerHeight; } ratio = RefreshThreshold / headerHeight; _offsetAnimation = _compositor.CreateExpressionAnimation("(min(max(0, ScrollManipulation.Translation.Y * ratio) / Divider, 1)) * MaxOffsetY"); _offsetAnimation.SetScalarParameter("Divider", (float)RefreshThreshold); _offsetAnimation.SetScalarParameter("MaxOffsetY", (float)RefreshThreshold * 5 / 4); _offsetAnimation.SetScalarParameter("ratio", (float)ratio); _offsetAnimation.SetReferenceParameter("ScrollManipulation", _scrollerViewerManipulation); _opacityAnimation = _compositor.CreateExpressionAnimation("min((max(0, ScrollManipulation.Translation.Y * ratio) / Divider), 1)"); _opacityAnimation.SetScalarParameter("Divider", (float)headerHeight); _opacityAnimation.SetScalarParameter("ratio", (float)1); _opacityAnimation.SetReferenceParameter("ScrollManipulation", _scrollerViewerManipulation); _headerVisual = ElementCompositionPreview.GetElementVisual(_header); _contentVisual = ElementCompositionPreview.GetElementVisual(_scrollViewerBorder); _headerVisual.StartAnimation("Offset.Y", _offsetAnimation); _headerVisual.StartAnimation("Opacity", _opacityAnimation); _contentVisual.StartAnimation("Offset.Y", _offsetAnimation); }
private void UpdatePerspectiveMatrix() { if (!m_setUpExpressions) { Vector3 perspectiveOrigin = new Vector3(PerspectiveOriginPercent * m_rootVisual.Size, 0); Matrix4x4 transform = Matrix4x4.CreateTranslation(-perspectiveOrigin) * new Matrix4x4(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, -1 / (float)PerspectiveDepth, 0, 0, 0, 1) * Matrix4x4.CreateTranslation(perspectiveOrigin); m_rootVisual.TransformMatrix = transform; } else if (m_matrixExpression == null) { m_matrixExpression = m_compositor.CreateExpressionAnimation(); m_matrixExpression.Properties.InsertVector3("LayoutSize", new Vector3(m_rootVisual.Size, 0)); // Expressions don't have an easy way to convert vector2 to vector3. But having this intermediate expression makes the below expression cleaner anyway. var perspectiveOriginExpression = m_compositor.CreateExpressionAnimation( "Vector3(publicProps.PerspectiveOriginPercent.x, publicProps.PerspectiveOriginPercent.y, 0) * props.LayoutSize"); perspectiveOriginExpression.SetReferenceParameter("publicProps", m_rootVisual.Properties); perspectiveOriginExpression.SetReferenceParameter("props", m_matrixExpression.Properties); m_matrixExpression.Properties.InsertVector3("PerspectiveOrigin", Vector3.Zero); m_matrixExpression.Properties.StartAnimation("PerspectiveOrigin", perspectiveOriginExpression); m_matrixExpression.Expression = "Matrix4x4.CreateFromTranslation(-props.PerspectiveOrigin) * " + "Matrix4x4(1,0,0,0, 0,1,0,0, 0,0,1,-1/publicProps.PerspectiveDepth, 0,0,0,1) * " + "Matrix4x4.CreateFromTranslation( props.PerspectiveOrigin)"; m_matrixExpression.SetReferenceParameter("publicProps", m_rootVisual.Properties); m_matrixExpression.SetReferenceParameter("props", m_matrixExpression.Properties); m_rootVisual.StartAnimation("TransformMatrix", m_matrixExpression); } }
private void OnSizeChanged(object sender, Windows.UI.Xaml.SizeChangedEventArgs e) { Vector2 size = new System.Numerics.Vector2((float)this.ActualWidth, (float)this.ActualHeight); if (m_interactionTracker != null) { m_interactionTracker.MinPosition = new Vector3(-size.X, 0, 0); m_interactionTracker.MaxPosition = new Vector3(size.X, 0, 0); if (Content != null) { var positionExpression = m_compositor.CreateExpressionAnimation("-tracker.Position"); positionExpression.SetReferenceParameter("tracker", m_interactionTracker); m_contentVisual = ElementCompositionPreview.GetElementVisual(Content); m_contentVisual.StartAnimation("Offset", positionExpression); m_contentVisual.Size = size; if (m_setUpExpressions && m_progressAnimation == null) { m_progressAnimation = m_compositor.CreateExpressionAnimation( "clamp(visual.Offset.X / visual.Size.X, -1, 1)"); m_progressAnimation.SetReferenceParameter("visual", m_contentVisual); m_rootVisual.Properties.StartAnimation("NormalizedProgress", m_progressAnimation); } } } }
private void CreateAnimationTemplates(Compositor compositor) { // // Near-slide and far-slide animations. // _nearSlideOffsetAnimation = compositor.CreateVector3KeyFrameAnimation(); _nearSlideOffsetAnimation.InsertExpressionKeyFrame(0.0f, "this.StartingValue"); _nearSlideOffsetAnimation.InsertExpressionKeyFrame(1.0f, "vector3(0,0,0) - myViewportCenter"); _farSlideOffsetAnimation = compositor.CreateVector3KeyFrameAnimation(); _farSlideOffsetAnimation.InsertExpressionKeyFrame(0.0f, "this.StartingValue"); _farSlideOffsetAnimation.InsertExpressionKeyFrame(0.9f, "vector3(0,0,0) - myViewportCenter"); _farSlideOffsetAnimation.InsertExpressionKeyFrame(1.0f, "vector3(0,0,0) - myViewportCenter"); _slideCenterAnimation = compositor.CreateVector3KeyFrameAnimation(); _slideCenterAnimation.InsertExpressionKeyFrame(0.0f, "this.StartingValue"); _slideCenterAnimation.InsertExpressionKeyFrame(1.0f, "myTargetCenterPoint"); _nearSlideScaleAnimation = compositor.CreateVector3KeyFrameAnimation(); _nearSlideScaleAnimation.InsertExpressionKeyFrame(0.00f, "this.StartingValue"); _nearSlideScaleAnimation.InsertExpressionKeyFrame(1.00f, "myScale"); _farSlideScaleAnimation = compositor.CreateVector3KeyFrameAnimation(); _farSlideScaleAnimation.InsertExpressionKeyFrame(0.00f, "this.StartingValue"); _farSlideScaleAnimation.InsertKeyFrame(0.30f, new Vector3(1.0f, 1.0f, 1.0f)); _farSlideScaleAnimation.InsertKeyFrame(1.00f, new Vector3(1.0f, 1.0f, 1.0f)); TimeSpan time4sec = TimeSpan.FromSeconds(4); TimeSpan time8sec = TimeSpan.FromSeconds(8); _nearSlideOffsetAnimation.Duration = time4sec; _farSlideOffsetAnimation.Duration = time8sec; _slideCenterAnimation.Duration = time4sec; _nearSlideScaleAnimation.Duration = time4sec; _farSlideScaleAnimation.Duration = time4sec; // // Zoom animations. // _zoomScaleAnimation = compositor.CreateVector3KeyFrameAnimation(); _zoomScaleAnimation.InsertExpressionKeyFrame(0.00f, "this.StartingValue"); _zoomScaleAnimation.InsertKeyFrame(0.40f, new Vector3(1.0f, 1.0f, 1.0f)); _zoomScaleAnimation.InsertKeyFrame(0.60f, new Vector3(1.0f, 1.0f, 1.0f)); _zoomScaleAnimation.InsertExpressionKeyFrame(1.00f, "myScale"); _zoomCenterAnimation = compositor.CreateVector3KeyFrameAnimation(); _zoomCenterAnimation.InsertExpressionKeyFrame(0.00f, "this.StartingValue"); _zoomCenterAnimation.InsertExpressionKeyFrame(0.40f, "this.StartingValue"); _zoomCenterAnimation.InsertExpressionKeyFrame(0.60f, "myTargetCenterPoint"); _zoomCenterAnimation.InsertExpressionKeyFrame(1.00f, "myTargetCenterPoint"); _zoomOffsetAnimation = compositor.CreateVector3KeyFrameAnimation(); _zoomOffsetAnimation.InsertExpressionKeyFrame(0.00f, "this.StartingValue"); _zoomOffsetAnimation.InsertExpressionKeyFrame(1.00f, "vector3(0,0,0) - myViewportCenter"); TimeSpan time12sec = TimeSpan.FromSeconds(12); _zoomScaleAnimation.Duration = time12sec; _zoomCenterAnimation.Duration = time12sec; _zoomOffsetAnimation.Duration = time12sec; // // Stack animations. // CubicBezierEasingFunction flyInEasing; CubicBezierEasingFunction flyOutEasing; flyInEasing = compositor.CreateCubicBezierEasingFunction(new Vector2(0.0f, 1.0f), new Vector2(0.8f, 1.0f)); _stackFlyInAnimation = compositor.CreateVector3KeyFrameAnimation(); _stackFlyInAnimation.InsertExpressionKeyFrame(0.00f, "stackVisual.Offset + startDelta"); _stackFlyInAnimation.InsertExpressionKeyFrame(1.00f, "stackVisual.Offset + endDelta", flyInEasing); _stackFlyInAnimation.Duration = TimeSpan.FromSeconds(2); flyOutEasing = compositor.CreateCubicBezierEasingFunction(new Vector2(0.0f, 0.4f), new Vector2(1.0f, 0.6f)); _stackFlyOutAnimation = compositor.CreateVector3KeyFrameAnimation(); _stackFlyOutAnimation.InsertExpressionKeyFrame(0.00f, "this.StartingValue", flyOutEasing); _stackFlyOutAnimation.InsertExpressionKeyFrame(0.50f, "this.StartingValue + delta", flyOutEasing); _stackFlyOutAnimation.InsertExpressionKeyFrame(1.00f, "originalOffset", flyOutEasing); _stackFlyOutAnimation.Duration = TimeSpan.FromSeconds(2); _stackScaleAnimation = compositor.CreateVector3KeyFrameAnimation(); _stackScaleAnimation.InsertExpressionKeyFrame(0.00f, "this.StartingValue"); _stackScaleAnimation.InsertExpressionKeyFrame(1.00f, "myScale"); _stackScaleAnimation.Duration = TimeSpan.FromSeconds(6); // // Color flashlight expression animation. // // This expression returns a computes between 0 and 1 as a function of on how close the // center of the frame is to the center of the window. // - If the frame is at the center of the window, the expression computes 0 (no // desaturation). // - If the frame is more than 300px away from the center of the window, the // expression computes 1 (full desaturation). // - If the frame is within 300px from the center of the window, the expression // computes a value between 0 and 1 relative to how far the frame is from the 300px // boundary (partial desaturation). _colorFlashlightAnimation = compositor.CreateExpressionAnimation( "1.0 - min(" + " 1.0," + " (" + " (" + " ( frame.Offset.x + (frame.Size.x * 0.5) + grid.Offset.x - (windowWidth * 0.5) )" + " * ( frame.Offset.x + (frame.Size.x * 0.5) + grid.Offset.x - (windowWidth * 0.5) )" + " ) + (" + " ( frame.Offset.y + (frame.Size.y * 0.5) + grid.Offset.y - (windowHeight * 0.5) )" + " * ( frame.Offset.y + (frame.Size.y * 0.5) + grid.Offset.y - (windowHeight * 0.5) )" + " )" + " ) / ( radius * radius )" + ")"); _colorFlashlightAnimation.SetReferenceParameter("grid", _layoutManager.GridVisual); _colorFlashlightAnimation.SetScalarParameter("radius", 300); _colorFlashlightAnimation.SetScalarParameter("windowWidth", _windowWidth); _colorFlashlightAnimation.SetScalarParameter("windowHeight", _windowHeight); }
private void SetupSkyVisualOffsetExpressionAnimation() { // Kick off an expression animation that links the roll & pitch degress to the -offset of the sky canvas visual // TODO: Need to constraint the offset (total offset < dimension * SkyVisualAreaRatio) with // CreateConditionalExpressionAnimation once the next mobile build is available. _skyViusalOffsetExpressionAnimation = _compositor.CreateExpressionAnimation( "Vector3(SkyVisual.Offset.X - Reading.Offset.X * Sensitivity, SkyVisual.Offset.Y - Reading.Offset.Y * Sensitivity, 0.0f)"); _skyViusalOffsetExpressionAnimation.SetReferenceParameter("SkyVisual", _skyVisual); _skyViusalOffsetExpressionAnimation.SetReferenceParameter("Reading", _reading); _skyViusalOffsetExpressionAnimation.SetScalarParameter("Sensitivity", 0.2f); //_skyViusalOffsetExpressionAnimation.SetScalarParameter("MaxDimension", SkyVisualRadius * 2 * SkyVisualAreaRatio); _skyVisual.StartAnimation("Offset", _skyViusalOffsetExpressionAnimation); }
private void ConfigureGearAnimation(Visual currentGear, Visual previousGear) { // If rotation expression is null then create an expression of a gear rotating the opposite direction _rotationExpression = _rotationExpression ?? _compositor.CreateExpressionAnimation("-previousGear.RotationAngleInDegrees"); // put in placeholder parameters _rotationExpression.SetReferenceParameter("previousGear", previousGear); // Start the animation based on the Rotation Angle in Degrees. currentGear.StartAnimation("RotationAngleInDegrees", _rotationExpression); }
/// <summary> /// Sets up the composition animations that position the Refresh Indicator and main content /// based on the overpan amount. /// </summary> private void UpdateCompositionAnimations() { if (m_root != null && m_scroller != null && m_scrollerContent != null && m_refreshIndicatorContainer != null) { if (m_scrollerContentAnimation == null) { CompositionPropertySet scrollingProperties = ElementCompositionPreview.GetScrollViewerManipulationPropertySet(m_scroller); Compositor compositor = scrollingProperties.Compositor; // Ensure that the maximum overpan amount corresponds to the Refresh Indicator's height. m_scrollerContentVisual = ElementCompositionPreview.GetElementVisual(m_scrollerContent); m_scrollerContentAnimation = compositor.CreateExpressionAnimation(@"overpanMultiplier * max(0, scrollingProperties.Translation.Y)"); m_scrollerContentAnimation.SetReferenceParameter("scrollingProperties", scrollingProperties); // Ensure that the Refresh Indicator is positioned on top of the main content. m_refreshIndicatorContainerVisual = ElementCompositionPreview.GetElementVisual(m_refreshIndicatorContainer); m_refreshIndicatorContainerAnimation = compositor.CreateExpressionAnimation(@"-refreshIndicatorContainerHeight"); // Create RefreshPropertySet and populate it with the PullRatio and PullProgress variables that vary from 0 to 1. this.RefreshPropertySet = compositor.CreatePropertySet(); m_pullRatioAnimation = compositor.CreateExpressionAnimation(@"clamp(max(0, scrollingProperties.Translation.Y) / maxOverpan + staticRatio, 0, 1)"); m_pullRatioAnimation.SetReferenceParameter("scrollingProperties", scrollingProperties); this.RefreshPropertySet.InsertScalar("PullRatio", 0); m_pullProgressAnimation = compositor.CreateExpressionAnimation(@"clamp(max(0, scrollingProperties.Translation.Y) / thresholdOverpan + staticProgress, 0, 1)"); m_pullProgressAnimation.SetReferenceParameter("scrollingProperties", scrollingProperties); this.RefreshPropertySet.InsertScalar("PullProgress", 0); } m_scrollerContentAnimation.SetScalarParameter("overpanMultiplier", (float)(m_refreshIndicatorContainer.ActualHeight / m_scroller.ActualHeight / MAX_SCROLLVIEWER_OVERPAN_RATIO - 1.0f / m_scroller.ZoomFactor)); m_scrollerContentVisual.StartAnimation("Offset.Y", m_scrollerContentAnimation); m_refreshIndicatorContainerAnimation.SetScalarParameter("refreshIndicatorContainerHeight", (float)m_refreshIndicatorContainer.ActualHeight); m_refreshIndicatorContainerVisual.StartAnimation("Offset.Y", m_refreshIndicatorContainerAnimation); float maxOverpan = (float)(m_scroller.ActualHeight * MAX_SCROLLVIEWER_OVERPAN_RATIO); m_pullRatioAnimation.SetScalarParameter("maxOverpan", maxOverpan); float staticRatio = (m_isAutoRefreshing || m_isSuppressingOverpan || m_scrollerContent.ManipulationMode == ManipulationModes.None) ? (float)DEFAULT_REFRESH_INDICATOR_THRESHOLD_RATIO : 0.0f; m_pullRatioAnimation.SetScalarParameter("staticRatio", staticRatio); this.RefreshPropertySet.StartAnimation("PullRatio", m_pullRatioAnimation); float thresholdOverpan = (float)(double.IsNaN(this.PullThreshold) ? (m_scroller.ActualHeight * MAX_SCROLLVIEWER_OVERPAN_RATIO * DEFAULT_REFRESH_INDICATOR_THRESHOLD_RATIO) : this.PullThreshold); m_pullProgressAnimation.SetScalarParameter("thresholdOverpan", thresholdOverpan); float staticProgress = (m_refreshActivated || m_isAutoRefreshing || m_isSuppressingOverpan || m_scrollerContent.ManipulationMode == ManipulationModes.None) ? 1.0f : 0.0f; m_pullProgressAnimation.SetScalarParameter("staticProgress", staticProgress); this.RefreshPropertySet.StartAnimation("PullProgress", m_pullProgressAnimation); } }
public void StartAnimation(bool update = false) { if (update || expression == null || visual == null) { visual = ElementCompositionPreview.GetElementVisual(VisualElement); //if (0 <= VisualElement.Margin.Top && VisualElement.Margin.Top <= ScrollViewer.ActualHeight) //{ // min = (float)-VisualElement.Margin.Top; // max = (float)ScrollViewer.ActualHeight + min; //} //else if (VisualElement.Margin.Top < 0) //{ //} //else if (VisualElement.Margin.Top > ScrollViewer.ActualHeight) //{ //} if (scrollViewerManipProps == null) { scrollViewerManipProps = ElementCompositionPreview.GetScrollViewerManipulationPropertySet(ScrollViewer); } Compositor compositor = scrollViewerManipProps.Compositor; // Create the expression //expression = compositor.CreateExpressionAnimation("min(max((ScrollViewerManipProps.Translation.Y + VerticalOffset), MinValue), MaxValue)"); ////Expression = compositor.CreateExpressionAnimation("ScrollViewerManipProps.Translation.Y +VerticalOffset"); //expression.SetScalarParameter("MinValue", min); //expression.SetScalarParameter("MaxValue", max); //expression.SetScalarParameter("VerticalOffset", (float)ScrollViewer.VerticalOffset); expression = compositor.CreateExpressionAnimation("ScrollViewerManipProps.Translation.Y + VerticalOffset"); ////Expression = compositor.CreateExpressionAnimation("ScrollViewerManipProps.Translation.Y +VerticalOffset"); //expression.SetScalarParameter("MinValue", min); //expression.SetScalarParameter("MaxValue", max); VerticalOffset = ScrollViewer.VerticalOffset; expression.SetScalarParameter("VerticalOffset", (float)ScrollViewer.VerticalOffset); // set "dynamic" reference parameter that will be used to evaluate the current position of the scrollbar every frame expression.SetReferenceParameter("ScrollViewerManipProps", scrollViewerManipProps); } visual.StartAnimation("Offset.Y", expression); IsActive = true; //Windows.UI.Xaml.Media.CompositionTarget.Rendering -= OnCompositionTargetRendering; //Windows.UI.Xaml.Media.CompositionTarget.Rendering += OnCompositionTargetRendering; }
private void ScrollViewer_Loaded(object sender, RoutedEventArgs e) { Compositor compositor = ElementCompositionPreview.GetElementVisual(this).Compositor; // 创建驱动视差滚动的表达式动画。 parallaxAnimation0 = compositor.CreateExpressionAnimation("MyForeground.Translation.X / MyParallaxRatio"); parallaxAnimation1 = compositor.CreateExpressionAnimation("MyForeground.Translation.X / MyParallaxRatio"); parallaxAnimation2 = compositor.CreateExpressionAnimation("MyForeground.Translation.X / MyParallaxRatio"); parallaxAnimation3 = compositor.CreateExpressionAnimation("MyForeground.Translation.X / MyParallaxRatio"); parallaxAnimation4 = compositor.CreateExpressionAnimation("((MyForeground.Translation.X / MyParallaxRatio) + offset)"); // 设置对前景对象的引用。 scrollViewerProperties = ElementCompositionPreview.GetScrollViewerManipulationPropertySet(RootScroll); parallaxAnimation0.SetReferenceParameter("MyForeground", scrollViewerProperties); parallaxAnimation1.SetReferenceParameter("MyForeground", scrollViewerProperties); parallaxAnimation2.SetReferenceParameter("MyForeground", scrollViewerProperties); parallaxAnimation3.SetReferenceParameter("MyForeground", scrollViewerProperties); parallaxAnimation4.SetReferenceParameter("MyForeground", scrollViewerProperties); // 设置背景对象视差滚动的速度。 parallaxAnimation0.SetScalarParameter("MyParallaxRatio", 1f); parallaxAnimation1.SetScalarParameter("MyParallaxRatio", 2f); parallaxAnimation2.SetScalarParameter("MyParallaxRatio", 4f); parallaxAnimation3.SetScalarParameter("MyParallaxRatio", 8f); parallaxAnimation4.SetScalarParameter("MyParallaxRatio", 0.5f); parallaxAnimation4.SetScalarParameter("offset", 3 * (float)ActualWidth); var backgroundVisual0 = ElementCompositionPreview.GetElementVisual(BGLayer0); var backgroundVisual1 = ElementCompositionPreview.GetElementVisual(BGLayer1); var backgroundVisual2 = ElementCompositionPreview.GetElementVisual(BGLayer2); var backgroundVisual3 = ElementCompositionPreview.GetElementVisual(BGLayer3); var backgroundVisual4 = ElementCompositionPreview.GetElementVisual(RootFrame); // 对背景对象开始视差动画。 backgroundVisual0.StartAnimation("Offset.X", parallaxAnimation0); backgroundVisual1.StartAnimation("Offset.X", parallaxAnimation1); backgroundVisual2.StartAnimation("Offset.X", parallaxAnimation2); backgroundVisual3.StartAnimation("Offset.X", parallaxAnimation3); backgroundVisual4.StartAnimation("Offset.X", parallaxAnimation4); MainFrame.Navigate(typeof(CitiesPage), "nimabi"); IndAni.Begin(); }