Using a trigger to set the IsEnabled button to be true on the mouse

I try to set the button so that only when the mouse goes over it the button changes its visual properties to the activated button.

This is my code:

    <Button Foreground="Black" Content="OK" Margin="186,100,170,172" >
        <Button.Style>
            <Style TargetType="Button">
                <Setter Property="IsEnabled" Value="False" />
                <Style.Triggers>
                    <Trigger Property="IsMouseOver" Value="True">
                        <Setter Property="IsEnabled" Value="True" />
                    </Trigger>
                </Style.Triggers>
            </Style>
        </Button.Style>
    </Button>

Thanks in advance for your help.

+3
source share
2 answers

You can encapsulate your button on the border to get what you need.

<Border Name="buttonBorder" Margin="186,100,170,172"
        Background="#01000000" BorderBrush="Transparent" BorderThickness="0">
    <Button Foreground="Black" Content="OK">
        <Button.Style>
            <Style TargetType="Button">
                <Setter Property="IsEnabled" Value="False" />
                <Style.Triggers>
                    <DataTrigger Binding="{Binding ElementName=buttonBorder, Path=IsMouseOver}" Value="True">
                        <Setter Property="IsEnabled" Value="True" />
                    </DataTrigger>
                </Style.Triggers>
            </Style>
        </Button.Style>
    </Button>
</Border>
+5
source

I don’t think it’s possible what you want to do here, because when the button is disabled, IsMouseOver is false (also it does not generate MouseMove or other events).

, (, , , ? ... , ? , ), , , , - ).

+2

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


All Articles