3

I use MVVM in my project and i have itemscontrol with grid as panel

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

And items templates are buttons with custom styles.

I am trying to display only like 20 items in grid but i have performance issues when items are added to my view model!

currentPage.Items = observable; 

It takes someting like 2 seconds to display those items. Any ideas how to make this faster?

Ievgen
  • 4,261
  • 7
  • 75
  • 124
  • 3
    have your `ItemTemplate` worry about layout's within an Item and let the `ItemsPanel` stay as a `VirtualizingStackPanel` so WPF can optimize stuff for you? – Viv Jul 30 '13 at 13:23
  • 1
    Agree with @Viv, otherwise you'll have to implement your own `VirtualizingGrid`, I guess, an endeavor which of course is far from trivial. – Federico Berasategui Jul 30 '13 at 14:01
  • 1
    extending observalbe collection to minimize it firing collection changed can help, there're lots of examples here. I wrote one too here on stackoverflow, it's not coming up in search, but this link shows other people doing it as well: http://stackoverflow.com/questions/13302933/how-to-avoid-firing-observablecollection-collectionchanged-multiple-times-when-r – denis morozov Jul 30 '13 at 17:10

0 Answers0