c# - 在 Windows Presentation Foundation WPF C# 中禁用自动鼠标悬停
问题描述
我创建了一个 Windows Presentation Foundation WPF 应用程序。
问题是当我将鼠标悬停在按钮上时会产生蓝色闪烁的自动 MouseHover。
我检查了所有组件,堆栈面板,网格,按钮......等,在我的选项中没有 MouseHover 动作,它是某种默认悬停,我无法禁用它。我可以以某种方式禁用或更改它吗?
<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>
解决方案
您必须为您的 定义Style
a ,然后在其中定义某些 的行为。您正在寻找的称为. 这里有一个小例子,颜色设置为 Aqua。Template
Button
Triggers
Trigger
IsMouseOver
Background
<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>
推荐阅读
- javascript - react-native 中的重复组件
- javascript - Github API 响应复制到 javascript 对象 Angular 应用程序
- reactjs - 是的,没有使用 Formik,也没有提供任何类型的错误
- android - 如何在颤振的小部件中加载(显示)大图像的一部分?
- assembly - x86 binarySearch 实现中的分段错误
- r - RAM 内存使用和管理:R 与 Power BI。为什么 Power Bi 在同一台计算机上处理大型数据集似乎比 R 更好?
- typescript - VSCode 扩展在调试模式下工作正常,但在发布时无法正常工作
- react-native - latlng 不能为空,需要一个位置。反应原生
- condor - HTCondor:在提交文件中,如何评估变量的值以便将其写入输出文件名?
- mysql - 如何填充表单:使用 onclick 图像的数据库记录