I read that when styling incorrectly, ListBox
will lose its virtualization. As notacat's answer in this question, his solution is OK.
I realize that whenever I put ItemsPresenter in another container, such as Grid
, Border
, ...
<ControlTemplate TargetType="ListBox">
<ScrollViewer x:Name="ScrollViewer"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
Background="{TemplateBinding Background}"
Foreground="{TemplateBinding Foreground}"
Padding="{TemplateBinding Padding}">
<StackPanel>
<TextBlock Text="{TemplateBinding MyText}" />
<ItemsPresenter/>
</StackPanel>
</ScrollViewer>
</ControlTemplate>
ListBox
will lose its virtualization right away. But I do want to place a TextBlock
before ItemsPresenter
, and ScrollViewer only accepts 1 child element.
How to deal with this ?
UPDATE:
I see this post, which Derek Lakin does is to place that TextBlock
to the ScrollViewer
template, but how can place that TextBlock
in ScrollContentPresenter
?
P/S: I do set VirtualizingStackPanel
as ItemsPanel
for my ListBox
.