Beispiel #1
0
 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();
 }
Beispiel #2
0
        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();
        }