删除标准wpf按钮上的悬停效果 [英] Remove the hover effect on a standard wpf button

查看:149
本文介绍了删除标准wpf按钮上的悬停效果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,

我希望有人可以帮助我。我使用的是标准的wpf Button。但我不希望鼠标进入控件时显示悬停效果。除了使用控制模板之外,还有其他选择除去这个效果吗?

也许有可能将系统画笔更改为透明或某些东西?



感谢您的帮助

greets moti

解决方案

查看第二个答案在哪里制作一个没有内置鼠标的WPF按钮的方法动画效果,仍然有简单的鼠标效果,显示黑色按钮边框。关键部分是

< trigger property =   IsMouseOver  value  =   >  



< / 触发器 >





您可以将MouseOver所需的任何动作放在那里或完全消除效果。


您必须自己创建按钮。 (据我所知)Mark H.就此做了一个教程。 (见链接)



创建自定义WPF按钮 [ ^ ]


如果有人不想覆盖默认控制模板然后这是解决方案。 

您可以创建DataTemplate for按钮,该按钮可以具有TextBlock,然后您可以在IsMouseOver属性上编写Property触发器以禁用鼠标悬停效果。 TextBlock和Button的高度应该相同。

< 按钮 背景 = 黑色 保证金 = 0 填充 = 0 BorderThickness = 0 光标 = 高度 = 20 >
< Button.ContentTemplate >
< DataTemplate >
< TextBlock 文字 = GO Foreground = 白色 Horizo​​ntalAlignment = 中心 VerticalAlignment = 中心 TextDecorations = 下划线 保证金 = 0 < span class =code-attribute>填充 = 0 高度 = 20 >
< TextBlock.Style >
< 样式 TargetType = TextBlock >
< Style.Triggers >
< 触发器 属性 = IsMouseOver = True >
< Setter 属性 = 背景 = 黑色 / >
< / Trigger >
< / Style.Triggers >
< / Style >
< / TextBlock.Style >
< span class =code-keyword><
/ TextBlock >
< / DataTemplate >
< / Button.ContentTemplate >
< /按钮 > ;


Hello,
i hope there is anybody who can help me. I am using a standard wpf Button. But i dont want the hover effekt to be displayed when the mouse enters the control. Is there any other option, to get rid of this effekt, except using a Control Template?
Maybe there is the possibility of changing the System Brush to transparent or somthing?

thanks for help
greets moti

解决方案

See the second answer here for a way to make a WPF button without the built-in mouse over animation effect, that still has the simple mouse over effect of showing the button border in black. The key section there is the section

<trigger property="IsMouseOver" value="True">
.
.
.
</trigger>



You can put any kind of action you want for MouseOver in there or get rid of the effect altogether.


You have to make your own button. (As far as I know) Mark H. made a tutorial on this. (see link)

Creating Custom WPF-Buttons [^]


If someone doesn't want to override default Control Template then here is the solution.

You can create DataTemplate for button which can have TextBlock and then you can write Property trigger on IsMouseOver property to disable mouse over effect. Height of TextBlock and Button should be same.

        <Button Background="Black" Margin="0" Padding="0" BorderThickness="0" Cursor="Hand" Height="20">
                        <Button.ContentTemplate>
                            <DataTemplate>
                                <TextBlock Text="GO" Foreground="White" HorizontalAlignment="Center" VerticalAlignment="Center" TextDecorations="Underline" Margin="0" Padding="0" Height="20">
                                    <TextBlock.Style>
                                        <Style TargetType="TextBlock">
                                            <Style.Triggers>
                                                <Trigger Property ="IsMouseOver" Value="True">
                                                    <Setter Property= "Background" Value="Black"/>
                                                </Trigger>
                                            </Style.Triggers>
                                        </Style>
                                    </TextBlock.Style>
                                </TextBlock>
                            </DataTemplate>
                        </Button.ContentTemplate>
                    </Button>


这篇关于删除标准wpf按钮上的悬停效果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆