示例#1
0
        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);
        }