2

I have created a Windows Presentation Foundation WPF application.

The problem is automatic MouseHover that creates blue shinning when I hover over a button.

I have checked all of the components, stackpanel, grid, button ... etc, and in my options there is no MouseHover action, it's somehow default hover and I cannot disable it. Can I somehow disable or change it?

enter image description here

<Window x:Class="EnovaLauncher.MainWindow"
        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"
        xmlns:local="clr-namespace:EnovaLauncher"
        mc:Ignorable="d"
        WindowStartupLocation="CenterScreen"
        Loaded="Window_Loaded"
        Title="Enova launcher" Height="586" Width="800" Background="#FF19680C">
    <Grid VerticalAlignment="Center" Margin="0,-60,0,0" Height="483">
        <StackPanel Margin="0,0,0,-59">
            <StackPanel.Resources>
                <Style TargetType="TextBlock">
                    <Setter Property="Margin" Value="4" />
                </Style>
                <Style TargetType="TextBox">
                    <Setter Property="Margin" Value="4" />
                </Style>
                <Style TargetType="ComboBox">
                    <Setter Property="Margin" Value="4" />
                </Style>
                <Style TargetType="Button">
                    <Setter Property="Margin" Value="4" />
                </Style>
            </StackPanel.Resources>
            <TextBlock Foreground="White">Ostatnio uruchamiane</TextBlock>
            <DockPanel>
                <Button DockPanel.Dock="Right" x:Name="btn_Delete" Click="btn_Delete_Click">X</Button>
                <ComboBox Name="cb_Recent" SelectionChanged="cb_Recent_SelectionChanged"></ComboBox>
            </DockPanel>

            <TextBlock Foreground="White">Parametry</TextBlock>
            <TextBlock Foreground="White">Nazwa</TextBlock>
            <TextBox x:Name="tb_Name"></TextBox>
            <Grid>
                <StackPanel>
                    <StackPanel>
                        <TextBlock Foreground="White">Wersja</TextBlock>
                        <ComboBox Name="cb_Version"></ComboBox>
                    </StackPanel>
                    <StackPanel Grid.Column="1">
                        <TextBlock Foreground="White">DBextensions</TextBlock>
                        <CheckBox x:Name="checkbox"  Foreground="White" Content="Dodaj" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="10,5,0,5"/>
                    </StackPanel>
                    <StackPanel Grid.Column="2">
                        <TextBlock Foreground="White">Operator</TextBlock>
                        <TextBox x:Name="tb_Op"></TextBox>
                    </StackPanel>
                    <StackPanel Grid.Column="3">
                        <TextBlock Foreground="White">DbConfig</TextBlock>
                        <ComboBox Name="cb_Db" SelectionChanged="cb_Db_SelectionChanged">
                            <ComboBox.Background>
                                <LinearGradientBrush EndPoint="0,1" StartPoint="0,0">
                                    <GradientStop Color="#FFF0F0F0" Offset="0"/>
                                    <GradientStop Color="#FFE5E5E5" Offset="1"/>
                                </LinearGradientBrush>
                            </ComboBox.Background>
                        </ComboBox>
                    </StackPanel>
                    <StackPanel Grid.Column="4">
                        <TextBlock Foreground="White">ExtPath</TextBlock>
                        <ComboBox Name="cb_Extensions" SelectionChanged="cb_Extensions_SelectionChanged">
                            <ComboBox.Background>
                                <LinearGradientBrush EndPoint="0,1" StartPoint="0,0">
                                    <GradientStop Color="#FFF0F0F0" Offset="0"/>
                                    <GradientStop Color="#FFE5E5E5" Offset="1"/>
                                </LinearGradientBrush>
                            </ComboBox.Background>
                        </ComboBox>
                    </StackPanel>
                </StackPanel>
            </Grid>
            <Button x:Name="btn_Load"  Height="40" Click="btn_LoadFromShortcut" Content="Załaduj skrót" Background="#FF498D11" FontSize="14" Foreground="White"/>
            <Button x:Name="btn_Shortcut" Height="40" Click="btn_Shortcut_Click" Content="Utwórz skrót" Background="#FF498D11" Foreground="White"  FontSize="14"/>
            <Button x:Name="btn_Launch" Height="40" Click="btn_Launch_Click" Content="Uruchom" Background="#FF498D11" Foreground="White"  FontSize="14"/>

        </StackPanel>
    </Grid>
</Window>

Simonsoft177
  • 175
  • 2
  • 22

1 Answers1

0

You'd have to define a Style with a Template for your Button, where you then define the behaviour for certain Triggers. The Trigger you are looking for is called IsMouseOver. Here a little example, where the Background colour is set to Aqua.

<Style x:Key="ButtonStyle" TargetType="{x:Type Button}">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type Button}">
                <Border
                    Width="{TemplateBinding Width}"
                    Height="{TemplateBinding Height}"
                    Background="{TemplateBinding Background}"
                    BorderBrush="{TemplateBinding BorderBrush}"
                    BorderThickness="{TemplateBinding BorderThickness}"
                    CornerRadius="0"
                    SnapsToDevicePixels="True">
                    <ContentPresenter 
                        Margin="{TemplateBinding Padding}"/>
                </Border>

                <ControlTemplate.Triggers>
                    <Trigger Property="IsMouseOver" Value="True">
                        <!-- Define your MouseOver behaviour here! E.g.:-->
                        <Setter Property="Background" Value="Aqua" />
                    </Trigger>
                </ControlTemplate.Triggers>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>
Florian H.
  • 89
  • 10
  • I cant work it out. I dont have action isMouseOver, only MouseEnter, MouseDown, MouseLeave – Simonsoft177 Jul 14 '20 at 11:07
  • You are looking at the `Events ` and not the `Triggers`. As I said, you have to add a `Template ` to your style, which includes Triggers. – Florian H. Jul 14 '20 at 11:22
  • is it possible to shorten this code? Do I need to do all of these things in order to create a hover effect? Because right now i've got a this automatic hover and all I want is to change the color of it – Simonsoft177 Aug 07 '20 at 08:07
  • You usually bundle styles into a (or multiple) style class(es). This means you can reuse them. If you do not always want to change the `IsMouseOver` behaviour, you can create a base style and then create further styles that are based on that base style. – Florian H. Aug 10 '20 at 05:55
  • I got this working thants bro, but had to use diffrent code because this made my button flat and not dynamic. Still thank you – Simonsoft177 Aug 10 '20 at 08:27