I am creating a path of Markers to be displayed on a GMapControl in my C#/XAML (WPF) application. The control requires I create a UIElement to be overlaid on the map as a marker. I have created a very simple UserControl for this purpose, as follows:
<UserControl x:Class="Project.Resources.Circle"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid>
<Ellipse Width="5" Height="5" Stroke="Red" Fill="Red" />
</Grid>
</UserControl>
However, when I build the line, creating anything up to 400 instances of this control, my application freezes. Since I can only seem to create UserControl's on the UI thread (and not in a Thread or BackgroundWorker), what can I do to speed up the creation of new Circle instances?
Is there a more lightweight UIElement than a UserControl? Any guidance on this appreciated.
You could create a minimal derived UIElement like this:
public class Circle : UIElement
{
protected override void OnRender(DrawingContext drawingContext)
{
const double radius = 2.5;
drawingContext.DrawEllipse(Brushes.Red, null, new Point(), radius, radius);
}
}