更改图钉WPF的图像

我有2个图钉,pin1和pin2。 如何将默认黑色图像更改为我自己的图像? 请帮忙。 谢谢

如果您不需要所有图钉function,可以使用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, , PositionOrigin.Center); bingMap.Children.Add(mapLayer); 

如果您确实需要某些Pushpinfunction,另一个选项是使用PushPin模板:

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

然后在您的应用程序资源XAML中,您可以像这样定义模板: