JK82
JK82

Reputation: 435

Why does my WPF ListView/GridView not virtualize?

I have performance problem with my listview/gridview.

I traced it down to the view not being virtualized. I removed all business critical code and was left with the following XAML.

<UserControl  x:Class="Weingartner.Controls.PointListEditorView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300"
              x:Name="Root">

    <Grid>
        <ListView ItemsSource="{Binding ElementName=Root, Path=Points, Mode=OneWay}">
                <ListView.View>
                    <GridView  >
                         <GridViewColumn>
                            <GridViewColumn.CellTemplate>
                                <DataTemplate>
                                    <Label>Foo</Label>
                                </DataTemplate>
                            </GridViewColumn.CellTemplate>
                        </GridViewColumn>
                     </GridView>
                </ListView.View>

            </ListView>
    </Grid>
</UserControl >

When I look in the visual debugger I see this

debugger screen shot

The ListViewItem instances continue for the full list of the data, ie about 800 points.

When I open up any of the ListViewItem objects I see that they are fully populated as below

enter image description here

As far as I understand the docs say that virtualization is on by default for ListBox and ListView. Is this correct?

Any suggestions?

Edit: This is a screenshot of the full visual tree: enter image description here

Upvotes: 4

Views: 2408

Answers (1)

JK82
JK82

Reputation: 435

We are using MahApps.Metro and after setting the default ListView style to VirtualisedMetroListView virtualising works:

<Style BasedOn="{StaticResource VirtualisedMetroListView}" TargetType="ListView" />

Upvotes: 3

Related Questions