3
我需要绘制许多矩形(〜50000)。目前我正在使用以下方法。在WPF中绘制数千个矩形
<ItemsControl ItemsSource="{Binding Elements}" IsHitTestVisible="False" Background="Transparent">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<Canvas IsItemsHost="True"
Background="Transparent"
Width="500"
Height="500">
</Canvas>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemContainerStyle>
<Style TargetType="ContentPresenter">
<Setter Property="Canvas.Left" Value="{Binding X}"/>
<Setter Property="Canvas.Bottom" Value="{Binding Y}"/>
</Style>
</ItemsControl.ItemContainerStyle>
<ItemsControl.ItemTemplate>
<DataTemplate DataType="{x:Type models:Element}">
<Rectangle Width = "{Binding Width}"
Height = "{Binding Height}"
Fill= "{Binding Brush}"
SnapsToDevicePixels="True" >
</Rectangle>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
问题是需要很长时间来绘制这个数量的矩形。 有没有更好的方法来绘制大量的形状?
我会摆脱绑定和手动的将矩形放入画布中 – thumbmunkeys