每个人都说 ListBox 的默认 ItemsPanel 是 VirtualizingStackPanel。我创建了一个 ListBox 派生类(称为 MyListBox),它默认为 StackPanel。
我的意思是我必须强制虚拟化,例如这样:
const string itemsPanelTemplateString = @"
<ItemsPanelTemplate
xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation""
xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"" >
<VirtualizingStackPanel/>
</ItemsPanelTemplate>";
MyListBox {
this.ItemsPanel = (ItemsPanelTemplate)
System.Windows.Markup.XamlReader.Load(itemsPanelTemplateString);
}
我可以在这里重印我的课程,但这不是重点。我想知道一般答案。
该类不会更改预定义的 ListBox 样式,但它使用自己的 ListBoxItem 派生类。
我很确定使用虚拟化有一些条件,因为我的同事说他过去看到过相应的 ListBox 代码。不幸的是,现在我们无法访问 MS dll 的调试版本。