我有一个Windows Forms应用程序,其中有一个包含WPF UserControl的ElementHost ...在我的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>

如果我的货源中有10件商品,则表单加载时间不到一秒钟。如果我的货源有1000件商品,则需要7秒钟!!!我的计时器仅考虑装载(而不是花费多少时间来获取物品)。

所以我的问题是:

使用ElementHost会成为性能梦night吗?

WPF DataBinding是一场性能梦night吗?

ListView是一件废话吗? (顺便说一句,与WPFToolkit的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>

08-05 17:22