在 WPF 中设置 Tab 键顺序
如何在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
如果您想显式设置表单中元素的制表符顺序,则以下附加属性应该有所帮助:
我说“应该有所帮助”,因为我还没有发现它非常可靠,尽管我可能需要阅读更多有关它如何使用的信息旨在使用。 我只发布这个半生不熟的答案,因为没有其他人提到这个属性。
请注意,在 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:
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"
.您可以通过设置 KeyboardNavigation 来跳过 Tab 键序列中的元素XAML 中元素上的 .IsTabStop。
您可以设置一个触发器,根据展开状态切换此属性。
You can skip elements in the tab sequence by setting KeyboardNavigation.IsTabStop on the element in XAML.
You can setup a trigger that would toggle this property based on the expanded state.
工作得很好...例如 -
将允许您使用 TAB 键浏览这两个组合框。
<Control KeyboardNavigation.TabIndex="0" ... />
Works perfectly fine...For example-
Will allow you to navigate through these two combo boxes using TAB key.
我认为这里有一个更简单的解决方案,
在控件或窗口的顶部,您可以添加:
这也会自动忽略折叠的选项卡。
I think there is a much easier solution here,
at the top within your control or window, you could add:
This also automaticaly ignores the collapsed tabs.
过去对我有用的另一种选择是简单地删除所有显式
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.
您可以使用 KeyboardNavigation.TabNavigation="None" 完全跳过特定控件的 Tab 键操作。
You can use KeyboardNavigation.TabNavigation="None" to completely skip the Tabbing for specific control.