WPF ListView的键盘导航问题 [英] WPF ListView Keyboard Navigation Problem

查看:315
本文介绍了WPF ListView的键盘导航问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的一个ListView

I've a listview like this

的ListView:结果
---------结果

ListView:
————-----


  • 芒果

  • 橙色

  • 葡萄

  • 葡萄

  • 葡萄

  • 苹果

  • 草莓

每当我进行导航用DownArrow中文,所述BlueHighlight暂停在第一葡萄,一个虚线矩形从第二葡萄开始,并在第三葡萄暂停,那么BlueHighlight从苹果恢复。这似乎不可思议,当导航是向上它变得更怪异。它从苹果跳转到橙色或芒果。

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?

推荐答案

有虚线框就是你的键盘焦点。蓝色的矩形是你的选择。

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.

要完成这项工作,你所期望的方式,你的包裹里面的ObservableCollection您的项目。因此,而不是:

To make this work the way you are expecting, wrap your items inside your ObservableCollection. So instead of:

coll.Add(fruit);

您会写

coll.Add(new FruitWrapper(fruit));

在你的的ListBox 你的的ItemTemplate 可以包括一个内容presenter 是presents水果的包装内(如<内容presenter CONTENT ={结合水果}/> )。

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

这篇关于WPF ListView的键盘导航问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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