Search code examples
wpftriggersstylesicommand

Is there a way to desaturate an Image on a Button thats disabled?


Is there a way I can desaturate images in Buttons that are disabled? eg. ICommand.CanExecute = false? or do I need to use separate images + Style/Triggers


Solution

  • I'm using a special style for this, which reduces the opacity of the image when the button gets disabled (yes, this also works if the button is bound to a command). Technically, this is not desaturation, but it looks similar and it might help you derive a solution on your own:

    <Style x:Key="buttonImage">
        <Style.Triggers>
            <DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType={x:Type Button}, AncestorLevel=1}, Path=IsEnabled}" Value="False">
                <Setter Property="Image.Opacity" Value="0.25"></Setter>
            </DataTrigger>
        </Style.Triggers>
    </Style>