WPF ListView键盘导航问题

发布于 2024-08-21 16:05:05 字数 309 浏览 3 评论 0原文

我有一个像这样的列表视图


————----

  • 芒果
  • 橙子
  • 葡萄
  • 葡萄
  • 葡萄
  • 苹果
  • 草莓

每当我使用向下箭头导航时,蓝色突出显示会在第一个葡萄处暂停,虚线矩形从第二个葡萄开始,在第三个葡萄处暂停,然后蓝色突出显示从苹果恢复。这看起来很奇怪,当导航向上时,它会变得更奇怪。它从苹果跳到橙子或芒果。

这是由于虚拟化造成的吗?
似乎只有重复的数据(葡萄)造成了问题。有帮助吗?

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 技术交流群。

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

发布评论

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

评论(3

瘫痪情歌 2024-08-28 16:05:05

虚线矩形是您的键盘焦点。蓝色矩形是您的选择。

当您向下移动键盘时,焦点会跟踪您所在的位置。然而,该选择会跟踪选择了哪个项目。当同一项目多次出现在列表中时,选择矩形只能显示在其中一项上。

为了使这项工作按照您期望的方式工作,请将您的项目包装在 ObservableCollection 中。因此,

coll.Add(fruit);

您可以在 ListBox 中编写

coll.Add(new FruitWrapper(fruit));

,您的 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:

coll.Add(fruit);

you would write

coll.Add(new FruitWrapper(fruit));

In your ListBox your ItemTemplate can include a single ContentPresenter that presents the fruit inside the wrapper (eg. <ContentPresenter Content="{Binding Fruit}" />).

极度宠爱 2024-08-28 16:05:05

将蓝色突出显示视为所选数据项。葡萄是重复的,因此数据选择不会改变。

虚线矩形是键盘焦点,它只关心代表数据项的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.

笑,眼淚并存 2024-08-28 16:05:05

您在 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.

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