为什么 WPF 切换按钮一旦未选中就会发出脉冲
在桌面应用程序中,我有一个切换按钮:
<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>
对于 Checked 事件,我设置一个值,然后执行 FilterView() 方法; //省略代码
未检查状态正好相反。重置变量并再次执行该方法
我的问题是,当我取消选中切换按钮时,我注意到按钮继续脉冲或闪烁(从蓝色变为铬色),就好像它仍然具有焦点一样。该按钮将保持这种状态,直到单击另一个按钮。
有没有办法消除此焦点,以便当未选中按钮时按钮返回到未选中状态而不会闪烁/脉冲颜色。
- 正如您从上面看到的,这是一个标准切换按钮,没有样式或自定义,
- 我仅在常规按钮上进行了测试,发现单击时会发生相同的情况,该按钮将继续脉冲/闪烁,直到单击另一个按钮。
您如何解决这个问题或防止这种影响发生。
谢谢
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
设置按钮
Focusable="False"
。Set the Button
Focusable="False"
.发生这种情况是因为控件的默认模板中内置了按钮镶边。您唯一的解决方法是重新模板化
Button
。 本文应该可以帮助您入门。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.