本文介绍了WPF的ListView非常慢的性能 - 为何? (ElementHost的,还是其他原因?)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Windows窗体应用程序,具有含WPF用户控件的单个ElementHost的......在我的WPF,我有一个非常简单的ListView:

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>

如果我的源有10个项目,形式载荷不到一秒钟。如果我的源有1000个项目,它需要7秒!我的计时器只走的是加载到户口(不花费多少时间来获取项目)。

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).

所以我的问题是:

时使用ElementHost的业绩噩梦?

Is using an ElementHost a performance nightmare?

时的WPF数据绑定性能的噩梦?

Is WPF DataBinding a performance nightmare?

时的ListView的一块垃圾? (顺便说一句,与WPFToolkit的DataGrid中相同的结果)?

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

推荐答案

使用虚拟化

<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>

这篇关于WPF的ListView非常慢的性能 - 为何? (ElementHost的,还是其他原因?)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 23:08