Reputation: 467
I'm trying to display a map using an ItemControl
and an UniformGrid
. The map is an observable collection of Cells.
When the map is large the rendering time is very big and I'm struggling to lower it.
Here is the concerned code:
<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>
I've tried replacing the Button
with a Rectangle
, it does improve the situation but it still takes > 10sec to display a 400x300 map.
Any ideas on how to make the rendering fast?
Upvotes: 0
Views: 181