我有2个图钉,pin1和pin2。 如何将默认黑色图像更改为我自己的图像? 请帮忙。感谢
答案 0 :(得分:8)
如果您不需要所有图钉功能,可以使用Image
并将其添加到MapLayer
。
示例:
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);
如果确实需要某些Pushpin功能,另一个选择是使用PushPin模板:
Pushpin pushpin = new Pushpin();
pushpin.Template = Application.Current.Resources["PushPinTemplate"]
as (ControlTemplate);
然后在您的应用程序资源XAML中,您可以像这样定义模板:
<ControlTemplate x:Key="PushPinTemplate">
<Grid>
<Rectangle Width="32" Height="32">
<Rectangle.Fill>
<ImageBrush BitmapSource="YOUR IMAGE URL" />
</Rectangle.Fill>
</Rectangle>
</Grid>
</ControlTemplate>