[英]WPF Listbox: How to display selected items at the top of the list
舉例來說,我在選中的ListBox中有100個項目,從Item1到Item99。 如果選擇了Item20,Item30和Item31,我希望將選中的項目作為前3個項目顯示在列表頂部,然后是其余項目。 請幫我如何實現這一目標?
謝謝拉古
由於我想如果選擇時位置發生變化,嘗試選擇多個項目可能會有些困難,所以建議您在失去焦點時移動它們。
類似於以下內容的算法應該起作用:
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)
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.