WPF:列表框,将所选项目居中 [英] WPF: Listbox, centering selected item

查看:108
本文介绍了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在他的博客上发布了一些文章,可能会对您有所帮助:第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屋!

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