0

I've been researching all over the internet for a way to change the pushpin image in the Bing Maps C# control. The closest that I came was using the following solution:

Change image for pushpin WPF

It is not entirely what I'm looking for, as I want to be able to change the color of the push pin as well as add a label.

The above solution is basically an image that is drawn over a push pin without additional functionality such as adding a label. I want to be able to easily change an image while having custom label functionality.

Is there any other way of doing this? An alternative would be to make use of "standard" Bing push pin graphics and be able to change the size. However it seems this functionality is not available in the C# control

Community
  • 1
  • 1
ceds
  • 2,097
  • 5
  • 32
  • 50
  • Possible duplicate of [Change image for pushpin WPF](http://stackoverflow.com/questions/14559630/change-image-for-pushpin-wpf) – Manfred Radlwimmer Feb 22 '17 at 12:52
  • Show what you have tried and argue why this other solution didn't work for you. It is always preferable if you include a [mcve]. As it is now, this question is a duplicate and might be closed. – Manfred Radlwimmer Feb 22 '17 at 12:53
  • https://openlayers.org/ is always nice to for abstraction layer and many examples what you want to do – lordkain Feb 22 '17 at 12:54
  • As explained in my question, I've used the code as illustrated in the solution that I referenced. It is not what I'm looking for. I have explained this as well – ceds Feb 22 '17 at 13:02

2 Answers2

0

This following blog post answers my questions: http://dennis.bloggingabout.net/2012/10/17/bing-maps-on-wpf-and-custom-pushpin-tutorial-for-pixelsense/

ceds
  • 2,097
  • 5
  • 32
  • 50
0

Surprisingly this is the only question about this topic in SOF (the other one is closed). To complete newbies in WPF (like me) it is hard to find good and at the same time simple information, so I will show how I managed to use custom images in programatically added pushpins in VB.NET:

This is my MainWindow.xaml file:

<Window x:Class="MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:m="clr-namespace:Microsoft.Maps.MapControl.WPF;assembly=Microsoft.Maps.MapControl.WPF"
        xmlns:local="clr-namespace:MyBingMapsApp"
        mc:Ignorable="d"
        Title="MainWindow" Height="350" Width="525">
    <Window.Resources>
        <ControlTemplate x:Key="PushpinControlTemplate" TargetType="m:Pushpin">
            <Grid>
                <Rectangle Width="24" Height="24">
                    <Rectangle.Fill>
                        <ImageBrush ImageSource= "Resources/marker_green.png"/>
                    </Rectangle.Fill>
                </Rectangle>
            </Grid>
        </ControlTemplate>
    </Window.Resources>
    <Grid>
        <m:Map x:Name="myMap" 
               CredentialsProvider= "xxxxxx mycredentialskey xxxxxxxx" 
               Center="42.13618,-0.40822" 
               ZoomLevel="15">
        </m:Map>
    </Grid>
</Window>

As you can see, you must define a ControlTemplate whose TargetType="m:Pushpin" There you can draw whatever you need. The simplest: use an image from your resources.

Important: change image "Build action" to Resource (click on the image in your resources folder of the Solution Explorer and change it in Advanced settings). Otherwise you will have to hardwrite the image path or use Uris or more complicated stuff

Now you are ready to create a pushpin wherever you need and assign your template:

mypin = New Pushpin
mypin.Location = New Location(mylat, mylon)
mypin.ToolTip = "This is a pushpin with custom image"

Dim mytemplate As System.Windows.Controls.ControlTemplate = FindResource(“PushpinControlTemplate”) 'here of course you must put the key name of your template
mypin.Template = mytemplate 
Carlos Borau
  • 1,433
  • 1
  • 24
  • 34