【问题标题】:Change image for pushpin WPF [closed]更改图钉 WPF 的图像 [关闭]
【发布时间】:2013-01-28 10:05:53
【问题描述】:

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

【问题讨论】:

  • 什么是 WPF 7?如果是 WPF,为什么要使用 Silverlight 标签?并且该图像也是图钉的Content 的一部分,如前所述。

标签: c# wpf bing-maps pushpin


【解决方案1】:

如果您不需要所有图钉功能,可以使用 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>

【讨论】:

  • 我使用 mapLayer 为我的代码添加了上述代码,但它没有在 Map 上显示任何图钉,有什么建议为什么它不起作用?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-12-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多