private void CreateAnimations()
        {
            var compositor = ElementCompositionPreview.GetElementVisual(this).Compositor;

            var offsetAnimation = compositor.CreateVector3KeyFrameAnimation();

            offsetAnimation.Target = nameof(Visual.Offset);
            offsetAnimation.InsertExpressionKeyFrame(1.0f, "this.FinalValue");
            offsetAnimation.Duration = TimeSpan.FromMilliseconds(800);

            var opacityAnimation = compositor.CreateScalarKeyFrameAnimation();

            opacityAnimation.Target = nameof(Visual.Opacity);
            opacityAnimation.InsertKeyFrame(0.2f, 0.5f);
            opacityAnimation.InsertKeyFrame(0.8f, 0.5f);
            opacityAnimation.InsertExpressionKeyFrame(1.0f, "this.FinalValue");
            opacityAnimation.Duration = TimeSpan.FromMilliseconds(800);

            var group = compositor.CreateAnimationGroup();
            group.Add(offsetAnimation);
            group.Add(opacityAnimation);

            animations = compositor.CreateImplicitAnimationCollection();
            animations[nameof(Visual.Offset)] = group;
        }
Пример #2
0
        public Photos()
        {
            this.InitializeComponent();
            _compositor = ElementCompositionPreview.GetElementVisual(this).Compositor;

            // Create ImplicitAnimations Collection. 
            _elementImplicitAnimation = _compositor.CreateImplicitAnimationCollection();

            //Define trigger and animation that should play when the trigger is triggered. 
            _elementImplicitAnimation["Offset"] = createOffsetAnimation();

        }
        /// <summary>
        /// Initialize all Composition related stuff here (Compositor, Animations etc)
        /// </summary>
        private void InitializeComposition()
        {
            var rootVisual = ElementCompositionPreview.GetElementVisual(this);
            // Compositor
            _compositor = rootVisual.Compositor;
            // Composition Generator
            _generator = CompositionGeneratorFactory.GetCompositionGenerator(_compositor);

            // Final Value Expressions
            var vector3Expr = _compositor.CreateFinalValueExpression<Vector3>();
            var scalarExpr = _compositor.CreateFinalValueExpression<float>();

            // Opacity Animation
            var opacityAnimation = _compositor.CreateKeyFrameAnimation<float>()
                                              .HavingDuration(DefaultOpacityAnimationDuration)
                                              .ForTarget(() => rootVisual.Opacity);
            opacityAnimation.InsertExpressionKeyFrame(1f, scalarExpr);

            // Scale Animation
            var scaleAnimation = _compositor.CreateKeyFrameAnimation<Vector3>()
                                            .HavingDuration(DefaultScaleAnimationDuration)
                                            .ForTarget(() => rootVisual.Scale);
            scaleAnimation.InsertExpressionKeyFrame(1f, vector3Expr);

            // ImplicitAnimation
            _implicitAnimationCollection = _compositor.CreateImplicitAnimationCollection();
            _implicitAnimationCollection["Opacity"] = opacityAnimation.Animation;
            _implicitAnimationCollection["Scale"] = scaleAnimation.Animation;

            // Expand Animations
            _expandLeftInset = _compositor.CreateKeyFrameAnimation<float>()
                                          .HavingDuration(InsetAnimationDuration)
                                          .DelayBy(InsetAnimationDelayDuration);

            _expandLeftInset.InsertKeyFrame(1f, 0);

            _expandRightInset = _compositor.CreateKeyFrameAnimation<float>()
                                           .HavingDuration(InsetAnimationDuration)
                                           .DelayBy(InsetAnimationDelayDuration);

            _expandInsetClip = _compositor.CreateKeyFrameAnimation<float>()
                                          .HavingDuration(InsetClipAnimationDuration);

            _expandInsetClip.InsertKeyFrame(1f, 0);

            // Collapse Animations
            _collapseLeftInset = _compositor.CreateKeyFrameAnimation<float>()
                                            .HavingDuration(InsetAnimationDuration);

            _collapseRightInset = _compositor.CreateKeyFrameAnimation<float>()
                                             .HavingDuration(InsetAnimationDuration);

            _collapseInsetClip = _compositor.CreateKeyFrameAnimation<float>()
                                            .HavingDuration(InsetClipAnimationDuration);

            // Root Container
            _rootContainer = _compositor.CreateContainerVisual();

            // Background Layer
            _bgLayer = _compositor.CreateLayerVisual();
            _bgLayer.Size = _rootContainer.Size;
            _bgLayer.CenterPoint = new Vector3(_bgLayer.Size * 0.5f, 0);

            // Top Layer
            _topLayer = _compositor.CreateLayerVisual();
            _topLayer.Size = _rootContainer.Size;

            _rootContainer.Children.InsertAtBottom(_bgLayer);
            _rootContainer.Children.InsertAtTop(_topLayer);

            // Add the rootContainer to the visual tree
            ElementCompositionPreview.SetElementChildVisual(this, _rootContainer);
        }
        /// <summary>
        /// Initialize all Composition related stuff here (Compositor, Animations etc)
        /// </summary>
        private void InitializeComposition()
        {
            var rootVisual = ElementCompositionPreview.GetElementVisual(this);
            // Compositor
            _compositor = rootVisual.Compositor;

            // Final Value Expressions
            var vector3Expr = _compositor.CreateFinalValueExpression<Vector3>();
            var scalarExpr = _compositor.CreateFinalValueExpression<float>();

            // Offset Animation
            var offsetAnimation = _compositor.CreateKeyFrameAnimation<Vector3>()
                                             .HavingDuration(DefaultFluidAnimationDuration)
                                             .ForTarget(() => rootVisual.Offset);
            offsetAnimation.InsertExpressionKeyFrame(1f, vector3Expr);

            // Opacity Animation
            var opacityAnimation = _compositor.CreateKeyFrameAnimation<float>()
                                              .HavingDuration(DefaultOpacityAnimationDuration)
                                              .ForTarget(() => rootVisual.Opacity);
            opacityAnimation.InsertExpressionKeyFrame(1f, scalarExpr);

            // Scale Animation
            var scaleAnimation = _compositor.CreateKeyFrameAnimation<Vector3>()
                                            .HavingDuration(DefaultFluidAnimationDuration)
                                            .ForTarget(() => rootVisual.Scale);
            scaleAnimation.InsertExpressionKeyFrame(1f, vector3Expr);

            // ImplicitAnimation
            _implicitAnimationCollection = _compositor.CreateImplicitAnimationCollection();
            _implicitAnimationCollection["Offset"] = offsetAnimation.Animation;
            _implicitAnimationCollection["Opacity"] = opacityAnimation.Animation;
            _implicitAnimationCollection["Scale"] = scaleAnimation.Animation;

            // ImplicitDragAnimation
            _implicitDragAnimationCollection = _compositor.CreateImplicitAnimationCollection();
            _implicitDragAnimationCollection["Opacity"] = opacityAnimation.Animation;
            _implicitDragAnimationCollection["Scale"] = scaleAnimation.Animation;
        }