在 WPF 渐变按钮中,点击后默认颜色和新渐变之间会出现脉冲 - 如何停止 [英] In WPF Gradient Button pulses between the default color and new gradient once clicked - how to stop

查看:24
本文介绍了在 WPF 渐变按钮中,点击后默认颜色和新渐变之间会出现脉冲 - 如何停止的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个非常烦人的工件,我注意到 WPF 并且我很好奇我可能做错了什么,因为我在 WPF XAML 中执行看似简单的代码:

This is a very annoying artifact I am noticing of WPF and I was curious what I could potentially be doing wrong as I am doing what appears to be simple code in WPF XAML:

<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="ExampleShapes.MainWindow"
x:Name="Window"
Title="MainWindow"
Width="400" Height="400">
<Grid x:Name="LayoutRoot">
    <Button Margin="50,50,50,50" Content="I pulse when clicked Why?">
        <Button.Background>
            <LinearGradientBrush EndPoint="0,1" StartPoint="0,0">
                <GradientStop Color="#FF0C0B0B" Offset="1"/>
                <GradientStop Color="#FFBF5656"/>
            </LinearGradientBrush>
        </Button.Background>
    </Button>
</Grid>

.NET 中似乎有一些我不知道的默认值,我不知道我不想要的 MouseOver 和 Click 事件.我不介意当鼠标悬停时它会将渐变的颜色更改为默认值,但是当我删除它时它会变回来.然而,即使在为CLICK"事件(不在示例中)应用底层 C# 代码之前,它也会假设在我指定的渐变和默认值之间出现脉冲"行为.对于简单的颜色也是如此.什么给?

It appears that there are some defaults that are in .NET that I am unaware of with events of the MouseOver and Click that I DO NOT WANT. I don't mind that when the mouse hovers that it changes the color of the gradient to the default but when I remove it it changes back. However even before applying underlying C# code for the 'CLICK' event (not in example) it assumes a 'pulsing' behavior of going between my specified gradient and the default. This is also true with a simple color. What gives?

有关更多信息,我正在使用 Visual Studio 2010 和 Expression Blend 3 的 Windows 7 64 位盒子进行设计,使用 .NET 4.0 for VS2010 不确定 EB3,因为它是一个较旧的副本,他们都这样做.有没有简单的方法可以更改默认行为,还是必须为按钮设置新的用户模板?

For further info I am designing on a Windows 7 64 bit box with Visual Studio 2010 and Expression Blend 3 using .NET 4.0 for VS2010 unsure for EB3 as it's an older copy and they Both do this. Is there a simple way to change the default behavior or do I have to set up a new user template for the button?

非常感谢您的帮助!

推荐答案

这似乎与 Button 的 Focused 样式有关.我猜默认的焦点样式在正常背景和鼠标悬停背景之间交替,这会导致脉冲"行为.

It appears to have something to do with the Focused style for the Button. I am guessing the default focused style alternates between the normal and mouseover backgrounds, which is causing the "pulsing" behavior.

点击按钮将其设置为焦点,但您也可以通过简单地切换到按钮来实现相同的效果.

Clicking the button sets it as focused, but you can also achieve the same effect by simply tabbing to the button.

编辑

再仔细研究一下,它似乎是任何具有输入焦点的元素的 Aero 主题的默认设置.您可以设置按钮的 Focusable="False",但是随后您无法使用 Tab 键或按 Enter 键(尽管仍然可以单击它),而且我个人讨厌我不能的应用程序t 使用键盘导航.

Looking into this a bit more and it seems to be the default for the Aero theme for any element that has input focus. You can set the button's Focusable="False", however then you can't tab to the button or hit Enter on it (can still click it though), and personally I hate applications that I can't navigate with the keyboard.

为了避免点击时闪烁,您可以在点击事件结束时将焦点设置到另一个控件上,但是当您点击按钮时仍然会出现效果.

To avoid the flashing when clicked, you can set focus to another control at the end of your click event, however the effect will still occur when you tab to the button.

这篇关于在 WPF 渐变按钮中,点击后默认颜色和新渐变之间会出现脉冲 - 如何停止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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