Why does WPF toggle button pulse once unchecked
Asked Answered
A

2

5

Within a Desktop app I have a toggle button:

<ToggleButton x:Name="CFStglBtn" Checked="cfsCBox_Checked"
              Unchecked="cfsCBox_Unchecked"
              IsChecked="True" HorizontalAlignment="Left" Margin="5,0,0,0">
    <StackPanel Orientation="Horizontal">
        <Image Source="assets\telephone.png" Margin="3,0,0,0" />
        <TextBlock Text="CFS" FontSize="10" Margin="5,5,5,0"
                   Foreground="DarkSlateGray"/>
    </StackPanel>
</ToggleButton>

For the Checked event I am setting a value and then executing a method FilterView(); //ommitting code

Unchecked state is just the opposite. resets a variable and executed the method again

The question I have is I noticed when I uncheck the toggle button the button continues to pulse or flash ( going from blue to chrome) as if it still has focus. The button will stay like this until another button is clicked.

Is there a way to remove this focus so that when the button is unchecked the button goes back to a unchecked state without the flashing / pulsing color.

  • As you can see from above this is a standard toggle button no styles or custom
  • I tested this on just a regular button and I found the same occured when clicked the button will continue to pulse / flash until another button is clicked.

How do you work around this or prevent this effect from happening.

Thank you

Acoustician answered 15/6, 2010 at 18:53 Comment(2)
not sure why it didn't post but here is the code for the toggle button <ToggleButton x:Name="CFStglBtn" Checked="cfsCBox_Checked" Unchecked="cfsCBox_Unchecked" IsChecked="True" HorizontalAlignment="Left" Margin="5,0,0,0"> <StackPanel Orientation="Horizontal"> <Image Source="assets\telephone.png" Margin="3,0,0,0" /> <TextBlock Text="CFS" FontSize="10" Margin="5,5,5,0" Foreground="DarkSlateGray"/> </StackPanel> </ToggleButton>Acoustician
Code needs to be preceded by a blank line and indented 4 spaces. Or highlight it and click the "Code Sample" (101010) icon.Fitful
C
5

This is happening because of the button chrome built into the default template for the control. Your only workaround is to re-template the Button. This article should get you started.

Cosmos answered 15/6, 2010 at 19:37 Comment(1)
Thanks that is perfect I also checked with a peer of mine and he refereced an article from StackOverflow with another solution #363493 Thanks again!Acoustician
B
12

Set the Button Focusable="False".

Boman answered 1/3, 2012 at 15:22 Comment(1)
nice easy fix instead of re-templatingGrubstake
C
5

This is happening because of the button chrome built into the default template for the control. Your only workaround is to re-template the Button. This article should get you started.

Cosmos answered 15/6, 2010 at 19:37 Comment(1)
Thanks that is perfect I also checked with a peer of mine and he refereced an article from StackOverflow with another solution #363493 Thanks again!Acoustician

© 2022 - 2024 — McMap. All rights reserved.