WPF ListView的性能非常慢——为什么?(ElementHost,或其他原因?)

时间:2021-12-10 09:39:44

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

我有一个Windows窗体应用程序,它有一个包含WPF用户控件的单一元素。在我的WPF中,我有一个非常简单的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).

如果我的源代码有10个条目,那么窗体将在不到一秒内加载。如果我的来源有1000个项目,它需要7秒!!我的计时器只考虑了加载(而不考虑获取项目所需的时间)。

So my question is:

我的问题是:

Is using an ElementHost a performance nightmare?

使用元素专家是一场表演噩梦吗?

Is WPF DataBinding a performance nightmare?

WPF数据库化是性能噩梦吗?

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

ListView是垃圾吗?(顺便说一句,WPFToolkit的DataGrid的结果也一样)?

2 个解决方案

#1


25  

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> 

#2


11  

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

WPF:由Paul McClean提供的数据虚拟化:http://www.codeproject.com/kb/wpf/wpfdatavirtualiz.aspx。

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

它向您展示了在最小内存和带宽使用上更好的方法。

#1


25  

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> 

#2


11  

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

WPF:由Paul McClean提供的数据虚拟化:http://www.codeproject.com/kb/wpf/wpfdatavirtualiz.aspx。

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

它向您展示了在最小内存和带宽使用上更好的方法。