Disable mouse button over effect

I have a wppf button with a background image.

When the mouse above the background is empty and a button appears.

How to disable the mouse effect?

<Button BorderBrush="{x:Null}" Content="Reset" BorderThickness="0"Foreground="White" Focusable="False"> <Button.Background> <ImageBrush ImageSource="button.png" /> </Button.Background> 
+6
source share
2 answers

Here I turn off the visual hover effects on the buttons. I left in some of my settings so that you feel how to play with triggers and other things, do not hesitate to experiment!

 <Style TargetType="Button" x:Key="ImageButton" BasedOn="{StaticResource {x:Static ToolBar.ButtonStyleKey}}"> <Setter Property="FocusVisualStyle" Value="{x:Null}" /> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="Button"> <Border Name="border" BorderThickness="{TemplateBinding BorderThickness}" Padding="{TemplateBinding Padding}" BorderBrush="{TemplateBinding BorderBrush}" CornerRadius="5" Background="{TemplateBinding Background}"> <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center" /> </Border> <ControlTemplate.Triggers> <Trigger Property="IsMouseOver" Value="True"> <Setter Property="BorderBrush" Value="Gainsboro" /> </Trigger> <Trigger Property="IsEnabled" Value="false"> <Setter Property="Opacity" Value="0.25" /> <Setter Property="BorderBrush" Value="Transparent" /> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> 

EDIT: using the "BasedOn" + FocusVisualStyle parameter in null (first 2 lines) eliminates mouse effects. Everything else is just examples. I added a border there to play with it through the trigger (since I want a custom mouse effect).

+13
source

In the ControlTemplate Button Background property will be overridden by the trigger.
You can either redo the entire ControlTemplate , or leave the background change or just add an image as the content of your Button to avoid all these complications:

 <Button.Content> <Image Source="button.png" /> </Button.Content> 

Or, if you need text, also:

 <Button.Content> <Grid> <Image Source="button.png" /> <TextBlock Text="Reset" VerticalAlignment="Center" HorizontalAlignment="Center" /> <Grid> </Button.Content> 
+8
source

All Articles