Skip to content

GrayscaleEffect

闫驚鏵(Jinhua Yan) edited this page Jul 3, 2023 · 1 revision

1)Xaml

    <wd:Window.Effect>
        <wd:GrayscaleEffect x:Name="grayscaleEffect" Factor="1"/>
    </wd:Window.Effect>

2)CSharp

private void Grayscale_Click(object sender, RoutedEventArgs e)
        {
            if(grayscaleEffect.Factor == 1)
            {
                menuItemGrayscale.Header = "关闭灰度";
                Create(0);
            }
               
            else
            {
                menuItemGrayscale.Header = "开启灰度";
                Create(1);

            }
        }
        void Create(double to)
        {
            var sineEase = new SineEase() { EasingMode = EasingMode.EaseOut };
            var doubleAnimation = new DoubleAnimation
            {
                To = to,
                Duration = TimeSpan.FromMilliseconds(1000),
                EasingFunction = sineEase
            };
            grayscaleEffect.BeginAnimation(GrayscaleEffect.FactorProperty, doubleAnimation);
        }
Clone this wiki locally