简体   繁体   中英

Disable automatic MouseHover in Windows Presentation Foundation WPF C#

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?

在此处输入图像描述

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

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM