Timothy Khouri
Timothy Khouri

Reputation: 31845

WPF ListView Very Slow Performance - Why? (ElementHost, or Other Reason?)

I have a Windows Forms app, that has a single ElementHost containing a WPF UserControl... in my WPF, I have a VERY simple ListView:

<ListView Margin="4" ItemsSource="{Binding Notifications}">
    <ListView.View>
        <GridView>
            <GridViewColumn Header="FirstName" DisplayMemberBinding="{Binding FirstName}" />
            <GridViewColumn Header="LastName" DisplayMemberBinding="{Binding LastName}" />
            <GridViewColumn Header="Address" DisplayMemberBinding="{Binding Address}" />
            <GridViewColumn Header="City" DisplayMemberBinding="{Binding City}" />
            <GridViewColumn Header="State" DisplayMemberBinding="{Binding State}" />
            <GridViewColumn Header="Zip" DisplayMemberBinding="{Binding Zip}" />
        </GridView>
    </ListView.View>
</ListView>

If my source has 10 items, the form loads in less than one second. If my source has 1000 items, it takes 7 seconds!!! My timer is ONLY taking the loading into account (not how much time it takes to get the items).

So my question is:

Is using an ElementHost a performance nightmare?

Is WPF DataBinding a performance nightmare?

Is the ListView a piece of crap? (btw, same results with the WPFToolkit's DataGrid)?

Upvotes: 29

Views: 31188

Answers (4)

Indy Singh
Indy Singh

Reputation: 37

I had the same problem. Replacing the listview with DataGrid containing DataGridTextColumn items fixed the problem.

<DataGrid Margin="4" ItemsSource="{Binding Notifications}">
    <DataGrid.Columns>
    <DataGridTextColumn Header="FirstName" DisplayMemberBinding="{Binding FirstName}" />
    <DataGridTextColumn Header="LastName" DisplayMemberBinding="{Binding LastName}" />
</DataGrid.Columns>

Upvotes: 0

Simon Voggeneder
Simon Voggeneder

Reputation: 387

I had a case where the answers presented here didn't solve my problem. In my case, setting the MaxHeight property of the ListView to a value larger than the actual displayed height solved it immediately, thanks to this answer here, even if I cannot explain how and why it worked.

Upvotes: 6

Tawani
Tawani

Reputation: 11198

You may also want to check this excellent article on the Code Project:

WPF: Data Virtualization By Paul McClean http://www.codeproject.com/KB/WPF/WpfDataVirtualization.aspx

It show you a much better approach at minimal memory and bandwidth usage.

Upvotes: 12

loic
loic

Reputation:

Use virtualization

<ListView ItemsSource="{BindingNames}"Name="lv">
            <ListView.ItemsPanel>
                <ItemsPanelTemplate>
                   <!--<StackPanel/>
                    If StackPanel was used, the memory consumed was over 2GB and dead slow.
                    -->
                   <VirtualizingStackPanel>
                    <!--Memory footprint is only 200 mb-->
                    </VirtualizingStackPanel>
                </ItemsPanelTemplate>
            </ListView.ItemsPanel>
            <ListView.ItemTemplate>
                <DataTemplate>
                    <TextBlock Text="{Binding}"/>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView> 

Upvotes: 35

Related Questions