GMap.NET C#WFP:我可以将自定义用户控件添加到GMapControl覆盖中吗?

GMap.NET C#WFP:我可以将自定义用户控件添加到GMapControl覆盖中吗?,c#,wpf,xaml,user-controls,gmap.net,C#,Wpf,Xaml,User Controls,Gmap.net,项目:c#,wpf,.net4.0,Gmap.Net.Presentation 1.7.1 我所拥有的: 我的自定义MapControl类继承自GMap.NET.WindowsPresentation.GMapControl类 public sealed class MapControl : GMapControl { /* Some special data. */ public MapConrol() : base() { /* So

项目:c#,wpf,.net4.0,Gmap.Net.Presentation 1.7.1

我所拥有的:

我的自定义MapControl类继承自GMap.NET.WindowsPresentation.GMapControl类

public sealed class MapControl : GMapControl
{
    /* Some special data. */

    public MapConrol()
        : base()
    {
        /* Some init actions. */
    }

    /* Overrided and additional methods. */
}
例如,我有一些自定义的UserControl类

public sealed class MapControl : GMapControl
{
    /* Some special data. */

    public MapConrol()
        : base()
    {
        /* Some init actions. */
    }

    /* Overrided and additional methods. */
}
代码:

Xaml:

在我的诗中,我没有这首诗。我已经存在内置的标记覆盖到GMap类

gmap.Markers-可观察到的GMapMarkers集合。

而且没有办法创建我自己的覆盖并将其添加到GMapControl对象

更新0:

我脑子里的第一个想法。例如,只需在地图上添加带有地图对象id的特殊标记的GMapMarkers。GMapControl的OnRender()找到屏幕上的所有标记,解析它们的ID并在我的wpf用户控件上方绘制。但我希望在GMapControl中有一些内部机制可以做到这一点


我相信解决方案比您尝试的更简单,您可以从
GMapMarker
中获得,例如:

class CustomMarker: GMapMarker
{
    public string Description { get; set; }

    public CustomMarker(PointLatLng pos, string description)
            : base(pos)
    {
        Description = description;
        Shape = new CustomMarkerElement();

        ((CustomMarkerElement)Shape).lblDesc.Content = description;            
    }
}
此标记实例允许您访问自己的
customermarkerement
(项目中的
UserControl
)中的UI属性:



缺点是,恐怕没有办法以符合MVVM的方式实现这一点(例如,在项目模板中定义自定义标记)。

我相信解决方案比您尝试的更简单,您可以从
GMapMarker
中获得,例如:

class CustomMarker: GMapMarker
{
    public string Description { get; set; }

    public CustomMarker(PointLatLng pos, string description)
            : base(pos)
    {
        Description = description;
        Shape = new CustomMarkerElement();

        ((CustomMarkerElement)Shape).lblDesc.Content = description;            
    }
}
此标记实例允许您访问自己的
customermarkerement
(项目中的
UserControl
)中的UI属性:



缺点是,afaik无法以符合MVVM的方式实现这一点(例如,在项目模板中定义自定义标记)。

我不知道GMap,但我的感觉是,应该很容易将任何UIElement派生的控件添加到映射中,并通过某种附加属性指定其位置。如果不可能,您应该尝试其他控件,例如Bing Maps或XAML Map控件。他们有一个带有ItemTemplate(或ItemContainerStyle)的MapItemsControl,您可以在其中放置任何UIElement。这将是MVVM。谢谢你的建议。现在我试图在GMap中找到MapItemsControl的类似项。如果不存在,我将找不到其他解决方案-更改我的地图控件。我不知道GMap,但我的感觉是,应该很容易将任何UIElement派生控件添加到地图,并通过某种附加属性指定其位置。如果不可能,您应该尝试其他控件,例如Bing Maps或XAML Map控件。他们有一个带有ItemTemplate(或ItemContainerStyle)的MapItemsControl,您可以在其中放置任何UIElement。这将是MVVM。谢谢你的建议。现在我试图在GMap中找到MapItemsControl的类似项。如果不存在,我将找不到其他解决方案-将更改我的地图控制。非常感谢。这是正确的答案。我只是创建了我自己的CustomMarker并改变了里面的形状。非常感谢。这是正确的答案。我只是创建自己的CustomMarker并更改其中的形状。
class CustomMarker: GMapMarker
{
    public string Description { get; set; }

    public CustomMarker(PointLatLng pos, string description)
            : base(pos)
    {
        Description = description;
        Shape = new CustomMarkerElement();

        ((CustomMarkerElement)Shape).lblDesc.Content = description;            
    }
}
<UserControl x:Class="WpfApplication3.CustomMarkerElement"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300">
    <Grid>
        <Ellipse 
            Fill="DarkKhaki"
            Height="40"
            HorizontalAlignment="Left"
            VerticalAlignment="Top"
            Width="40" />

        <Label 
            x:Name="lblDesc"
            Content="TST" 
            Foreground="White" 
            FontWeight="Bold" 
            HorizontalAlignment="Left" 
            HorizontalContentAlignment="Center" 
            Margin="0,6"
            VerticalAlignment="Top"
            Width="40"/>

    </Grid>
</UserControl>