我正在尝试使用 anItemControl
和 an显示地图UniformGrid
。该地图是一个可观察的细胞集合。当地图很大时,渲染时间非常长,我正在努力降低它。
这是相关的代码:
<ItemsControl Grid.Row="1" ItemsSource="{Binding Cells}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<!-- Do not use binding because it's slow -->
<!-- Command="{Binding Path=DataContext.CellClickedCommand, RelativeSource={RelativeSource AncestorType=ItemsControl}}" -->
<!-- CommandParameter="{Binding}" -->
<Button Name="Button" Style="{StaticResource CellButtonStyle}" Tag="{Binding}"
Click="Cell_OnClick"
MouseEnter="Cell_OnMouseEnter"
MouseRightButtonUp="Cell_OnMouseRightButtonUp" />
<DataTemplate.Triggers>
<DataTrigger Binding="{Binding IsIncluded}" Value="True">
<Setter TargetName="Button" Property="Background" Value="White" />
</DataTrigger>
<DataTrigger Binding="{Binding IsIncluded}" Value="False">
<Setter TargetName="Button" Property="Background" Value="Black" />
</DataTrigger>
<DataTrigger Binding="{Binding IsCurrentPlayerLocation}" Value="True">
<Setter TargetName="Button" Property="Foreground" Value="Green" />
<Setter TargetName="Button" Property="Content" Value="X" />
<Setter TargetName="Button" Property="BorderBrush" Value="Red" />
<Setter TargetName="Button" Property="BorderThickness" Value="5" />
</DataTrigger>
<DataTrigger Binding="{Binding IsCurrentPlayerLocation}" Value="False">
<Setter TargetName="Button" Property="Foreground" Value="Transparent" />
<Setter TargetName="Button" Property="Content" Value="" />
<Setter TargetName="Button" Property="BorderBrush" Value="DarkGray" />
<Setter TargetName="Button" Property="BorderThickness" Value="1" />
</DataTrigger>
</DataTemplate.Triggers>
</DataTemplate>
</ItemsControl.ItemTemplate>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<UniformGrid HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
Columns="{Binding Header.ColumnCount, UpdateSourceTrigger=PropertyChanged}"
Rows="{Binding Header.RowCount, UpdateSourceTrigger=PropertyChanged}" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
我尝试用 替换Button
,Rectangle
它确实改善了这种情况,但显示 400x300 地图仍然需要 > 10 秒。
关于如何使渲染快速的任何想法?