Cannot implicitly convert type when adding pin to MapControl

72 views Asked by At

I'm trying to add a pin to a MapControl dynamically but it's not working despite using an import statement (using). new Point(0.5, 1) in NormalizedAnchorPoint = new Point(0.5, 1) returns the following error. What's the correct way to resolve this?

Cannot implicitly convert type 'Windows.Foundation.Point' to 'System.Drawing.Point'

MainPage.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);
    }
}

'PointOfInterest' class

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; }
}
1

There are 1 answers

0
Nico Zhu On BEST ANSWER

Cannot implicitly convert type 'Windows.Foundation.Point' to 'System.Drawing.Point'

The problem is NormalizedAnchorPoint property is using System.Drawing namespace. And you could add the full namespace Windows.Foundation.Point for NormalizedAnchorPoint to specific it's type like the following.

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