/// <summary> /// Create the Visual that will host the profile background image and setup /// the animations that will drive it. /// </summary> /// /// <param name="scrollProperties">A property set who has Translation.Y specified - typically the return from ElementCompositionPreview.GetScrollViewerManipulationPropertySet(...).</param> private void InitializeBackgroundImageVisual(CompositionPropertySet scrollProperties) { // // Get the visual for the background image, and let it parallax up until the BackgroundPeekSize. // BackgroundPeekSize is later defined as the amount of the image to leave showing. // _backgroundVisual = ElementCompositionPreview.GetElementVisual(ParallaxingImage); // // If the scrolling is positive (i.e., bouncing), don't translate at all. Then check to see if // we have parallaxed as far as we should go. If we haven't, keep parallaxing otherwise use // the scrolling translation to keep the background stuck with the background peeking out. // _backgroundTranslationAnimation = _compositor.CreateExpressionAnimation( "BaseOffset + (scrollingProperties.Translation.Y > 0 ? 0 : " + "( (1-ParallaxRatio) * -scrollingProperties.Translation.Y) < BackgroundPeekSize ? " + "(ParallaxRatio * -scrollingProperties.Translation.Y) : -BackgroundPeekSize-scrollingProperties.Translation.Y)"); _backgroundTranslationAnimation.SetReferenceParameter("scrollingProperties", scrollProperties); _backgroundTranslationAnimation.SetScalarParameter("ParallaxRatio", _parallaxRatio); _backgroundScaleAnimation = _compositor.CreateExpressionAnimation( "Lerp(" + "1," + "1+Amount," + "Clamp(scrollingProperties.Translation.Y/50,0,1)" + ")"); _backgroundScaleAnimation.SetScalarParameter("Amount", _backgroundScaleAmount); _backgroundScaleAnimation.SetReferenceParameter("scrollingProperties", scrollProperties); _backgroundBlurAnimation = _compositor.CreateExpressionAnimation( "Clamp(-scrollingProperties.Translation.Y / (BackgroundPeekSize * .5),0,1)"); _backgroundBlurAnimation.SetScalarParameter("Amount", _backgroundScaleAmount); _backgroundBlurAnimation.SetReferenceParameter("scrollingProperties", scrollProperties); _backgroundInverseBlurAnimation = _compositor.CreateExpressionAnimation( "1-Clamp(-scrollingProperties.Translation.Y / (BackgroundPeekSize * .5),0,1)"); _backgroundInverseBlurAnimation.SetScalarParameter("Amount", _backgroundScaleAmount); _backgroundInverseBlurAnimation.SetReferenceParameter("scrollingProperties", scrollProperties); // // We want to keep the Name/Title text in the middle of the background image. To start with, // we add the centerpoint - since we move the anchor point to (.5,/5) which XAML layout doesn't // expect - and the background offset offset to keep the element positioned with the background. // we then lerp between its existing position and its final position based on parallaxed distance // traveled. // _profileContentVisual = ElementCompositionPreview.GetElementVisual(ProfileContent); _profileContentTranslationAnimation = _compositor.CreateExpressionAnimation( "(-scrollingProperties.Translation.Y + Background.Offset.Y + Background.Size.Y/2)/2"); _profileContentTranslationAnimation.SetReferenceParameter("Background", _backgroundVisual); _profileContentTranslationAnimation.SetReferenceParameter("scrollingProperties", scrollProperties); _profileContentScaleAnimation = _compositor.CreateExpressionAnimation( "Lerp(1,ShrinkRatio, " + "Clamp( (Background.Offset.Y - Background.Size.Y/2) / (Background.Size.Y - BackgroundPeekSize),0,1))" ); _profileContentScaleAnimation.SetScalarParameter("ShrinkRatio", _contentShrinkRatio); _profileContentScaleAnimation.SetReferenceParameter("Background", _backgroundVisual); }
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; }
protected void List_Loaded(object sender, RoutedEventArgs e) { var scrollingHost = ScrollingHost.GetScrollViewer(); if (scrollingHost != null) { //ScrollingHost.ItemsPanelRoot.SizeChanged += ItemsPanelRoot_SizeChanged; //ScrollingHost.ItemsPanelRoot.MinHeight = ActualHeight + ProfileHeader.ActualHeight; Canvas.SetZIndex(ScrollingHost.ItemsPanelRoot, -1); var properties = ElementCompositionPreview.GetScrollViewerManipulationPropertySet(scrollingHost); var visual = ElementCompositionPreview.GetElementVisual(HeaderPanel); var panel = ElementCompositionPreview.GetElementVisual(ScrollingHost.ItemsPanelRoot); panel.Clip = panel.Compositor.CreateInsetClip(); ElementCompositionPreview.SetIsTranslationEnabled(HeaderPanel, true); _properties = visual.Compositor.CreatePropertySet(); _properties.InsertScalar("ActualHeight", ProfileHeader.ActualSize.Y + 16); _properties.InsertScalar("TopPadding", TopPadding); var translation = visual.Compositor.CreateExpressionAnimation( "scrollViewer.Translation.Y > -properties.ActualHeight ? 0 : -scrollViewer.Translation.Y - properties.ActualHeight"); translation.SetReferenceParameter("scrollViewer", properties); translation.SetReferenceParameter("properties", _properties); visual.StartAnimation("Translation.Y", translation); var clip = visual.Compositor.CreateExpressionAnimation( "scrollViewer.Translation.Y > -properties.ActualHeight ? 0 : -scrollViewer.Translation.Y - properties.ActualHeight - properties.TopPadding"); clip.SetReferenceParameter("scrollViewer", properties); clip.SetReferenceParameter("properties", _properties); panel.Clip.StartAnimation("TopInset", clip); //void handler(object _, object args) //{ // scrollingHost.LayoutUpdated -= handler; // scrollingHost.ChangeView(null, ViewModel.VerticalOffset, null, true); //} //scrollingHost.InvalidateScrollInfo(); //scrollingHost.ChangeView(null, ViewModel.VerticalOffset, null, true); //scrollingHost.LayoutUpdated += handler; scrollingHost.ViewChanged += OnViewChanged; } }
/// <summary> /// Create the Visual that will host the profile background image and setup /// the animations that will drive it. /// </summary> /// /// <param name="scrollProperties">A property set who has Translation.Y specified - typically the return from ElementCompositionPreview.GetScrollViewerManipulationPropertySet(...).</param> private void InitializeBackgroundImageVisual(CompositionPropertySet scrollProperties) { // // Get the visual for the background image, and let it parallax up until the BackgroundPeekSize. // BackgroundPeekSize is later defined as the amount of the image to leave showing. // _backgroundVisual = ElementCompositionPreview.GetElementVisual(ParallaxingImage); // // If the scrolling is positive (i.e., bouncing), don't translate at all. Then check to see if // we have parallaxed as far as we should go. If we haven't, keep parallaxing otherwise use // the scrolling translation to keep the background stuck with the background peeking out. // var scrollPropSet = scrollProperties.GetSpecializedReference <ManipulationPropertySetReferenceNode>(); var baseOffsetParam = ExpressionValues.Constant.CreateConstantScalar("BaseOffset"); var backgroundPeekSize = ExpressionValues.Constant.CreateConstantScalar("BackgroundPeekSize"); _backgroundTranslateExpression = baseOffsetParam + EF.Conditional(scrollPropSet.Translation.Y > 0, 0, EF.Conditional(((1 - _parallaxRatio) * -scrollPropSet.Translation.Y) < backgroundPeekSize, (_parallaxRatio * -scrollPropSet.Translation.Y), -backgroundPeekSize - scrollPropSet.Translation.Y)); _backgroundScaleExpression = EF.Lerp(1, 1 + _backgroundScaleAmount, EF.Clamp(scrollPropSet.Translation.Y / 50, 0, 1)); _backgroundBlurExpression = EF.Clamp(-scrollPropSet.Translation.Y / (backgroundPeekSize * 0.5f), 0, 1); _backgroundInverseBlurExpression = 1 - EF.Clamp(-scrollPropSet.Translation.Y / (backgroundPeekSize * 0.5f), 0, 1); // // We want to keep the Name/Title text in the middle of the background image. To start with, // we add the centerpoint - since we move the anchor point to (.5,/5) which XAML layout doesn't // expect - and the background offset offset to keep the element positioned with the background. // we then lerp between its existing position and its final position based on parallaxed distance // traveled. // _profileContentVisual = ElementCompositionPreview.GetElementVisual(ProfileContent); var background = _backgroundVisual.GetReference(); _profileTranslationExpression = (-scrollPropSet.Translation.Y + background.Offset.Y + background.Size.Y / 2) / 2; _profileScaleExpression = EF.Lerp( 1, _contentShrinkRatio, EF.Clamp((background.Offset.Y - background.Size.Y / 2) / (background.Size.Y - backgroundPeekSize), 0, 1)); }
/// <summary> /// Create the _frontVisual and the animations that drive it. /// </summary> /// <param name="scrollProperties">A property set who has Translation.Y specified - typically the return from ElementCompositionPreview.GetScrollViewerManipulationPropertySet(...).</param> /// <param name="maskedBrush">This is the brush that will be set on _frontVisual</param> private void InitializeFrontVisual(CompositionPropertySet scrollProperties, CompositionEffectBrush maskedBrush) { // // Create the _frontVisual, set the brush on it, and attach it to the scrollViewer. Setting it as the // child visual on scrollviewer will put it in front of all the scrollViewer content. // _frontVisual = _compositor.CreateSpriteVisual(); _frontVisual.Brush = maskedBrush; ElementCompositionPreview.SetElementChildVisual(MainGrid, _frontVisual); // // "Terms" in the following expression: // // (CrossoverTranslation + scrollingProperties.Translation.Y)/CrossoverTranslation // // Since scrollingProperties.Translation.Y is negative. This creates a normalized value that goes from // 0 to 1 between no scrolling and the CrossoverTranslation. // var scrollPropSet = scrollProperties.GetSpecializedReference <ManipulationPropertySetReferenceNode>(); var crossoverTranslation = ExpressionValues.Constant.CreateConstantScalar("CrossoverTranslation"); _frontPropertiesScaleExpression = EF.Lerp( _finalScaleAmount, _initialScaleAmount, EF.Clamp((crossoverTranslation + scrollPropSet.Translation.Y) / crossoverTranslation, 0, 1)); // // The previous equation calculates a scalar which is later bound to ScalarScale in FrontVisual's Properties. // This equation uses that scalar to construct a new vector3 to set to animate the scale of the visual itself. // _frontVisual.Properties.InsertScalar("ScalarScale", 1); var frontScalarScale = _frontVisual.GetReference().GetScalarProperty("ScalarScale"); var vec3ScaleExpression = EF.Vector3(frontScalarScale, frontScalarScale, 1); _frontVisual.StartAnimation("Scale", vec3ScaleExpression); // // This equation controls whether or not the FrontVisual is visibile via opacity. It uses a simple ternary operator // to pick between 100% and 0% opacity based on the position being before the crossover point. // _frontVisibilityExpression = EF.Conditional(-scrollPropSet.Translation.Y <= crossoverTranslation, 1, 0); var baseOffset = ExpressionValues.Constant.CreateConstantScalar("BaseOffset"); _frontTranslationExpression = EF.Conditional(scrollPropSet.Translation.Y > 0, baseOffset, baseOffset - scrollPropSet.Translation.Y); }
private void Page_Unloaded(object sender, RoutedEventArgs e) { if (_parallaxExpression != null) { // (TODO) Re-add this in after Dispose() implemented on ExpressionNode //_parallaxExpression.Dispose(); _parallaxExpression = null; } if (_scrollProperties != null) { _scrollProperties.Dispose(); _scrollProperties = null; } }
public AnimatedIcon() { //__RP_Marker_ClassById(RuntimeProfiler.ProfId_AnimatedIcon); #if !HAS_UNO m_progressPropertySet = Windows.UI.Xaml.Window.Current.Compositor.CreatePropertySet(); m_progressPropertySet.InsertScalar(s_progressPropertyName, 0); #else m_progressPropertySet = new CompositionPropertySet(null); #endif Loaded += OnLoaded; this.RegisterPropertyChangedCallback(ForegroundProperty, OnForegroundPropertyChanged); this.RegisterPropertyChangedCallback(FlowDirectionProperty, OnFlowDirectionPropertyChanged); }
private void MainPage_Loaded(object sender, RoutedEventArgs e) { CompositionPropertySet scrollerViewerManipulation = ElementCompositionPreview.GetScrollViewerManipulationPropertySet(myScroller); Compositor compositor = scrollerViewerManipulation.Compositor; ExpressionAnimation expression = compositor.CreateExpressionAnimation("ScrollManipululation.Translation.Y * ParallaxMultiplier"); expression.SetScalarParameter("ParallaxMultiplier", 0.3f); expression.SetReferenceParameter("ScrollManipululation", scrollerViewerManipulation); Visual textVisual = ElementCompositionPreview.GetElementVisual(background); textVisual.StartAnimation("Offset.Y", expression); }
/// <summary> Create an ExpressionNode reference to this specialized PropertySet. </summary> public static T GetSpecializedReference <T>(this CompositionPropertySet ps) where T : PropertySetReferenceNode { if (typeof(T) == typeof(ManipulationPropertySetReferenceNode)) { return(new ManipulationPropertySetReferenceNode(null, ps) as T); } else if (typeof(T) == typeof(PointerPositionPropertySetReferenceNode)) { return(new PointerPositionPropertySetReferenceNode(null, ps) as T); } else { throw new System.Exception("Invalid property set specialization"); } }
private void Element_Loaded(object sender, RoutedEventArgs e) { if (!DesignMode.DesignModeEnabled) { if (sender is FrameworkElement element) { element.Loaded -= Element_Loaded; scrollViewer = element.VisualTreeFindName <ScrollViewer>(TargetScrollerName); if (scrollViewer != null) { ScrollerPropSet = ElementCompositionPreview.GetScrollViewerManipulationPropertySet(scrollViewer); UpdateAnimations(); } } } }
XElement FromCompositionPropertySet(CompositionPropertySet obj, IEnumerable <CompositionObject.Animator> animators = null) { return(new XElement("PropertySet", GetContents())); IEnumerable <XObject> GetContents() { foreach (var prop in obj.ColorProperties) { foreach (var item in FromAnimatableColor(prop.Key, animators, prop.Value)) { yield return(item); } } foreach (var prop in obj.ScalarProperties) { foreach (var item in FromAnimatableScalar(prop.Key, animators, prop.Value)) { yield return(item); } } foreach (var prop in obj.Vector2Properties) { foreach (var item in FromAnimatableVector2(prop.Key, animators, prop.Value)) { yield return(item); } } foreach (var prop in obj.Vector3Properties) { foreach (var item in FromAnimatableVector3(prop.Key, animators, prop.Value)) { yield return(item); } } foreach (var prop in obj.Vector4Properties) { foreach (var item in FromAnimatableVector4(prop.Key, animators, prop.Value)) { yield return(item); } } } }
/// <summary> /// Create the _frontVisual and the animations that drive it. /// </summary> /// <param name="scrollProperties">A property set who has Translation.Y specified - typically the return from ElementCompositionPreview.GetScrollViewerManipulationPropertySet(...).</param> /// <param name="maskedBrush">This is the brush that will be set on _frontVisual</param> private void InitializeFrontVisual(CompositionPropertySet scrollProperties, CompositionEffectBrush maskedBrush) { // // Create the _frontVisual, set the brush on it, and attach it to the scrollViewer. Setting it as the // child visual on scrollviewer will put it in front of all the scrollViewer content. // _frontVisual = _compositor.CreateSpriteVisual(); _frontVisual.Brush = maskedBrush; ElementCompositionPreview.SetElementChildVisual(MainGrid, _frontVisual); // // "Terms" in the following expression: // // (CrossoverTranslation + scrollingProperties.Translation.Y)/CrossoverTranslation // // Since scrollingProperties.Translation.Y is negative. This creates a normalized value that goes from // 0 to 1 between no scrolling and the CrossoverTranslation. // _frontPropertiesScalarScaleAnimation = _compositor.CreateExpressionAnimation( "Lerp(minClamp, maxClamp, Clamp((CrossoverTranslation + scrollingProperties.Translation.Y)/CrossoverTranslation,0,1))" ); _frontPropertiesScalarScaleAnimation.SetReferenceParameter("scrollingProperties", scrollProperties); _frontPropertiesScalarScaleAnimation.SetScalarParameter("minClamp", _finalScaleAmount); _frontPropertiesScalarScaleAnimation.SetScalarParameter("maxClamp", _initialScaleAmount); // // The previous equation calculates a scalar which is later bound to ScalarScale in FrontVisual's Properties. // This equation uses that scalar to construct a new vector3 to set to animate the scale of the visual itself. // var vector3ScaleAnimation = _compositor.CreateExpressionAnimation("Vector3(Properties.ScalarScale, Properties.ScalarScale, 1)"); _frontVisual.Properties.InsertScalar("ScalarScale", 1); vector3ScaleAnimation.SetReferenceParameter("Properties", _frontVisual.Properties); _frontVisual.StartAnimation("Scale", vector3ScaleAnimation); // // This equation controls whether or not the FrontVisual is visibile via opacity. It uses a simple ternary operator // to pick between 100% and 0% opacity based on the position being before the crossover point. // _frontVisibilityAnimation = _compositor.CreateExpressionAnimation("-scrollingProperties.Translation.Y <= CrossoverTranslation ? 1 : 0"); _frontVisibilityAnimation.SetReferenceParameter("scrollingProperties", scrollProperties); _frontTranslationAnimation = _compositor.CreateExpressionAnimation("scrollingProperties.Translation.Y > 0 ? BaseOffset : BaseOffset-scrollingProperties.Translation.Y"); _frontTranslationAnimation.SetReferenceParameter("scrollingProperties", scrollProperties); }
private void OnPageLoaded(object sender, RoutedEventArgs e) { var animationService = ConnectedAnimationService.GetForCurrentView(); var animation = animationService.GetAnimation(Constants.ConnectedAnimationKey); if (animation != null) { animation.TryStart(CoverImage, new UIElement[] { SetImage }); } // Get the PropertySet that contains the scroll values from MyScrollViewer _scrollerPropertySet = ElementCompositionPreview.GetScrollViewerManipulationPropertySet(MyScrollviewer); _compositor = _scrollerPropertySet.Compositor; // Create a PropertySet that has values to be referenced in the ExpressionAnimations below _props = _compositor.CreatePropertySet(); _props.InsertScalar("progress", 0); _props.InsertScalar("clampSize", 100); // Get references to our property sets for use with ExpressionNodes var scrollingProperties = _scrollerPropertySet.GetSpecializedReference <ManipulationPropertySetReferenceNode>(); var props = _props.GetReference(); var progressNode = props.GetScalarProperty("progress"); var clampSizeNode = props.GetScalarProperty("clampSize"); // Create and start an ExpressionAnimation to track scroll progress over the desired distance var progressAnimation = ExpressionFunctions.Clamp(-scrollingProperties.Translation.Y / clampSizeNode, 0, 1); _props.StartAnimation("progress", progressAnimation); // Get the backing visual for the header so that its properties can be animated var headerVisual = ElementCompositionPreview.GetElementVisual(Header); // Create and start an ExpressionAnimation to clamp the header's offset to keep it onscreen var headerTranslationAnimation = ExpressionFunctions.Conditional(progressNode < 1, 0, -scrollingProperties.Translation.Y - clampSizeNode); headerVisual.StartAnimation("Offset.Y", headerTranslationAnimation); // Create and start an ExpressionAnimation to scale the header during overpan var headerScaleAnimation = ExpressionFunctions.Lerp(1, 1.25f, ExpressionFunctions.Clamp(scrollingProperties.Translation.Y / 50, 0, 1)); headerVisual.StartAnimation("Scale.X", headerScaleAnimation); headerVisual.StartAnimation("Scale.Y", headerScaleAnimation); //Set the header's CenterPoint to ensure the overpan scale looks as desired headerVisual.CenterPoint = new Vector3((float)(Header.ActualWidth / 2), (float)Header.ActualHeight, 0); }
internal void StartAnimation(ScrollViewer sv) { _sv = sv; if (_frozenContent == null || _sv == null || _pressedHider == null || _frozenContentVisual != null) { return; } _scrollerViewerManipulation = ElementCompositionPreview.GetScrollViewerManipulationPropertySet(sv); _compositor = _scrollerViewerManipulation.Compositor; _offsetAnimation = _compositor.CreateExpressionAnimation("-min(0,ScrollManipulation.Translation.X)"); _offsetAnimation.SetReferenceParameter("ScrollManipulation", _scrollerViewerManipulation); _frozenContentVisual = ElementCompositionPreview.GetElementVisual(_frozenContent); _pressedHiderVisual = ElementCompositionPreview.GetElementVisual(_pressedHider); _frozenContentVisual.StartAnimation("Offset.X", _offsetAnimation); _pressedHiderVisual.StartAnimation("Offset.X", _offsetAnimation); }
private void PrepareCompositionAnimation() { if (_scrollViewer != null) { if (_scrollerViewerManipulation == null) { _scrollerViewerManipulation = ElementCompositionPreview.GetScrollViewerManipulationPropertySet(_scrollViewer); } if (_offsetXAnimation == null) { _offsetXAnimation = _scrollerViewerManipulation.Compositor.CreateExpressionAnimation("-min(0,ScrollManipulation.Translation.X)"); _offsetXAnimation.SetReferenceParameter("ScrollManipulation", _scrollerViewerManipulation); _columnsHeader._offsetXAnimation = _offsetXAnimation; _frozenRows._offsetXAnimation = _offsetXAnimation; } } }
private void startAnimation(CompositionSurfaceBrush brush) { animatingPropset = compositor.CreatePropertySet(); animatingPropset.InsertScalar("xcoord", 1.0f); animatingPropset.StartAnimation("xcoord", moveSurfaceExpressionAnimation); animatingPropset.InsertScalar("ycoord", 1.0f); animatingPropset.StartAnimation("ycoord", moveSurfaceUpDownExpressionAnimation); animatingPropset.InsertScalar("scale", 1.0f); animatingPropset.StartAnimation("scale", scaleSurfaceUpDownExpressionAnimation); animateMatrix = compositor.CreateExpressionAnimation("Matrix3x2(props.scale, 0.0, 0.0, props.scale, props.xcoord, props.ycoord)"); animateMatrix.SetReferenceParameter("props", animatingPropset); brush.StartAnimation(nameof(brush.TransformMatrix), animateMatrix); }
private static void CreateParallax(UIElement parallaxElement, ScrollViewer scroller, double horizontalMultiplier, double verticalMultiplier) { if ((parallaxElement == null) || (scroller == null)) { return; } CompositionPropertySet scrollerViewerManipulation = ElementCompositionPreview.GetScrollViewerManipulationPropertySet(scroller); var scrollPropSet = scrollerViewerManipulation.GetSpecializedReference <ManipulationPropertySetReferenceNode>(); var parallax = ExpressionFunctions.Vector3((float)horizontalMultiplier * scrollPropSet.Translation.X, (float)verticalMultiplier * scrollPropSet.Translation.Y, 0f); var expression = ExpressionFunctions.CreateTranslation(parallax); Visual visual = ElementCompositionPreview.GetElementVisual(parallaxElement); visual.StartAnimation("TransformMatrix", expression); }
private static void StartSpy <T>( T source, Dictionary <T, KeyValuePair <CompositionPropertySet, Dictionary <string, ExpressionAnimation> > > dictionary, Compositor compositor, ref string propertyName, ref string propertySetPropertyName, out CompositionPropertySet propertySet, out ExpressionAnimation expressionAnimation) { propertySet = null; expressionAnimation = null; if (source == null) { throw new ArgumentException(); } KeyValuePair <CompositionPropertySet, Dictionary <string, ExpressionAnimation> > propertySetExpressionsPair; Dictionary <string, ExpressionAnimation> expressionAnimations = null; if (!dictionary.ContainsKey(source)) { propertySet = compositor.CreatePropertySet(); expressionAnimations = new Dictionary <string, ExpressionAnimation>(); propertySetExpressionsPair = new KeyValuePair <CompositionPropertySet, Dictionary <string, ExpressionAnimation> >(propertySet, expressionAnimations); dictionary.Add(source, propertySetExpressionsPair); } else { propertySetExpressionsPair = dictionary[source]; propertySet = propertySetExpressionsPair.Key; expressionAnimations = propertySetExpressionsPair.Value; } if (!expressionAnimations.ContainsKey(propertySetPropertyName)) { expressionAnimation = compositor.CreateExpressionAnimation(c_source + "." + propertyName); expressionAnimations.Add(propertySetPropertyName, expressionAnimation); } else { expressionAnimation = expressionAnimations[propertySetPropertyName]; } }
public static ExpressionAnimation StartExpressionAnimation( this ScrollViewer scrollViewer, UIElement target, Axis sourceAxis, Axis targetAxis) { CompositionPropertySet scrollSet = ElementCompositionPreview.GetScrollViewerManipulationPropertySet(scrollViewer); ExpressionAnimation animation = scrollSet.Compositor.CreateExpressionAnimation($"{nameof(scrollViewer)}.{nameof(UIElement.Translation)}.{sourceAxis}"); animation.SetReferenceParameter(nameof(scrollViewer), scrollSet); Visual visual = ElementCompositionPreview.GetElementVisual(target); visual.StartAnimation($"{nameof(Visual.Offset)}.{targetAxis}", animation); return(animation); }
/// <summary> /// Creates a PerspectiveProjection with default properties. /// Fov = Pi / 2 /// Near = 1 /// Far = 1000 /// </summary> /// <param name="compositor"></param> /// <exception cref="System.ArgumentException">Thrown when constructor is passed a null value.</exception> public PerspectiveProjection(Compositor compositor) { if (compositor == null) { throw new System.ArgumentException("Compositor cannot be null"); } _compositor = compositor; _propertySet = _compositor.CreatePropertySet(); // Create the properties for the projection _propertySet.InsertScalar("Fov", MathF.PI / 2); _propertySet.InsertScalar("Near", 1f); _propertySet.InsertScalar("Far", 1000f); _propertySet.InsertMatrix4x4("ProjectionMatrix", Matrix4x4.Identity); StartAnimationonProjectionMatrix(); }
private void Page_Loaded(object sender, RoutedEventArgs e) { CompositionPropertySet scrollerPropertySet = ElementCompositionPreview.GetScrollViewerManipulationPropertySet(MainScrollViewer); Compositor compositor = scrollerPropertySet.Compositor; // Get the visual that represents our HeaderTextBlock // And define the progress animation string var headerVisual = ElementCompositionPreview.GetElementVisual(ScrollHeader); String progress = "Clamp(Abs(scroller.Translation.Y) / 100.0, 0.0, 1.0)"; // Create the expression and add in our progress string. var textExpression = compositor.CreateExpressionAnimation("Lerp(1.5, 1, " + progress + ")"); textExpression.SetReferenceParameter("scroller", scrollerPropertySet); // Shift the header by 50 pixels when scrolling down var offsetExpression = compositor.CreateExpressionAnimation($"-scroller.Translation.Y - {progress} * 50"); offsetExpression.SetReferenceParameter("scroller", scrollerPropertySet); headerVisual.StartAnimation("Offset.Y", offsetExpression); // Logo scale and transform var logoHeaderScaleAnimation = compositor.CreateExpressionAnimation("Lerp(Vector2(1,1), Vector2(0.5, 0.5), " + progress + ")"); logoHeaderScaleAnimation.SetReferenceParameter("scroller", scrollerPropertySet); var logoVisual = ElementCompositionPreview.GetElementVisual(HeaderLogo); logoVisual.StartAnimation("Scale.xy", logoHeaderScaleAnimation); var logoVisualOffsetAnimation = compositor.CreateExpressionAnimation($"Lerp(0, 50, {progress})"); logoVisualOffsetAnimation.SetReferenceParameter("scroller", scrollerPropertySet); logoVisual.StartAnimation("Offset.Y", logoVisualOffsetAnimation); // Offset the header title Visual textVisual = ElementCompositionPreview.GetElementVisual(HeaderText); Vector3 finalOffset = new Vector3(-45, 22, 0); var headerOffsetAnimation = compositor.CreateExpressionAnimation($"Lerp(Vector3(0,0,0), finalOffset, {progress})"); headerOffsetAnimation.SetReferenceParameter("scroller", scrollerPropertySet); headerOffsetAnimation.SetVector3Parameter("finalOffset", finalOffset); textVisual.StartAnimation(nameof(Visual.Offset), headerOffsetAnimation); }
private void Page_Loaded(object sender, RoutedEventArgs e) { Compositor compositor = ElementCompositionPreview.GetElementVisual(this).Compositor; // Get scrollviewer ScrollViewer myScrollViewer = ThumbnailList.GetFirstDescendantOfType <ScrollViewer>(); _scrollProperties = ElementCompositionPreview.GetScrollViewerManipulationPropertySet(myScrollViewer); // Setup the expression _parallaxExpression = compositor.CreateExpressionAnimation(); _parallaxExpression.SetScalarParameter("StartOffset", 0.0f); _parallaxExpression.SetScalarParameter("ParallaxValue", 0.5f); _parallaxExpression.SetScalarParameter("ItemHeight", 0.0f); _parallaxExpression.SetReferenceParameter("ScrollManipulation", _scrollProperties); _parallaxExpression.Expression = "(ScrollManipulation.Translation.Y + StartOffset - (0.5 * ItemHeight)) * ParallaxValue - (ScrollManipulation.Translation.Y + StartOffset - (0.5 * ItemHeight))"; ThumbnailList.ItemsSource = Model.Items; }
private void ScrollViewer_Loaded(object sender, RoutedEventArgs e) { 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 Header_Loaded(object sender, RoutedEventArgs e) { var scrollviewer = MainScroller; _scrollerPropertySet = ElementCompositionPreview.GetScrollViewerManipulationPropertySet(scrollviewer); _compositor = _scrollerPropertySet.Compositor; _props = _compositor.CreatePropertySet(); _props.InsertScalar("progress", 0); _props.InsertScalar("clampSize", (float)HeaderBG.Height); _props.InsertScalar("scaleFactor", 0.7f); // Get references to our property sets for use with ExpressionNodes var scrollingProperties = _scrollerPropertySet.GetSpecializedReference <ManipulationPropertySetReferenceNode>(); var props = _props.GetReference(); var progressNode = props.GetScalarProperty("progress"); var clampSizeNode = props.GetScalarProperty("clampSize"); var scaleFactorNode = props.GetScalarProperty("scaleFactor"); // Create and start an ExpressionAnimation to track scroll progress over the desired distance var progressAnimation = EF.Clamp(-scrollingProperties.Translation.Y / clampSizeNode, 0, 1); _props.StartAnimation("progress", progressAnimation); var headerbgVisual = ElementCompositionPreview.GetElementVisual(HeaderBG); var bgblurOpacityAnimation = EF.Clamp(progressNode, 0, 1); headerbgVisual.StartAnimation("Opacity", bgblurOpacityAnimation); var headerVisual = ElementCompositionPreview.GetElementVisual(HeroTitle); var scaleAnimation = EF.Lerp(1, scaleFactorNode, progressNode); headerVisual.StartAnimation("Scale.X", scaleAnimation); headerVisual.StartAnimation("Scale.Y", scaleAnimation); var offsetAnimation = EF.Lerp(160f, 32f, progressNode); var opacityAnimation = EF.Lerp(1f, 0.6f, progressNode); var containerVisual = ElementCompositionPreview.GetElementVisual(TextContainer); containerVisual.StartAnimation("Offset.Y", offsetAnimation); containerVisual.StartAnimation("Opacity", opacityAnimation); }
private void Page_Loaded(object sender, RoutedEventArgs e) { Compositor compositor = ElementCompositionPreview.GetElementVisual(this).Compositor; // Get scrollviewer ScrollViewer myScrollViewer = ThumbnailList.GetFirstDescendantOfType <ScrollViewer>(); _scrollProperties = ElementCompositionPreview.GetScrollViewerManipulationPropertySet(myScrollViewer); // Setup the expression var scrollPropSet = _scrollProperties.GetSpecializedReference <ManipulationPropertySetReferenceNode>(); var startOffset = ExpressionValues.Constant.CreateConstantScalar("startOffset", 0.0f); var parallaxValue = 0.5f; var parallax = (scrollPropSet.Translation.Y + startOffset); _parallaxExpression = parallax * parallaxValue - parallax; ThumbnailList.ItemsSource = LocalDataSource.RandomizeDataSource(Model.Nature); }
/// <summary> /// Retrieves an object for the given key, from the CompositionPropertySet /// </summary> /// <typeparam name="T">Type of the object to retrieve</typeparam> /// <param name="propertySet">CompositionPropertySet</param> /// <param name="key">Key of the object to retrieve</param> /// <returns>The retrieved object</returns> public static T Get <T>(this CompositionPropertySet propertySet, string key) { var type = typeof(T); while (!type.IsPublic()) { type = type.BaseType(); } // Find matching TryGetXXX method for the given type or if there // is no TryGetXXX method directly matching the parameter type, then // find if the parameter type derives from any of the types which are the // keys in the TryGetMethods dictionary var methodKey = TryGetMethods.Keys.FirstOrDefault(t => (t == type) || t.IsAssignableFrom(type)); // If no matching method is found, then raise an exception if (methodKey == null) { throw new ArgumentException($"No suitable method was found to obtain the value of type '{type}' " + $"for the key '{key}' in the CompositionPropertySet!"); } var result = default(T); // Once a matching TryGetXXX method is found, Invoke it! var methodResult = (CompositionGetValueStatus)TryGetMethods[methodKey].Invoke(propertySet, new object[] { key, result }); switch (methodResult) { case CompositionGetValueStatus.Succeeded: return(result); case CompositionGetValueStatus.TypeMismatch: throw new ArgumentException($"The key \'{key}\' does not return data of type " + $"\'{type.FullName}\' in the CompositionPropertySet!"); case CompositionGetValueStatus.NotFound: throw new ArgumentException($"The key \'{key}\' was not found in the CompositionPropertySet!"); } throw new ArgumentException($"The key \'{key}\' was not found in the CompositionPropertySet!"); }
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); // 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; }
/// <summary> /// Create the _backVisual and the animations that drive it. /// </summary> /// <param name="scrollProperties">A property set who has Translation.Y specified - typically the return from ElementCompositionPreview.GetScrollViewerManipulationPropertySet(...).</param> /// <param name="maskedBrush">This is the brush that will be set on _frontVisual</param> private void InitializeBehindVisual(CompositionPropertySet scrollProperties, CompositionEffectBrush maskedBrush) { // // Create the _backVisual, set the brush on it, and attach it to the BackGrid. BackGrid is an empty grid // that is visually behind the profile background (the waves). Therefore, setting it as the // child visual on the BackGrid will put it behind all the scrollViewer content. // _backVisual = _compositor.CreateSpriteVisual(); _backVisual.Brush = maskedBrush; ElementCompositionPreview.SetElementChildVisual(BackGrid, _backVisual); // // This equation controls whether or not the FrontVisual is visibile via opacity. It uses a simple ternary operator // to pick between 100% and 0% opacity based on the position being after the crossover point. // _backVisual.Scale = new Vector3(_finalScaleAmount, _finalScaleAmount, 1); var scrollPropSet = scrollProperties.GetSpecializedReference <ManipulationPropertySetReferenceNode>(); var crossoverTranslation = ExpressionValues.Constant.CreateConstantScalar("CrossoverTranslation"); _behindOpacityExpression = EF.Conditional(-scrollPropSet.Translation.Y <= crossoverTranslation, 0, 1); // // "Terms" and explanation of the following expression: // // (initialOffset - scrollingProperties.Translation.Y) // // Since _backVisual is a child of the scroller, the initial position minus the scrolling offset keeps the content // in its original location. // // 2 * (CrossoverTranslation + scrollingProperties.Translation.Y) // // Since scrollingProperties.Translation.Y is negative when this expression is visibile, this term calculates the // distance past the crossover point and scales it. The scale causes the content to move faster than the scrolling. // Since this term evaluates to zero at the crossover point and the term above keeps the content from moving, when // the visibility swaps between frontVisual and backVisual, they are perfectly aligned. // var baseOffset = ExpressionValues.Constant.CreateConstantScalar("BaseOffset"); _behindTranslationExpression = (baseOffset - scrollPropSet.Translation.Y) + 2 * (crossoverTranslation + scrollPropSet.Translation.Y); }
/// <summary> /// </summary> protected override void OnConnected() { var compositor = Window.Current.Compositor; // Load milky way image _surface = LoadedImageSurface.StartLoadFromUri(new Uri(App.PhotoCollection.ElementAt(4).Path)); _surface.LoadCompleted += (s, startArgs) => { if (startArgs.Status == LoadedImageSourceLoadStatus.Success) { // Create blur effect var brush = compositor.CreateSurfaceBrush(_surface); brush.Stretch = CompositionStretch.UniformToFill; IGraphicsEffect graphicsEffect = new GaussianBlurEffect { Name = "Blur", BlurAmount = 0, Source = new CompositionEffectSourceParameter("image") }; var effectFactory = compositor.CreateEffectFactory(graphicsEffect, new[] { "Blur.BlurAmount" }); var effectBrush = effectFactory.CreateBrush(); effectBrush.SetSourceParameter("image", brush); // Composition Brush is what is being applied to the UI Element. CompositionBrush = effectBrush; PropertySet = effectBrush.Properties; // Animate the blur var blurAnimation = compositor.CreateScalarKeyFrameAnimation(); blurAnimation.InsertKeyFrame(0, 0f); blurAnimation.InsertKeyFrame(0.5f, 10.0f); blurAnimation.InsertKeyFrame(1, 0); blurAnimation.Duration = TimeSpan.FromSeconds(4); blurAnimation.IterationBehavior = AnimationIterationBehavior.Forever; effectBrush.Properties.StartAnimation("Blur.BlurAmount", blurAnimation); } }; }
/// <summary> /// Creates a FirstPersonCamera with default properties. /// Position = Vector3.Zero /// Yaw = 0 /// Pitch = 0 /// Roll = 0 /// ModelViewProjectionMatrix = Matrix4x4.Identity /// </summary> /// <param name="compositor"></param> /// <exception cref="System.ArgumentException">Thrown when constructor is passed a null value.</exception> public FirstPersonCamera(Compositor compositor) { if (compositor == null) { throw new System.ArgumentException("Compositor cannot be null"); } _compositor = compositor; // Create the properties for the camera _propertySet = _compositor.CreatePropertySet(); _propertySet.InsertVector3("Position", Vector3.Zero); _propertySet.InsertScalar("Yaw", 0f); _propertySet.InsertScalar("Pitch", 0f); _propertySet.InsertScalar("Roll", 0f); _propertySet.InsertMatrix4x4("ModelViewProjectionMatrix", Matrix4x4.Identity); // Default is an orthographic projection Projection = new OrthographicProjection(_compositor); }
//warning internal void StopAnimation() { if (_frozenContentVisual != null) { _frozenContentVisual.StopAnimation("Offset.X"); _frozenContentVisual.Dispose(); _frozenContentVisual = null; _pressedHiderVisual.StopAnimation("Offset.X"); _pressedHiderVisual.Dispose(); _pressedHiderVisual = null; _compositor.Dispose(); _compositor = null; _offsetAnimation.Dispose(); _offsetAnimation = null; _scrollerViewerManipulation.Dispose(); _scrollerViewerManipulation = null; } }
/// <summary> /// Creates a Viewport with default properties. /// Offset = Vector3.Zero /// Size = Vector2(100, 100) /// Stretch = Uniform /// StretchMatrix = Matrix4x4.Identity /// </summary> /// <param name="compositor"></param> /// <exception cref="System.ArgumentException">Thrown when constructor is passed a null value.</exception> public Viewport(Compositor compositor) { if (compositor == null) { throw new System.ArgumentException("Compositor cannot be null"); } _compositor = compositor; _propertySet = _compositor.CreatePropertySet(); // Create properties of viewport _propertySet.InsertVector3("Offset", Vector3.Zero); _propertySet.InsertVector2("Size", new Vector2(100, 100)); _propertySet.InsertScalar("Stretch", (int)Stretch.Uniform); _propertySet.InsertMatrix4x4("StretchMatrix", Matrix4x4.Identity); Camera = new OrbitalCamera(_compositor); StartAnimationsOnStretchMatrix(); }
public override void OnPointerEnter(Vector2 pointerPosition, CompositionImage image) { _propertySet = _compositor.CreatePropertySet(); _propertySet.InsertScalar("Scale", 1f); Vector2 positionNormalized = new Vector2((pointerPosition.X / (float)image.Width) - .5f, (pointerPosition.Y / (float)image.Height) - .5f); _propertySet.InsertVector2("Translate", positionNormalized); _propertySet.InsertVector2("CenterPointOffset", new Vector2(128, 128)); _transformExpression.SetReferenceParameter("props", _propertySet); image.Brush.StartAnimation("LightMapTransform.TransformMatrix", _transformExpression); _propertySet.StartAnimation("Scale", _enterAnimation); }
private async void Initialize(UIElement element,double value) { //1.- Find its scrollviewer and compositor while(scroller == null) { scroller = Effects.GetElementParameter(element); await Task.Delay(500); } scrollerViewerManipulation = ElementCompositionPreview.GetScrollViewerManipulationPropertySet(scroller as ScrollViewer); scrollerCompositor = scrollerViewerManipulation.Compositor; //2.- Apply Effect CreateScrollExpression(element, (float)value); }
/// <summary> /// Create the _backVisual and the animations that drive it. /// </summary> /// <param name="scrollProperties">A property set who has Translation.Y specified - typically the return from ElementCompositionPreview.GetScrollViewerManipulationPropertySet(...).</param> /// <param name="maskedBrush">This is the brush that will be set on _frontVisual</param> private void InitializeBehindVisual(CompositionPropertySet scrollProperties, CompositionEffectBrush maskedBrush) { // // Create the _frontVisual, set the brush on it, and attach it to the BackGrid. BackGrid is an empty grid // that is visually behind the profile background (the waves). Therefore, setting it as the // child visual on the BackGrid will put it behind all the scrollViewer content. // _backVisual = _compositor.CreateSpriteVisual(); _backVisual.Brush = maskedBrush; ElementCompositionPreview.SetElementChildVisual(BackGrid, _backVisual); // // This equation controls whether or not the FrontVisual is visibile via opacity. It uses a simple ternary operator // to pick between 100% and 0% opacity based on the position being after the crossover point. // _backVisual.Scale = new Vector3(_finalScaleAmount, _finalScaleAmount, 1); _behindOpacityAnimation = _compositor.CreateExpressionAnimation("-scrollingProperties.Translation.Y <= CrossoverTranslation ? 0 : 1"); _behindOpacityAnimation.SetReferenceParameter("scrollingProperties", scrollProperties); // // "Terms" and explanation of the following expression: // // (initialOffset - scrollingProperties.Translation.Y) // // Since _backVisual is a child of the scroller, the initial position minus the scrolling offset keeps the content // in its original location. // // 2 * (CrossoverTranslation + scrollingProperties.Translation.Y) // // Since scrollingProperties.Translation.Y is negative when this expression is visibile, this term calculates the // distance past the crossover point and scales it. The scale causes the content to move faster than the scrolling. // Since this term evaluates to zero at the crossover point and the term above keeps the content from moving, when // the visibility swaps between frontVisual and backVisual, they are perfectly aligned. // _behindTranslateAnimation = _compositor.CreateExpressionAnimation( "(BaseOffset - scrollingProperties.Translation.Y) + 2 * (CrossoverTranslation + scrollingProperties.Translation.Y)"); _behindTranslateAnimation.SetReferenceParameter("scrollingProperties", scrollProperties); }
public override void OnPointerEnter(Vector2 pointerPosition, CompositionImage image) { _propertySet = _compositor.CreatePropertySet(); _propertySet.InsertScalar("Scale", 1.25f); _propertySet.InsertScalar("Rotation", 0f); _propertySet.InsertVector2("Translate", new Vector2(0f, 0f)); _propertySet.InsertVector2("CenterPointOffset", new Vector2((float)_lightMap.Size.Width / 2f, 0f)); _transformExpression.SetReferenceParameter("props", _propertySet); image.Brush.StartAnimation("LightMapTransform.TransformMatrix", _transformExpression); _propertySet.StartAnimation("Rotation", _enterAnimation); }
/// <summary> /// Create the _frontVisual and the animations that drive it. /// </summary> /// <param name="scrollProperties">A property set who has Translation.Y specified - typically the return from ElementCompositionPreview.GetScrollViewerManipulationPropertySet(...).</param> /// <param name="maskedBrush">This is the brush that will be set on _frontVisual</param> private void InitializeFrontVisual(CompositionPropertySet scrollProperties, CompositionEffectBrush maskedBrush) { // // Create the _frontVisual, set the brush on it, and attach it to the scrollViewer. Setting it as the // child visual on scrollviewer will put it in front of all the scrollViewer content. // _frontVisual = _compositor.CreateSpriteVisual(); _frontVisual.Brush = maskedBrush; ElementCompositionPreview.SetElementChildVisual(MainGrid, _frontVisual); // // "Terms" in the following expression: // // (CrossoverTranslation + scrollingProperties.Translation.Y)/CrossoverTranslation // // Since scrollingProperties.Translation.Y is negative. This creates a normalized value that goes from // 0 to 1 between no scrolling and the CrossoverTranslation. // _frontPropertiesScalarScaleAnimation = _compositor.CreateExpressionAnimation( "Lerp(minClamp, maxClamp, Clamp((CrossoverTranslation + scrollingProperties.Translation.Y)/CrossoverTranslation,0,1))" ); _frontPropertiesScalarScaleAnimation.SetReferenceParameter("scrollingProperties", scrollProperties); _frontPropertiesScalarScaleAnimation.SetScalarParameter("minClamp", _finalScaleAmount); _frontPropertiesScalarScaleAnimation.SetScalarParameter("maxClamp", _initialScaleAmount); // // The previous equation calculates a scalar which is later bound to ScalarScale in FrontVisual's Properties. // This equation uses that scalar to construct a new vector3 to set to animate the scale of the visual itself. // var vector3ScaleAnimation = _compositor.CreateExpressionAnimation("Vector3(Properties.ScalarScale, Properties.ScalarScale, 1)"); _frontVisual.Properties.InsertScalar("ScalarScale", 1); vector3ScaleAnimation.SetReferenceParameter("Properties", _frontVisual.Properties); _frontVisual.StartAnimation("Scale", vector3ScaleAnimation); // // This equation controls whether or not the FrontVisual is visibile via opacity. It uses a simple ternary operator // to pick between 100% and 0% opacity based on the position being before the crossover point. // _frontVisibilityAnimation = _compositor.CreateExpressionAnimation("-scrollingProperties.Translation.Y <= CrossoverTranslation ? 1 : 0"); _frontVisibilityAnimation.SetReferenceParameter("scrollingProperties", scrollProperties); _frontTranslationAnimation = _compositor.CreateExpressionAnimation("scrollingProperties.Translation.Y > 0 ? BaseOffset : BaseOffset-scrollingProperties.Translation.Y"); _frontTranslationAnimation.SetReferenceParameter("scrollingProperties", scrollProperties); }
/// <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 async Task HideStatusBar() //{ // //if (ApiInformation.IsApiContractPresent("Windows.Phone.PhoneContract", 1, 0)) // //{ // // var statusBar = StatusBar.GetForCurrentView(); // // await statusBar.HideAsync(); // //} //} private void InitializeCompositionVariables() { var bounds = ApplicationView.GetForCurrentView().VisibleBounds; var maxWindowWidth = bounds.Width.ToFloat(); var maxWindowHeight = bounds.Height.ToFloat(); var maxWindowRadius = Math.Max(maxWindowWidth, maxWindowHeight); // Setup sky visual's size, position, opacity, etc. _skyVisual = Sky.ContainerVisual(); _skyVisual.Size = new Vector2(maxWindowRadius * SkyVisualAreaRatio); _skyVisual.Offset = new Vector3(-SkyVisualRadius + maxWindowWidth / 2.0f, -SkyVisualRadius + maxWindowHeight / 2.0f, 0.0f); _skyVisual.CenterPoint = new Vector3(SkyVisualRadius, SkyVisualRadius, 0.0f); _skyVisual.Opacity = 0; _compositor = _skyVisual.Compositor; _reading = _compositor.CreatePropertySet(); _reading.InsertVector3("Offset", new Vector3(0.0f, 0.0f, 0.0f)); _imageLoader = ImageLoaderFactory.CreateImageLoader(_compositor); _circleBrush = _compositor.CreateSurfaceBrush(); _circleBrush.Surface = _imageLoader.LoadImageFromUri(new Uri(StarUriString)); if (_inclinometer != null) SetupSkyVisualOffsetExpressionAnimation(); }
public override void ReleaseResources() { if (_effectFactory != null) { _effectFactory.Dispose(); _effectFactory = null; } if (_enterAnimation != null) { _enterAnimation.Dispose(); _enterAnimation = null; } if (_exitAnimation != null) { _exitAnimation.Dispose(); _exitAnimation = null; } if (_transformExpression != null) { _transformExpression.Dispose(); _transformExpression = null; } if (_propertySet != null) { _propertySet.Dispose(); _propertySet = null; } }
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 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(); }
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 CreateCompositionScene(Compositor compositor) { // Create the property driving the animations _animationPropertySet = _compositor.CreatePropertySet(); _animationPropertySet.InsertScalar("currentZ", selectedLayerIndex); // Create the layer effect var layerEffectDesc = new GaussianBlurEffect { Name = "blur", BorderMode = EffectBorderMode.Hard, BlurAmount = 0, Source = new SaturationEffect { Name = "saturation", Saturation = 1, Source = new CompositionEffectSourceParameter("source") } }; var layerEffectFactory = _compositor.CreateEffectFactory(layerEffectDesc, new[] { "blur.BlurAmount", "saturation.Saturation" }); // Create the host visual _rootVisual = compositor.CreateContainerVisual(); ElementCompositionPreview.SetElementChildVisual(compositionHostPanel, _rootVisual); // Create the scene visuals for (int layerIndex = 0; layerIndex < layers.Count; ++layerIndex) { var layer = layers[layerIndex]; layer.CreateVisuals(compositor); _rootVisual.Children.InsertAtBottom(layer.LayerVisual); layer.LayerVisual.Effect = layerEffectFactory.CreateBrush(); SetupLayerAnimations(layer, layerIndex); } UpdateVisualLayout(); }
private void Page_Unloaded(object sender, RoutedEventArgs e) { if (parallaxAnimation0 != null) { parallaxAnimation0.Dispose(); parallaxAnimation0 = null; } if (parallaxAnimation1 != null) { parallaxAnimation1.Dispose(); parallaxAnimation1 = null; } if (parallaxAnimation2 != null) { parallaxAnimation2.Dispose(); parallaxAnimation2 = null; } if (parallaxAnimation3 != null) { parallaxAnimation3.Dispose(); parallaxAnimation3 = null; } if (parallaxAnimation4 != null) { parallaxAnimation4.Dispose(); parallaxAnimation4 = null; } if (scrollViewerProperties != null) { scrollViewerProperties.Dispose(); scrollViewerProperties = null; } IndAni.Stop(); }