【发布时间】:2013-01-28 10:05:53
【问题描述】:
我有 2 个图钉,pin1 和 pin2。 如何将默认的黑色图像更改为我自己的图像? 请帮忙。谢谢
【问题讨论】:
-
什么是 WPF 7?如果是 WPF,为什么要使用 Silverlight 标签?并且该图像也是图钉的
Content的一部分,如前所述。
我有 2 个图钉,pin1 和 pin2。 如何将默认的黑色图像更改为我自己的图像? 请帮忙。谢谢
【问题讨论】:
Content 的一部分,如前所述。
如果您不需要所有图钉功能,可以使用 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>
【讨论】: