向MapControl添加pin时无法隐式转换类型



我试图动态地向MapControl添加一个pin,但尽管使用了import语句(using(,它还是无法工作。NormalizedAnchorPoint = new Point(0.5, 1)中的new Point(0.5, 1)返回以下错误。解决这个问题的正确方法是什么?

无法将类型"Windows.Foundation.Point"隐式转换为"System.Drawing.Point">

主页.xaml.cs

using System;
using System.Collections.Generic;
using TownTraveller.Data;
using TownTraveller.UserControls;
using Windows.Devices.Geolocation;
using Windows.Foundation;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
public MainPage()
{
this.InitializeComponent();
var mapPage = new MapPage();
var pinUri = new Uri("ms-appx:///Images/MapPin.png");
var myMapControl = pageMap.MyMapControl;
var mapCenter =
new Geopoint(new BasicGeoposition()
{
Latitude = 51053881,
Longitude = -0.100239
});
myMapControl.Center = mapCenter;
myMapControl.ZoomLevel = 10;
var MapPoints = new List<PointOfInterest>();
var mapPin1 = new PointOfInterest
{
PinName = "Pin1",
DisplayName = "Place One",
ImageSourceUri = pinUri,
),
Location = new Geopoint(new BasicGeoposition()
{
Latitude = 51.486223,
Longitude = -0.124474
})
};
MapPoints.Add(mapPin1);
}
}

"兴趣点"类

public class PointOfInterest
{
public string PinName { get; set; }
public string DisplayName { get; set; }
public Uri ImageSourceUri { get; set; }
public Point NormalizedAnchorPoint { get; set; }
public Geopoint Location { get; set; }
}

无法将类型'Windows.Foundation.Point'隐式转换为'System.Drawing.Point'

问题是NormalizedAnchorPoint属性正在使用System.Drawing命名空间。您可以为NormalizedAnchorPoint添加完整的名称空间Windows.Foundation.Point来指定它的类型,如下所示。

public class PointOfInterest
{
public string PinName { get; set; }
public string DisplayName { get; set; }
public Uri ImageSourceUri { get; set; }
public Windows.Foundation.Point NormalizedAnchorPoint { get; set; }
public Geopoint Location { get; set; }
}

最新更新