【问题标题】:WPF Listbox: How to display selected items at the top of the listWPF Listbox:如何在列表顶部显示所选项目
【发布时间】:2014-01-19 16:42:00
【问题描述】:

例如,我在选中的 ListBox 中有 100 个项目,从 Item1 到 Item99。如果选择了 Item20、Item30 和 Item31,我希望将列表顶部的选定项目视为前 3 个项目,然后是其余项目。请帮助我如何实现这一目标?

谢谢 拉古

【问题讨论】:

标签: c# wpf listbox


【解决方案1】:

由于我认为如果在选择事物时位置发生变化,尝试选择多个项目可能会有点困难,因此我建议您在失去焦点时移动它们。

类似以下的算法应该可以工作:

listbox_LostFocus()
{
    if (there are any selected items after the first unselected item)
      move them to immediately prior the first unselected item
}

可以通过调用Items.Remove(item) 后跟Items.Insert(item, position) 来进行移动。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-05-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-27
    • 2013-07-17
    • 1970-01-01
    • 2016-03-22
    相关资源
    最近更新 更多