コード例 #1
0
        private void Page_Loaded(object sender, RoutedEventArgs e)
        {
            //Create Visual to contain effect
            effectVisual = compositor.CreateSpriteVisual();
            var destinationBrush = compositor.CreateBackdropBrush();
            //Create the Effect you want
            var graphicsEffect = new GaussianBlurEffect
            {
                Name       = "Blur",
                BlurAmount = 0f,
                BorderMode = EffectBorderMode.Hard,
                Source     = new CompositionEffectSourceParameter("Background")
            };



            effectFactory = compositor.CreateEffectFactory(graphicsEffect, new[] { "Blur.BlurAmount" });
            effectBrush   = effectFactory.CreateBrush();
            effectBrush.SetSourceParameter("Background", destinationBrush);

            effectVisual.Brush = effectBrush;
            //By the default the Visual have the size width and height (defined in Vector 2) 0 and 0
            ResizeVisual();

            ElementCompositionPreview.SetElementChildVisual(Back, effectVisual);

            //Create Spring Animation for nature increase and decrease value
            _springAnimation              = compositor.CreateSpringScalarAnimation();
            _springAnimation.Period       = TimeSpan.FromSeconds(0.5);
            _springAnimation.DampingRatio = 0.75f;
        }
コード例 #2
0
        private void Department_Loaded(object sender, RoutedEventArgs e)
        {
            effectVisual = compositor.CreateSpriteVisual();
            var destinationBrush = compositor.CreateBackdropBrush();
            //Create the Effect you want
            var graphicsEffect = new GaussianBlurEffect
            {
                Name         = "Blur",
                BlurAmount   = 0f,
                BorderMode   = EffectBorderMode.Hard,
                Optimization = EffectOptimization.Balanced,
                Source       = new CompositionEffectSourceParameter("Background")
            };



            effectFactory = compositor.CreateEffectFactory(graphicsEffect, new[] { "Blur.BlurAmount" });
            effectBrush   = effectFactory.CreateBrush();
            effectBrush.SetSourceParameter("Background", destinationBrush);

            effectVisual.Brush = effectBrush;
            effectVisual.Size  = new System.Numerics.Vector2(900, 400);

            ElementCompositionPreview.SetElementChildVisual(CoverImage, effectVisual);

            //Create Spring Animation for nature increase and decrease value
            _springAnimation        = compositor.CreateSpringScalarAnimation();
            _springAnimation.Period = TimeSpan.FromSeconds(0.70);
            //_springAnimation.DampingRatio = 0.25f;
        }
コード例 #3
0
        private void CreateThumbAnimation()
        {
            if (HorizontalThumb != null)
            {
                // // 平移动画 由于动画是上推Thumb操作带动Track弯曲,正确的行为是Thumb始终跟手,所以移除了平移动画
                //var imp = Window.Current.Compositor.CreateImplicitAnimationCollection();
                //var offsetAnimation = Window.Current.Compositor.CreateVector3KeyFrameAnimation();
                //offsetAnimation.InsertExpressionKeyFrame(0f, "(abs(this.FinalValue.X - this.StartingValue.X) > 80) ? this.StartingValue : this.FinalValue");
                //offsetAnimation.InsertExpressionKeyFrame(1f, "this.FinalValue");
                //offsetAnimation.Duration = TimeSpan.FromSeconds(0.1d);
                //offsetAnimation.Target = "Offset";
                //imp["Offset"] = offsetAnimation;
                //ElementCompositionPreview.GetElementVisual(HorizontalThumb).ImplicitAnimations = imp;

                //if (CurveHost != null)
                //{
                //    ElementCompositionPreview.GetElementVisual(CurveHost).ImplicitAnimations = imp;
                //}

                horizontalThumbContent = VisualTreeHelper.GetChild(HorizontalThumb, 0) as Ellipse;

                if (horizontalThumbContent == null)
                {
                    HorizontalThumb.Loaded += HorizontalThumb_Loaded;
                }
                else
                {
                    CreateAnimation();
                }

                void HorizontalThumb_Loaded(object sender, RoutedEventArgs e)
                {
                    HorizontalThumb.Loaded -= HorizontalThumb_Loaded;
                    horizontalThumbContent  = VisualTreeHelper.GetChild(HorizontalThumb, 0) as Ellipse;

                    if (horizontalThumbContent != null)
                    {
                        CreateAnimation();
                    }
                }

                void CreateAnimation()
                {
                    ElementCompositionPreview.SetIsTranslationEnabled(horizontalThumbContent, true);

                    pressedThumbAnimation = Window.Current.Compositor.CreateScalarKeyFrameAnimation();
                    pressedThumbAnimation.InsertKeyFrame(1f, -8f);
                    pressedThumbAnimation.Duration = TimeSpan.FromSeconds(0.05d);

                    releasedThumbAnimation = Window.Current.Compositor.CreateSpringScalarAnimation();
                    releasedThumbAnimation.DampingRatio = 0.25f;
                    releasedThumbAnimation.Period       = TimeSpan.FromSeconds(0.01d);
                    releasedThumbAnimation.FinalValue   = 0f;
                }
            }
        }