ItemsControl的WPF性能问题

时间:2013-07-30 12:29:05

标签: c# wpf performance wpf-controls

我在我的项目中使用MVVM,并且我将itemscontrol与grid作为面板

<ItemsControl
                ItemsSource="{Binding Items}"
                ItemTemplateSelector="{StaticResource TemplateSelector}">
                <ItemsControl.ItemContainerStyle>
                    <Style>
                        <Setter
                            Property="Grid.Row"
                            Value="{Binding Row}" />
                        <Setter
                            Property="Grid.Column"
                            Value="{Binding Column}" />
                        <Setter
                            Property="Grid.ColumnSpan"
                            Value="{Binding HorizontalSize}" />
                        <Setter
                            Property="Grid.RowSpan"
                            Value="{Binding VerticalSize}" />
                    </Style>
                </ItemsControl.ItemContainerStyle>
                <ItemsControl.ItemsPanel>
                    <ItemsPanelTemplate>
                        <Grid
                            ShowGridLines="False"
                            wpflib:GridHelpers.ColumnCount="{Binding Columns, Mode=OneWay}"
                            wpflib:GridHelpers.RowCount="{Binding Rows, Mode=OneWay}"
                            wpflib:GridHelpers.AutoRows="{Binding AutoRowsFormatted, Mode=OneWay}"
                            wpflib:GridHelpers.AutoColumns="{Binding AutoColumnsFormatted, Mode=OneWay}" />
                    </ItemsPanelTemplate>
                </ItemsControl.ItemsPanel>
            </ItemsControl>

项目模板是具有自定义样式的按钮。

我试图在网格中只显示20个项目,但是当项目添加到我的视图模型时,我会遇到性能问题!

currentPage.Items = observable; 

显示这些项目需要2秒钟。任何想法如何使这更快?

0 个答案:

没有答案