WPF:列表框,使所选项目居中 [英] WPF: Listbox, centering selected item
本文介绍了WPF:列表框,使所选项目居中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以始终将所选项目保留在列表框的中间?如果用户选择了一个项目,我想滚动以使新选择的项目位于中间.
Is it possible to always keep selected item in the middle of a listbox? If the user selects an item, I want to scroll so that the newly selected item is in the middle.
我想边缘情况"(前几项和最后几项)是可能的,但没关系.
I guess it want be possible for the 'edge cases' (the first and last few items), but that's ok.
推荐答案
David Anson 在他的博客上发布了一些可能对您有所帮助的文章:第 1 部分 和第 2 部分.他给出了一个扩展方法,可以将一个项目集中在一个列表框中.您或许可以在此基础上再接再厉.
David Anson posted some articles on his blog that might help you here: Part 1 and Part 2. He gives an extension method that centers an item in an List Box. You might be able to build on that.
这篇关于WPF:列表框,使所选项目居中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文