2

I have 2 pushpins, pin1 and pin2. How do I change the default black image to my own image? Please help. Thanks

User238
  • 31
  • 1
  • 4
  • What is WPF 7? And if it is WPF, why the Silverlight tag? And the image is also part of the Pushpin's `Content`, as answered before. – Clemens Jan 28 '13 at 10:14

1 Answers1

9

You could use a Image and add it to a MapLayer if you don't necesserily need all pushpin functionality.

Example:

MapLayer mapLayer = new MapLayer();
Image myPushPin = new Image();
myPushPin.Source = new BitmapImage(new Uri("YOUR IMAGE URL",UriKind.Relative));
myPushPin.Width = 32; 
myPushPin.Height = 32;
mapLayer.AddChild(myPushPin, <LOCATION_OF_PIN>, PositionOrigin.Center);
bingMap.Children.Add(mapLayer);

If you do need have certain Pushpin functionality, another option is to use the PushPin template:

Pushpin pushpin = new Pushpin();
pushpin.Template = Application.Current.Resources["PushPinTemplate"]  
    as (ControlTemplate);

Then in your application resources XAML , you can define the template like this:

<ControlTemplate x:Key="PushPinTemplate">
    <Grid>
        <Rectangle Width="32" Height="32">
            <Rectangle.Fill>
               <ImageBrush BitmapSource="YOUR IMAGE URL" /> 
            </Rectangle.Fill>
        </Rectangle>
    </Grid>
</ControlTemplate>
Leon Lucardie
  • 9,541
  • 4
  • 50
  • 70