Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 900
Jiew Meng Avatar asked Dec 17 '22 19:12

Jiew Meng


1 Answers

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>
like image 152
Heinzi Avatar answered May 16 '23 06:05

Heinzi