按下向上/向下箭头时,选择单选按钮 [英] Mark a Radio Button selected when Up/Down arrow is pressed
问题描述
在C#WPF表单中。我有一个单选按钮组,有3个单选按钮。目前,如果我按向上/向下箭头,我可以通过组中的单选按钮进行解析,但它们未被选中。我需要一个空格按来选择它们。
我期望的行为是,当我按下向上/向下箭头时,聚焦的单选按钮应该被选中而离开另一个单选按钮未选中。有人可以提供具有此行为的示例代码。
In C# WPF forms. I have a radio button group which has 3 radio buttons. Currently if I press Up/Down arrow, I'm able to parse through radio buttons in the group but they are not selected. I need a space press to select them.
The behavior I expect is, when I press a Up/Down arrow, the focused radio button should get selected leaving the other radio buttons unchecked. Could someone give a sample code which has this behavior.
推荐答案
这似乎与您昨天提出的问题相同:
This seems to be the same question as the one you asked yesterday:
https://social.msdn.microsoft.com/Forums/vstudio/en-US/93ecf0e8-b96f-47f5-a890-6c118a1267b0/check-radiobutton-when-tab-is-pressed?forum= wpf#93ecf0e8-b96f-47f5-a890-6c118a1267b0
https://social.msdn.microsoft.com/Forums/vstudio/en-US/93ecf0e8-b96f-47f5-a890-6c118a1267b0/check-radiobutton-when-tab-is-pressed?forum=wpf#93ecf0e8-b96f-47f5-a890-6c118a1267b0
没有关于更改标签顺序的内容
Just without the stuff about changing tab order
<Window.Resources>
<Style TargetType="RadioButton">
<Style.Triggers>
<DataTrigger Binding="{Binding Path=IsFocused, RelativeSource={RelativeSource Self}}" Value="True">
<Setter Property="IsChecked" Value="True"/>
</DataTrigger>
</Style.Triggers>
</Style>
</Window.Resources>
<Grid>
<StackPanel>
<RadioButton>xxxx</RadioButton>
<RadioButton>yyyy</RadioButton>
<RadioButton>zzzzz</RadioButton>
</StackPanel>
</Grid>
</Window>
无论是制表符还是箭头,控件都会获得焦点,触发器会设置为IsChecked。
Whether you tab or arrow, the control receives focus and the trigger sets IsChecked.
IsChecked是勾选一个复选框或者给圆圈中的一个单选按钮。
IsChecked is the thing makes a checkbox ticked or gives a radiobutton the spot in the circle.
。
请不要忘记阅读你的主题并将帖子标记为解决问题的答案。
Please don't forget to read your threads and mark post(s) as answer which resolve your issues.
这篇关于按下向上/向下箭头时,选择单选按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!