I’m trying to apply a style to a MapPolyline from the bing maps silverlight classes.
I have this style defined:
<Style x:Key="routeStyle" TargetType="map:MapPolyline">
<Setter Property="Stroke">
<Setter.Value>
<SolidColorBrush Color="Magenta" />
</Setter.Value>
</Setter>
<Setter Property="StrokeThickness" Value="10" />
</Style>
And I get this error when it runs:
The property ‘Stroke’ was not found in type ‘Microsoft.Maps.MapControl.MapPolyline’.
Which is in contradiction to this:
http://msdn.microsoft.com/en-us/library/microsoft.maps.mapcontrol.mappolyline_members.aspx
I wondered if maybe it was struggling to find the property because it’s declared in the base class. So I tried this:
<Style x:Key="routeStyle" TargetType="mapCore:MapShapeBase">
<Setter Property="Stroke">
<Setter.Value>
<SolidColorBrush Color="Magenta" />
</Setter.Value>
</Setter>
<Setter Property="StrokeThickness" Value="10" />
</Style>
But still got:
The property ‘Stroke’ was not found in type ‘Microsoft.Maps.MapControl.Core.MapShapeBase’.
Am I missing something obvious?
The Stroke and StrokeThickness are not backed by DependencyProperties defined for that class. Internally they are using the Stroke(Thickness)Property fields of the Shape class. One option would be to define your own attached DependencyProperty for each and within the PropertyChangeCallback you could use the associated Shape class’s DP to set the value on the object. This would have the downside of being a local value (rather than a style value) but it should work for basic scenarios. e.g.