更改图钉WPF的图像 [英] Change image for pushpin WPF

查看:94
本文介绍了更改图钉WPF的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have 2 pushpins, pin1 and pin2. How do I change the default black image to my own image? Please help. Thanks

推荐答案

如果不需要所有图钉功能,则可以使用Image并将其添加到MapLayer中.

You could use a Image and add it to a MapLayer if you don't necesserily need all pushpin functionality.

示例:

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模板:

If you do need have certain Pushpin functionality, another option is to use the PushPin template:

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

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

Then in your application resources XAML , you can define the template like this:

<ControlTemplate x:Key="PushPinTemplate">
    <Grid>
        <Rectangle Width="32" Height="32">
            <Rectangle.Fill>
               <ImageBrush BitmapSource="YOUR IMAGE URL" /> 
            </Rectangle.Fill>
        </Rectangle>
    </Grid>
</ControlTemplate>

这篇关于更改图钉WPF的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆