public class MyTextSymbol : MarkerSymbol { public double Scale { get { return (double)GetValue(ScaleProperty); } set { SetValue(ScaleProperty, value); } } public static readonly DependencyProperty ScaleProperty = DependencyProperty.Register("Scale", typeof(double), typeof(MyTextSymbol), new PropertyMetadata(1.0)); }
<local:MyTextSymbol x:Key="myTextSymbol"> <local:MyTextSymbol.ControlTemplate> <ControlTemplate> <TextBlock Text="MyText" FontFamily="Arial" FontSize="10" Foreground="Red" FontStyle="Italic" FontWeight="Bold"> <TextBlock.RenderTransform> <ScaleTransform ScaleX="{Binding Symbol.Scale}" ScaleY="{Binding Symbol.Scale}" /> </TextBlock.RenderTransform> </TextBlock> </ControlTemplate> </local:MyTextSymbol.ControlTemplate> </local:MyTextSymbol>
The only drawback of this method is that the text is re-scaled only when the MapExtend has changed, unlike the other geometries (polygons, lines, etc.) that change gradually as the MapExtend is changing.
You can fix that by hooking up the same handler to the map event 'ExtentChanging'.
Another way to do it is to use a Polygon instead and use an ImageFill that stretches with the polygon (the image contains the text). That way you won't have to do anything to make it scale.