HypernovaDesktop Components · docs
Binarymission
WPF › Shaders Library › ColorToBlackAndWhiteEffect

ColorToBlackAndWhiteEffect

class.NET 6 / 8 / 10.NET Framework 4.8Binarymission.WPF.Shaders.Library.CustomEffects

Turns the picture black and white, or – with DesaturationFactor raised towards 1 – mutes its colours part of the way.

public class ColorToBlackAndWhiteEffect : ShaderEffect

Inherits from / implements: ShaderEffect

Remarks

The usual way to grey out a disabled image or icon. The grey level is a mix of 30 per cent red, 30 per cent green and 40 per cent blue. Despite its name, DesaturationFactor works as the amount of colour kept: 0, the default, is full black and white and 1 the original colours.

Settings

PropertyRange and default

DesaturationFactor

Colour kept, from 0 (black and white, the default) to 1 (unchanged). Values outside that range are ignored.

Examples

An icon that turns grey when its button is disabled.

<Image Source="Icons/print.png"
       xmlns:fx="clr-namespace:Binarymission.WPF.Shaders.Library.CustomEffects;assembly=Binarymission.WPF.Shaders.Library">
    <Image.Style>
        <Style TargetType="Image">
            <Style.Triggers>
                <Trigger Property="IsEnabled" Value="False">
                    <Setter Property="Effect">
                        <Setter.Value>
                            <fx:ColorToBlackAndWhiteEffect />
                        </Setter.Value>
                    </Setter>
                </Trigger>
            </Style.Triggers>
        </Style>
    </Image.Style>
</Image>

See also

Members at a glance

Constructors
ColorToBlackAndWhiteEffectCreates the effect with its default settings: DesaturationFactor 0, full black and white.
Properties
DesaturationFactorGets or sets how much of the picture's colour is kept.
InputGets or sets the picture the effect works on.
Fields
DesaturationFactorPropertyIdentifies the DesaturationFactor dependency property.
InputPropertyIdentifies the Input dependency property.

Constructors

ColorToBlackAndWhiteEffect

public ColorToBlackAndWhiteEffect()

Creates the effect with its default settings: DesaturationFactor 0, full black and white.

Properties

DesaturationFactor

public double DesaturationFactor

Gets or sets how much of the picture's colour is kept.

Value
From 0 to 1: 0, the default, gives full black and white, 1 the original colours, and values between mute the colours part way. A value outside 0 to 1 is ignored and the property keeps its previous value.
Remarks

The name suggests the opposite; the scale is as described here.

Input

public Brush Input

Gets or sets the picture the effect works on.

Value
A brush. The default is the element the effect is applied to, as WPF renders it – the effect's implicit input.
Remarks

Leave it unset in the usual case, where the effect is set as an element's Effect. Set it to a ImageBrush or VisualBrush to have the effect work on that picture instead.

Fields

DesaturationFactorProperty static

public static readonly DependencyProperty DesaturationFactorProperty

Identifies the DesaturationFactor dependency property.

InputProperty static

public static readonly DependencyProperty InputProperty

Identifies the Input dependency property.