在 WPF 中设置 Tab 键顺序

发布于 2024-07-09 23:31:08 字数 99 浏览 8 评论 0原文

如何在 WPF 中设置选项卡顺序? 我有一个 ItemsControl,其中一些项目已展开,有些项目已折叠,并且想在使用选项卡时跳过折叠的项目。

有任何想法吗?

How do I set tab ordering in WPF? I have an ItemsControl with some items expanded and some collapsed and would like to skip the collapsed ones when I'm tabbing.

Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

纸伞微斜 2024-07-16 23:31:08

如果您想显式设置表单中元素的制表符顺序,则以下附加属性应该有所帮助:

<Control KeyboardNavigation.TabIndex="0" ... />

我说“应该有所帮助”,因为我还没有发现它非常可靠,尽管我可能需要阅读更多有关它如何使用的信息旨在使用。 我只发布这个半生不熟的答案,因为没有其他人提到这个属性。


请注意,在 Win RT 中,该属性只是 TabIndex="0"

If you want to explicitly set the tab ordering for elements in your form, the following attached property is supposed to help:

<Control KeyboardNavigation.TabIndex="0" ... />

I say "supposed to help" as I haven't found it very reliable though I probably need to read more about how it is intended to be used. I only post this half baked answer because no one else mentioned this property.


Note that in Win RT, the property is just TabIndex="0".

回梦 2024-07-16 23:31:08

您可以通过设置 KeyboardNavigation 来跳过 Tab 键序列中的元素XAML 中元素上的 .IsTabStop

KeyboardNavigation.IsTabStop="False"

您可以设置一个触发器,根据展开状态切换此属性。

You can skip elements in the tab sequence by setting KeyboardNavigation.IsTabStop on the element in XAML.

KeyboardNavigation.IsTabStop="False"

You can setup a trigger that would toggle this property based on the expanded state.

原来是傀儡 2024-07-16 23:31:08

工作得很好...
例如 -

<ComboBox Height="23" 
          Margin="148,24,78,0" 
          Name="comboBoxDataSet"
          VerticalAlignment="Top"
          SelectionChanged="comboBoxDestMarketDataSet_SelectionChanged"
          DropDownOpened="comboBoxDestMarketDataSet_DropDownOpened"
          KeyboardNavigation.TabIndex="0" />
<ComboBox Height="23" 
          Margin="148,56,78,0" 
          Name="comboBoxCategory" 
          VerticalAlignment="Top" 
          SelectionChanged="comboBoxDestCategory_SelectionChanged"
          DropDownOpened="comboBoxDestCategory_DropDownOpened"
          KeyboardNavigation.TabIndex="1" />

将允许您使用 TAB 键浏览这两个组合框。

<Control KeyboardNavigation.TabIndex="0" ... /> Works perfectly fine...
For example-

<ComboBox Height="23" 
          Margin="148,24,78,0" 
          Name="comboBoxDataSet"
          VerticalAlignment="Top"
          SelectionChanged="comboBoxDestMarketDataSet_SelectionChanged"
          DropDownOpened="comboBoxDestMarketDataSet_DropDownOpened"
          KeyboardNavigation.TabIndex="0" />
<ComboBox Height="23" 
          Margin="148,56,78,0" 
          Name="comboBoxCategory" 
          VerticalAlignment="Top" 
          SelectionChanged="comboBoxDestCategory_SelectionChanged"
          DropDownOpened="comboBoxDestCategory_DropDownOpened"
          KeyboardNavigation.TabIndex="1" />

Will allow you to navigate through these two combo boxes using TAB key.

南风几经秋 2024-07-16 23:31:08

我认为这里有一个更简单的解决方案,
在控件或窗口的顶部,您可以添加:

KeyboardNavigation.TabNavigation="Cycle"

这也会自动忽略折叠的选项卡。

I think there is a much easier solution here,
at the top within your control or window, you could add:

KeyboardNavigation.TabNavigation="Cycle"

This also automaticaly ignores the collapsed tabs.

泅人 2024-07-16 23:31:08

过去对我有用的另一种选择是简单地删除所有显式 TabIndex 语句,并让控件使用它们在 XAML 中声明的顺序来发挥其魔力。

当然,这可能需要您重新排序控件。 但这是一个简单的复制粘贴操作。

Another alternative that has worked for me in the past is to simply remove all explicit TabIndex statements, and let the controls use the order that they're declared in XAML work their magic.

This, of course, may require you to reorder your controls. But this is a simple copy-paste operation.

烟柳画桥 2024-07-16 23:31:08

您可以使用 KeyboardNavigation.TabNavigation="None" 完全跳过特定控件的 Tab 键操作。

You can use KeyboardNavigation.TabNavigation="None" to completely skip the Tabbing for specific control.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文