WPF/xaml 中视图元素之间的 Tab 键切换

发布于 2024-08-05 14:31:50 字数 377 浏览 4 评论 0原文

我正在尝试在 xaml 中的当前 WPF 项目上设置选项卡键盘控制选项。

本质上,我在一个视图中、另一个视图中、另一个视图中都有一个 TextBox 元素。无论如何,当按下键盘上的选项卡时,它开始循环浏览容器视图的各种元素,并最终转到我需要它去的文本框。我希望让它从这个文本框开始,并且我希望有一种简单的方法来实现这一点。

我尝试设置 KeyboardBinding.TabNavigation 设置以及 TabIndex 选项,但这些并没有按照我想要的方式工作。

据我所知,到目前为止,我担心我可能需要转到容器视图并单独在每个 ItemControl 上设置绑定属性,然后它将使用每个子元素的本地选项卡设置。

不管怎样,我希望有一个更有效的方法。

提前致谢。

I'm trying to setup the tab keyboard control options on my current WPF project in xaml.

Essentially, I've got a TextBox element within a view, within another view, within another view. Anyway, when pushing tab on the keyboard, it starts cycling through various elements of the container views and eventually goes to the TextBox I need it to go to. I'm hoping to make it start at this text box, and I'm hoping there is an easy way to accomplish this.

I tried setting KeyboardBinding.TabNavigation settings, as well as TabIndex options, but these aren't working in the way I'm trying to get.

From what I understand so far, I'm worried I may need to go to the container views and set up a binding property on each of the ItemControls individually and then it would use the local tabbing settings for each child element.

Anyway, I'm hoping there is a more efficient way.

Thanks in advance.

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

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

发布评论

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

评论(1

半步萧音过轻尘 2024-08-12 14:31:50

在您的根容器(在我的示例中它是一个用户控件)中设置焦点,如下所示:

<UserControl FocusManager.FocusedElement="{Binding ElementName=txtMyTextBox}">
    <TextBox x:Name="txtMyTextBox" />
</UserControl>

At your root container (in my example it's a user control) set the focus like this:

<UserControl FocusManager.FocusedElement="{Binding ElementName=txtMyTextBox}">
    <TextBox x:Name="txtMyTextBox" />
</UserControl>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文