列表元素 WPF 之间的制表符 [英] Tab between List elements WPF

查看:42
本文介绍了列表元素 WPF 之间的制表符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个列表框,其中每个项目都使用文本框表示.问题是我希望能够在移动到 xaml 窗口中的下一个元素之前在列表框中的所有项目之间切换.

I have a listbox that in which every item is represented using a textbox. The thing is that I want to be able to tab between all the items in the listbox before moving to the next element in the xaml window.

当前(和正常的 WPF 行为)是,当我使用 Tab 键进入列表框时,第一个元素会突出显示,如果我再次使用 Tab 键,则焦点移动到该项目内的文本框中.如果我再次使用 Tab,焦点将移至窗口中的下一个元素(不经过 ListBox 中的任何其他项目).

The current (and normal WPF behavior) is that when I tab into the listbox, the first element is highlighted, if I tab again, then the focus moves into the textbox inside that item. If I tab once again, focus moves to the next element in the window (without going through any of the other items in the ListBox).

我想要的行为如下:当我进入列表框时,第一个文本框自动获得焦点(不突出显示整个项目)*.如果我再次使用 Tab,则列表框中的下一个文本框将获得焦点.当我在列表框中的最后一个文本框上使用 Tab 键时,焦点将移动到下一个控件.

The behavior I want is the following: When I tab into the listbox, the first textbox obtains focus automatically (without highlighting the whole Item)*. If I tab again then the next textbox in the listbox gets focus. When I tab at the last textbox in the listbox, then focus moves to the next control.

*我已经这样做了,我在这里发布它只是为了解释完整的过程.

*I already how to do this, I'm only posting it here in order to explain the complete process.

我一直在寻找解决方案,但一直找不到.

I've been looking for the solution and I've been unable to find something.

推荐答案

这可以在 xaml 中完成,通过设置以下两个属性.

This can be done in xaml, by setting the following two properties.

    <Style TargetType="ListBox" >
        <Setter Property="KeyboardNavigation.TabNavigation" Value="Continue" />
    </Style>

    <Style TargetType="ListBoxItem">
        <Setter Property="IsTabStop" Value="False" />
    </Style>

完整解释见德里克威尔逊的博客文章.

这篇关于列表元素 WPF 之间的制表符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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