Change image for pushpin WPF [closed]

断了今生、忘了曾经 提交于 2019-12-02 06:26:17

问题


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


回答1:


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

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 = new Pushpin();
pushpin.Template = Application.Current.Resources["PushPinTemplate"]  
    as (ControlTemplate);

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>


来源:https://stackoverflow.com/questions/14559630/change-image-for-pushpin-wpf

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!