Glowing WPF Buttons
Asked Answered
H

2

7

After clicking the WPF buttons in our app they glow blue, back to original color, back to blue, etc. This appears to be default behavior on Windows Vista/7. It does not happen on XP. Any advice?

Holman answered 16/2, 2010 at 20:1 Comment(0)
R
9

You need to override the default button template -- http://mark-dot-net.blogspot.com/2007/07/creating-custom-wpf-button-template-in.html should get ya started.

Specifically Section 3:

<ControlTemplate.Triggers>
    <Trigger Property="IsMouseOver" Value="True">
        <Setter TargetName="border" Property="BorderBrush" Value="#FF4788c8" />
        <Setter Property="Foreground" Value="#FF4788c8" />
    </Trigger>
    <Trigger Property="IsPressed" Value="True">                   
       <Setter Property="Background" >
           <Setter.Value>
               <LinearGradientBrush StartPoint="0,0" EndPoint="0,1" >
                   <GradientStop Color="#FFFFD190" Offset="0.35"/>
                   <GradientStop Color="Orange" Offset="0.95"/>
                   <GradientStop Color="#FFFFD190" Offset="1"/>
               </LinearGradientBrush>
            </Setter.Value>
        </Setter>
        <Setter TargetName="content" Property="RenderTransform" >
            <Setter.Value>
                <TranslateTransform Y="1.0" />
            </Setter.Value>
        </Setter>
    </Trigger>
    <Trigger Property="IsDefaulted" Value="True">
       <Setter TargetName="border" Property="BorderBrush" Value="#FF282828" />
    </Trigger>
    <Trigger Property="IsFocused" Value="True">
       <Setter TargetName="border" Property="BorderBrush" Value="#FF282828" />
    </Trigger>
    <Trigger Property="IsEnabled" Value="False">
       <Setter TargetName="border" Property="Opacity" Value="0.7" />
       <Setter Property="Foreground" Value="Gray" />
   </Trigger>
</ControlTemplate.Triggers>
Ripping answered 16/2, 2010 at 20:3 Comment(2)
Your triggers would be better suited in a Style which is considerably easier than using a ControlTemplateMandell
@Mandell Feel free to post an alternate answer if there is a better approach! There has been no accepted answer here. The Style option may very well be the best option. If anything else it will help others who find this post, even if OP has solved and shipped his code.Ripping
C
2

You need to override the ControlTemplate. Otherwise it's using triggers to set the colors on events like hovering the mouse over it. If you simply set the Background, you're only setting the default background when there's no Triggers going on.

Cham answered 16/2, 2010 at 20:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.