Search code examples
wpfxamlbing-mapspushpin

XAML Create ControlTemplate for Map PushPin


I am trying to customize the template for a map pushpin. Not windows 8 mobile, this is just a WPF map control. I can't get XAML to recognize the TargetType. I have to specify the TargetType so I can modify certain elements not found in a generic Control. I've tried several variations. The code exists in a XAML file separate from the WPF UserControl (gets referenced in the MergedDictionaries). Code below:

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:m="clr-namespace:Microsoft.Maps.MapControl.WPF;assembly=Microsoft.Maps.MapControl.WPF">

    <ControlTemplate x:Key="PushPinTemplate" TargetType="m:PushPin" >
        <Grid x:Name="ContentGrid">
            <StackPanel Orientation="Vertical">
                <Grid Background="{TemplateBinding Background}"
                                                HorizontalAlignment="Left"
                                                MinHeight="31"
                                                MinWidth="29">
                    <ContentPresenter HorizontalAlignment="Center"
                                               Content="{TemplateBinding Content}"
                                               ContentTemplate="{TemplateBinding ContentTemplate}"
                                               Margin="4"/>
                </Grid>
                <Polygon Fill="{TemplateBinding Background}"
                                                             Points="0,0 29,0 0,29"
                                                             Width="29"
                                                             Height="29"
                                                             HorizontalAlignment="Left"/>
            </StackPanel>
        </Grid>
    </ControlTemplate>
</ResourceDictionary>

Setting PushPin.Template in C#

pushpin.Template = (ControlTemplate)(Resources["PushPinTemplate"]);

Solution

  • The type name is not written correctly. It is Pushpin, not PushPin:

    <ControlTemplate ... TargetType="m:Pushpin">