[英]How to remove highlight on button if IsMouseHover is true in wpf
I am developing a WPF project. 我正在开发WPF项目。 I want to remove highlight (it is like blue in picture) on button if isMouseHover of Button is true.
如果Button的isMouseHover为true,我想删除按钮上的突出显示(图片中的蓝色)。 And I am not sure it is called highlight.
而且我不确定它是否称为高光。 Maybe it is probably effect, focus etc.. I added BorderBrush is transparent but it didn't work.
也许是效果,焦点等。我添加了BorderBrush是透明的,但是没有用。 The code is as follows:
代码如下:
<Image x:Key="LoginImg" Source="..\Images\Login\oturumac.png"
Stretch="Fill"/>
<Image x:Key="LoginImg_RollOver" Source="..\Images\Login\oturumac_rollover.png"
Stretch="Fill"/>
<Style x:Key="LoginButtonStyle" TargetType="{x:Type Button}">
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Content" Value="{DynamicResource LoginImg_RollOver}"/>
</Trigger>
<Trigger Property="IsMouseOver" Value="False">
<Setter Property="Content" Value="{DynamicResource LoginImg}"/>
</Trigger>
</Style.Triggers>
</Style>
Picture is as follows. 图片如下。 First picture when IsMouseOver is true:
IsMouseOver为true时的第一张图片:
How can I solve? 我该如何解决?
Button code is as follows: 按钮代码如下:
<Button Background="Transparent" BorderBrush="Transparent" Style="{DynamicResource LoginButtonStyle}" Click="btnLogin_Click" HorizontalAlignment="Center" VerticalAlignment="Top" Width="180" Grid.Column="1" Grid.Row="4" x:Name="btnLogin" TabIndex="2"/>
You'll need to provide a new ControlTemplate
for the Button
to get rid of the default look and feel. 您需要为
Button
提供一个新的ControlTemplate
,以摆脱默认的外观。 You can just replace the default Button ControlTemplate
with a plain Image
control and replace your Style Trigger
s with ControlTemplate Trigger
s. 您可以只将默认的
Button ControlTemplate
替换为普通的Image
控件,然后将Style Trigger
替换为ControlTemplate Trigger
。 Try this: 尝试这个:
<Button>
<Button.Template>
<ControlTemplate>
<Image Name="Image" Stretch="None"
Source="pack://application:,,,/AppName;component/Images/Login/oturumac.png" />
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="Image" Property="Source" Value="
pack://application:,,,/AppName;component/Images/Login/oturumac_rollover.png" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Button.Template>
</Button>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.