WPF ListView键盘导航问题
我有一个像这样的列表视图
:
————----
- 芒果
- 橙子
- 葡萄
- 葡萄
- 葡萄
- 苹果
- 草莓
每当我使用向下箭头导航时,蓝色突出显示会在第一个葡萄处暂停,虚线矩形从第二个葡萄开始,在第三个葡萄处暂停,然后蓝色突出显示从苹果恢复。这看起来很奇怪,当导航向上时,它会变得更奇怪。它从苹果跳到橙子或芒果。
这是由于虚拟化造成的吗?
似乎只有重复的数据(葡萄)造成了问题。有帮助吗?
I've a listview like this
ListView:
————-----
- Mango
- Orange
- Grapes
- Grapes
- Grapes
- Apple
- Strawberry
Whenever i navigate using downarrow, the BlueHighlight pauses at the first Grapes, a dotted rectangle start from second grapes and pauses at the third grapes, then the BlueHighlight resumes from Apple. This seems weird and it grows more weird when the navigation is upwards. It jumps from Apple to Orange or mango.
Is this due to Virtualization?
It seems only the duplicate data (grapes) is creating the problem. Any Help?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
虚线矩形是您的键盘焦点。蓝色矩形是您的选择。
当您向下移动键盘时,焦点会跟踪您所在的位置。然而,该选择会跟踪选择了哪个项目。当同一项目多次出现在列表中时,选择矩形只能显示在其中一项上。
为了使这项工作按照您期望的方式工作,请将您的项目包装在 ObservableCollection 中。因此,
您可以在
ListBox
中编写,您的
ItemTemplate
可以包含一个ContentPresenter
,用于在包装器内呈现水果(例如>
)。The dotted rectangle is your keyboard focus. The blue rectangle is your selection.
As you move down your keyboard focus tracks where you are. The selection, however, tracks which item is selected. When the same item is in the list several times, the selection rectangle can only be shown on one of them.
To make this work the way you are expecting, wrap your items inside your ObservableCollection. So instead of:
you would write
In your
ListBox
yourItemTemplate
can include a singleContentPresenter
that presents the fruit inside the wrapper (eg.<ContentPresenter Content="{Binding Fruit}" />
).将蓝色突出显示视为所选数据项。葡萄是重复的,因此数据选择不会改变。
虚线矩形是键盘焦点,它只关心代表数据项的
ListViewItem
。因此,有一个 Grapes 对象由 3 个
ListViewItem
对象表示。Think of the blue highlight as the selected data item. Grapes is duplicated, so the data selection doesn't change.
The dotted rectangle is the keyboard focus, which only cares about the
ListViewItem
that represents the data item.So there's one Grapes object represented by 3
ListViewItem
objects.您在
ObservableCollection
中有相同的“Grapes”对象 3 次,我的意思是具有相同引用的对象。列表框对此很混乱。每个元素都应该是一个 uncial 实例。You have the same "Grapes" object in
ObservableCollection
3 times, I mean the object with same reference. And Listbox is mess with this. Each element should be an uncial instance.