我在我的项目中使用 MVVM,并且我有以网格作为面板的 itemscontrol
<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 秒。任何想法如何使这更快?