RSS

WPF ExpressionDark VirtualizingStackPanel issue

28 Sep

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

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”

Advertisements
 
Leave a comment

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

 

Tags: ,

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: