I've figured out a way to do this. I created a class which inherits from MarkerSymbol
which has a DependencyProperty
which holds the object I want to bind to (the Pogostick class).
public class EntityMarkerSymbol : MarkerSymbol
{
public static readonly DependencyProperty EntityProperty;
static EntityMarkerSymbol()
{
EntityMarkerSymbol.EntityProperty = DependencyProperty.Register("Entity", typeof(object), typeof(EntityMarkerSymbol), new PropertyMetadata());
return;
}
public EntityMarkerSymbol()
{
return;
}
public object Entity
{
get { return this.GetValue(EntityMarkerSymbol.EntityProperty); }
set { this.SetValue(EntityMarkerSymbol.EntityProperty, value); }
}
}
Then I create a ControlTemplate
in a resource dictionary like so:
<ControlTemplate x:Key="PogostickMarker">
<StackPanel>
<Image Source="{Binding Symbol.Entity.HeightImage}" />
<TextBlock Text="{Binding Symbol.Entity.PogostickId}" />
</StackPanel>
</ControlTemplate>
The key to this working is that ArcGIS for WPF will automatically assign the MarkerSymbol
's DataContext
to it's sealed class DataBinding
which contains a reference to the MarkerSymbol
assigned to the GpsLayer
's LocationMarkerSymbol
. So I can access my custom symbols Entity
property through this binding.
The code used to create the GpsLayer and assign the MarkerSymbol
is below:
GpsLayer layer = new GpsLayer();
EntityMarkerSymbol marker = new EntityMarkerSymbol() { Entity = pogoStick };
marker.ControlTemplate = Application.Current.Resources["ConvoyMarker"] as ControlTemplate;
layer.LocationMarkerSymbol = marker;
NOTE: this approach cannot be used when the UseAcceleratedDisplay
property of the map is set to True
. If someone can figure out how to use this approach with that property set to true, please let me know.