Silverlight – Bing Map – Custom Pins Style

How to customize the style of pushpins on the Bing Maps Silverlight control? I checked the document shown here (http://www.microsoft.com/maps/isdk/silverlightbeta/#MapControlInteractiveSdk.Tutorials.TutorialCustomPushpin). However, I am adding a variable number of Pushpins programmatically. Ideally , I want to be able to set the style of each push, but I don’t know how.
You have two methods: < p>

(1) Create any UIElement to pass to PushPinLayer.AddChild. The AddChild method will accept any UIElement, such as the image in this example:

 MapLayer m_PushpinLayer = new MapLayer();
Your_Map.Children.Add(m_PushpinLayer);
Image image = new Image();
image.Source = ResourceFile.GetBitmap("Images/Me. png", From.This);
image.Width = 40;
image.Height = 40;
m_PushpinLayer.AddChild(image,
new Microsoft.Maps.MapControl.Location (42.658, -71.137),
PositionOrigin.Center);

(2) Create a native PushPin object to pass to PushpinLayer.AddChild, but first set its Template property. Please note, PushPin is ContentControls, and has Template attributes that can be set from resources defined in XAML:

MapLayer m_PushpinLayer = new MapLayer();
Your_Map.Children.Add( m_PushpinLayer);
Pushpin pushpin = new Pushpin();
pushpin.Template = Application.Current.Resources["PushPinTemplate"]
as (ControlTemplate);
m_PushpinLayer.AddChild(pushpin,
new Microsoft.Maps .MapControl.Location(42.658, -71.137),
PositionOrigin.Center);


xmlns="http://schemas.microsoft.com /client/2007"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

< Grid>



< /pre>

How to customize the style of the pushpin on the Bing Maps Silverlight control? I checked the document shown here (http://www.microsoft.com/maps/isdk/silverlightbeta/#MapControlInteractiveSdk.Tutorials.TutorialCustomPushpin). However, I am adding a variable number of Pushpins programmatically. Ideally , I want to be able to set the style of each push, but I don’t know how.

You have two methods:

(1) Create any UIElement to pass to PushPinLayer.AddChild. The AddChild method will accept any UIElement, such as the image in this example:

MapLayer m_PushpinLayer = new MapLayer();
Your_Map.Children.Add(m_PushpinLayer);
Image image = new Image();
image.Source = ResourceFile.GetBitmap("Images/Me.png", From.This);
image.Width = 40;
image.Height = 40;
m_PushpinLayer.AddChild(image,
new Microsoft.Maps.MapControl.Location(42.658, -71.137),
PositionOrigin .Center);

(2) Create a native PushPin object to pass to PushpinLayer.AddChild, but first set its Template property. Please note that PushPin is ContentControls, and has what can be defined from XAML Template attributes of resource settings:

MapLayer m_PushpinLayer = new MapLayer();
Your_Map.Children.Add(m_PushpinLayer);
Pushpin pushpin = new Pushpin ();
pushpin.Template = Application.Current .Resources["PushPinTemplate"]
as (ControlTemplate);
m_PushpinLayer.AddChild(pushpin,
new Microsoft.Maps.MapControl.Location(42.658, -71.137),
PositionOrigin .Center);


xmlns="http://schemas.microsoft.com/client/2007"
xmlns:x="http: //schemas.microsoft.com/winfx/2006/xaml">





Leave a Comment

Your email address will not be published.