Question

I am trying to set a button so only when a mouse is going over it the button will change his visual properties to an enabled 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.

Was it helpful?

Solution

You could encapsulate your Button in a Border to get what you're after

<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>

OTHER TIPS

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

To achieve what you want (btw, why would you want a disabled button to become enabled when you put the mouse over it? It's so unnatural... how about if you want to navigate with the keyboard to the button? it will be impossible if it is disabled), you should restyle the button and make it look as in its disabled state when the mouse is not over it and as in its enabled state when the mouse is over it - but this will require some work).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top