按Tab键时检查RadioButton [英] Check RadioButton when Tab is pressed

查看:170
本文介绍了按Tab键时检查RadioButton的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个单选按钮组,有3个单选按钮和2个按钮。目前,如果我按Tab键,则组中的第一个单选按钮被聚焦,而在第二个Tab上按下它会移动到按钮。如果我按向上/向下箭头,焦点将移动到
组中的其他单选按钮。 


我期望的行为是,当我按下标签时,焦点应该移动到组中的其他单选按钮,并且应该选择聚焦的单选按钮,而不选中其他单选按钮。一旦组中的最后一个单选按钮被聚焦,下一个Tab
按下应该关注视图中的按钮。有人可以提供具有此行为的示例代码。 

解决方案

您可以使用通过样式应用的数据触发器来设置IsChecked和您可以设置tabindex来控制您使用选项卡导航到哪个控件:

< Window.Resources> 
< Style TargetType =" RadioButton">
< Style.Triggers>
< DataTrigger Binding =" {Binding Path = IsFocused,RelativeSource = {RelativeSource Self}}"值= QUOT;真">
< Setter Property =" IsChecked"值= QUOT;真" />
< / DataTrigger>
< /Style.Triggers>
< / Style>
< /Window.Resources>
< Grid>
< StackPanel>
< RadioButton KeyboardNavigation.TabIndex =" 0"> xxxx< / RadioButton>
< Button KeyboardNavigation.TabIndex =" 3">一些按钮< / Button>
< RadioButton KeyboardNavigation.TabIndex =" 1"> yyyy< / RadioButton>
< RadioButton KeyboardNavigation.TabIndex =" 2"> zzzzz< / RadioButton>
< / StackPanel>
< / Grid>
< / Window>

我的建议是在默认情况下更改Tab键顺序之前要三思而行。


It当您从默认订单更改时,往往会使用户感到困惑。


可能用户在此处特别要求的工作中有一些特定的逻辑。



I have a radio button group which has 3 radio buttons and 2 buttons. Currently if I press Tab then first radio button in the group is focused and on second Tab press it moves to button. If I press Up/Down arrows, focus is moved to other radio buttons in the group. 

The behavior I expect is, when I press a tab, the focus should move to other radio buttons in the group and the focused radio button should get selected leaving the other radiobuttons unchecked. Once the last radio button in the group is focused, next Tab press should focus on Buttons in the view. Could someone give a sample code which has this behavior. 

解决方案

You can use a datatrigger applied via a style to set IsChecked and you can set tabindex to control which control you navigate to with a tab:

    <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 KeyboardNavigation.TabIndex="0">xxxx</RadioButton>
            <Button      KeyboardNavigation.TabIndex="3">Some button</Button>
            <RadioButton KeyboardNavigation.TabIndex="1">yyyy</RadioButton>
            <RadioButton KeyboardNavigation.TabIndex="2">zzzzz</RadioButton>
        </StackPanel>
    </Grid>
</Window>

My advice would be to think twice before changing tab order from the default.

It tends to confuse users when you change from the default order.

Maybe there's some particular logic at work the users have specifically requested here though.


这篇关于按Tab键时检查RadioButton的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆