具体来说,我希望能够启动我的WPF (C#)应用程序,然后立即能够使用箭头键在两个单选按钮之间切换。
实际上,我需要使用Tab键或鼠标来“选择”其中一个单选按钮,然后我可以开始使用箭头键在它们之间跳跃。
注意:我不是在问如何控制默认选中哪个单选按钮。我想知道如何优化我的WPF控件的键盘友好性。
发布于 2019-12-13 01:58:03
您可以使用Focus ()函数来选择窗口打开时选定的项。
public MainPage()
{
InitializeComponent();
Button1.Focus();
}
您可以定义TabIndex订单来优化用户体验。
在Xaml中:
<Button x:Name="Button1" TabIndex="0"/>
<Button x:Name="Button2" TabIndex="1"/>
<Button x:Name="Button3" TabIndex="2"/>
或者在C#中:
Button1.TabIndex = 0;
Button2.TabIndex = 1;
Button3.TabIndex = 2;
https://stackoverflow.com/questions/59319806
复制