In WPF Gradient Button, pulses between the default color and the new gradient after clicking - how to stop

This is a very nasty artifact that I notice in WPF, and I was curious what I could do wrong, because I am doing what seems like 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> 

It seems that there are some default values ​​that are in .NET that I do not know about the MouseOver and Click events that I DO NOT WANT. I do not mind that when the mouse hangs, it changes the color of the gradient to the default value, but when I delete it, it changes back. However, even before applying the C # base code for the 'CLICK' event (not in the example), it assumes a "pulsating" transition behavior between my given gradient and the default value. This is true for plain color. What gives?

For more information, I am developing on a 64-bit box of Windows 7 with Visual Studio 2010 and Expression Blend 3, using .NET 4.0 for VS2010, unsure of EB3, as this is an older copy, and they both do it. Is there an easy way to change the default behavior or do I need to configure a new user template for a button?

Any help is greatly appreciated thanks!

+6
source share
1 answer

This seems to be related to Focused focus for Button. I assume that the default focused style alternates between the normal background and the mouse background, which causes a "pulsating" behavior.

Pressing the button sets it as focused, but you can also achieve the same effect by simply pressing the button.

Edit

Looking into this is a little more, and it seems the default Aero theme for any item with input focus. You can set the Focusable="False" button, but then you cannot go to the button or press Enter on it (you can still click it), and personally I hate applications that I can’t move using the keyboard.

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

+6
source

Source: https://habr.com/ru/post/903395/


All Articles