更改图钉 WPF 的图像
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14559630/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Change image for pushpin WPF
提问by User238
I have 2 pushpins, pin1 and pin2. How do I change the default black image to my own image? Please help. Thanks
我有 2 个图钉,pin1 和 pin2。如何将默认的黑色图像更改为我自己的图像?请帮忙。谢谢
回答by Leon Lucardie
You could use a Imageand add it to a MapLayerif you don't necesserily need all pushpin functionality.
如果您不需要所有图钉功能,您可以使用 aImage并将其添加到 a 中MapLayer。
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 模板:
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:
然后在您的应用程序资源 XAML 中,您可以像这样定义模板:
<ControlTemplate x:Key="PushPinTemplate">
<Grid>
<Rectangle Width="32" Height="32">
<Rectangle.Fill>
<ImageBrush BitmapSource="YOUR IMAGE URL" />
</Rectangle.Fill>
</Rectangle>
</Grid>
</ControlTemplate>

