Exemplo n.º 1
0
        void SetCompositionFocus(bool IsGotFocus)
        {
            if (CompositionBrush == null)
            {
                return;
            }
            if (BackgroundSource == AcrylicBackgroundSource.Backdrop)
            {
                return;
            }
            var tintOpacity = Convert.ToSingle(TintOpacity);

            if (tintOpacity < 0f)
            {
                tintOpacity = 0f;
            }
            if (tintOpacity > 1f)
            {
                tintOpacity = 1f;
            }
            HostOpacityZeroAnimation.SetScalarParameter("TintOpacity", tintOpacity);
            TintOpacityFillAnimation.SetScalarParameter("TintOpacity", tintOpacity);
            if (IsGotFocus)
            {
                CompositionBrush = Brush;
                TintOpacityFillAnimation.Direction = AnimationDirection.Reverse;
                HostOpacityZeroAnimation.Direction = AnimationDirection.Reverse;
                TintToFallBackAnimation.Direction  = AnimationDirection.Reverse;
                CompositionBrush.StartAnimation("arithmetic.Source2Amount", TintOpacityFillAnimation);
                CompositionBrush.StartAnimation("arithmetic.Source1Amount", HostOpacityZeroAnimation);
                CompositionBrush.StartAnimation("tintcolor.Color", TintToFallBackAnimation);
            }
            else if (CompositionBrush == Brush)
            {
                var scopedBatch = compositor.CreateScopedBatch(CompositionBatchTypes.Animation);
                TintOpacityFillAnimation.Direction = AnimationDirection.Normal;
                HostOpacityZeroAnimation.Direction = AnimationDirection.Normal;
                TintToFallBackAnimation.Direction  = AnimationDirection.Normal;
                CompositionBrush.StartAnimation("arithmetic.Source2Amount", TintOpacityFillAnimation);
                CompositionBrush.StartAnimation("arithmetic.Source1Amount", HostOpacityZeroAnimation);
                CompositionBrush.StartAnimation("tintcolor.Color", TintToFallBackAnimation);
                scopedBatch.Completed += (s, a) => CompositionBrush = compositor.CreateColorBrush(FallbackColor);
                scopedBatch.End();
            }
            else
            {
                CompositionBrush = compositor.CreateColorBrush(FallbackColor);
            }
        }