Tag Archives: VirtualizingStackPanel

WPF ExpressionDark VirtualizingStackPanel issue

WPF Themes are a nice feature, if they have no errors. Unfortunaterly by using one of the WPF Template you run in issue if you want to display large data sets, because the ListBox, Combobox ect have some problems with virtualizing data. This problem only occurs on these Template, because e.g. of following code piece:

<Style TargetType="{x:Type ListBox}">
    <Setter Property="Template">
            <ControlTemplate TargetType="{x:Type ListBox}">
                    <Border x:Name="Border" BorderBrush="{TemplateBinding BorderBrush}"
                               BorderThickness="{TemplateBinding BorderThickness}"
                               Background="{DynamicResource ControlBackgroundBrush}" />
                    <ScrollViewer Margin="1" Style="{DynamicResource NuclearScrollViewer}"
                               Focusable="false" Background="{x:Null}">
                        <StackPanel Margin="1,1,1,1" IsItemsHost="true" />
                    <Trigger Property="IsEnabled" Value="false">
                        <Setter Property="Background" TargetName="Border"
                               Value="{DynamicResource DisabledBackgroundBrush}"  />
                        <Setter Property="BorderBrush" TargetName="Border"
                               Value="{DynamicResource DisabledBorderBrush}"  />
                    <Trigger Property="IsGrouping" Value="true">
                        <Setter Property="ScrollViewer.CanContentScroll" Value="false" />

If you replace the StackPanel in the highlighted line 13 with VirtualizingStackPanel the virtualization will work.
The only problem is if you deactivate the virtualizing by calling VirtualizingStackPanel.IsVirtualizing=”False”

Leave a comment

Posted by on September 28, 2010 in C-Sharp, WPF


Tags: ,