2017-02-22 111 views
0

我一直在研究互联网上的各种方法来更改Bing Maps C#控件中的图钉图像。C#中的Bing地图 - 变化图钉图片

Change image for pushpin WPF

这并不完全是我要找的,因为我希望能够改变推针的颜色,以及添加一个:我用的是下面的解决方案来最接近标签。

上述解决方案基本上是通过推针绘制的图像,不需要额外的功能,如添加标签。我希望能够在定制标签功能的同时轻松更改图像。

有没有其他方式做到这一点?另一种方法是使用“标准”Bing推针图形并能够改变尺寸。但是看来这个功能是不是在C#控制

+0

[为图钉WPF更改图片]的可能的复制(http://stackoverflow.com/questions/14559630/change-image-for-pushpin-wpf) –

+0

显示你已经尝试过,并争辩为什么这个其他的解决方案不适合你。如果包含[mcve],则总是可取的。现在,这个问题是重复的,可能会被关闭。 –

+0

https://openlayers.org/对于抽象层和许多示例总是很好,你想要做什么 – lordkain

回答

0

令人惊讶的,这是关于这个主题的SOF唯一的问题(在other one关闭)。要在WPF中完成新手(和我一样)很难找到好的并且同时有简单的信息,所以我将展示如何在VB.NET中以编程方式添加图钉时使用自定义图像:

这是我的MainWindow.xaml文件:

<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> 

正如你所看到的,你必须定义一个ControlTemplateTargetType="m:Pushpin" 在那里,你可以画任何你所需要的。最简单的方法是:使用资源中的图片。

重要:改变形象“建设行动” 资源(在资源解决方案管理器的文件夹,点击图片,并改变它在高级设置)。否则,你将不得不hardwrite图像路径或使用URI或more complicated stuff

现在,您可以创建一个图钉你需要的地方,并指定你的模板:

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 
相关问题