WPF UI Thread blocked with large collection

前端 未结 1 785
名媛妹妹
名媛妹妹 2021-01-15 22:18

I have a WPF application built using MVVM; one of the Views contains a collection of models that can be between 200-500 in length, each of the models are mapped to a Reposit

相关标签:
1条回答
  • 2021-01-15 22:59

    Look into adding virtualization to your ItemsControl. This way it only renders the items in view rather than all of them.

    <ItemsControl VirtualizingStackPanel.IsVirtualizing="True"
                  ScrollViewer.CanContentScroll="True">
        <ItemsControl.ItemsPanel>
            <ItemsPanelTemplate>
                <VirtualizingStackPanel />
            </ItemsPanelTemplate>
        </ItemsControl.ItemsPanel>
    </ItemsControl>
    

    I believe you'd also need to remove the ItemsControl from the StackPanel and ScrollViewer, as they'll give the ItemsControl infinite space to render, and render the virtualization useless.

    I see you're using a WrapPanel for your ItemsPanelTemplate, so you may need to roll your own virtualized panel, or check out some other controls (haven't used these myself).

    0 讨论(0)
提交回复
热议问题