WPF XAML Changing Image Transparency in IsEnabled State

I would like the image to be opaque .50 when IsEnabled is false. I looked at a few examples, but still I cannot figure out how to make it work.

Here is the full XAML of my custom control. Any help would be greatly appreciated.

<UserControl
 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
 xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
 mc:Ignorable="d"
 x:Class="test.StopButtonControl"
 x:Name="UserControl"
 d:DesignWidth="85" d:DesignHeight="85">

    <Grid x:Name="LayoutRoot">
        <Image x:Name="StopButtonUI" Source="Images/stop.png" Stretch="Fill" MouseUp="StopButtonClick"/>  
    </Grid>
</UserControl>
+3
source share
1 answer

You can associate a property Image Opacitywith its property IsEnabledusing a style trigger as follows:

<Grid x:Name="LayoutRoot">
    <Image x:Name="StopButtonUI" Source="Images/stop.png" >
        <Image.Style>
            <Style TargetType="Image">
                <Style.Triggers>
                    <Trigger Property="IsEnabled" Value="False">
                        <Setter Property="Opacity" Value="0.5" />
                    </Trigger>
                </Style.Triggers>
            </Style>
        </Image.Style>
    </Image>
</Grid>

This will set the value Opacityto 0.5 if IsEnabledfalse.

Image IsEnabled , UserControl IsEnabled, , , IsEnabled .

+16

Source: https://habr.com/ru/post/1782823/


All Articles