I would like to display a customized map icon within a .net core 3.1 WPF application.
I added the NuGet Package Microsoft.Toolkit.Wpf.UI.Controls and put the MapControl on the MainWindow.
<map:MapControl x:Name="myMap" Loaded="OnMapLoaded" />
In the code-behind file I add a mapIcon to the MapElements collection and set the Image to a mapIconStreamReference.
private void OnMapLoaded(object sender, RoutedEventArgs e)
{
var position = new Geopoint(new BasicGeoposition() { Latitude = Latitude, Longitude = Longitude });
MapIcon mapIcon1 = new MapIcon
{
Location = position,
Image = mapIconStreamReference,
};
myMap.MapElements.Add(mapIcon1);
}
I tried to initialize the stream reference through different ways:
// load by WPF pack URI:
mapIconStreamReference = RandomAccessStreamReference.CreateFromUri(new Uri("pack://application:,,,/Assets/MapPin.png"));
// load by UWP pack URI
mapIconStreamReference = RandomAccessStreamReference.CreateFromUri(new Uri("ms-appx:///Assets/MapPin.png"));
// load file into a memory stream
var fileStream = File.OpenRead(@"Assets/mappin.png");
var memStream = new MemoryStream();
fileStream.CopyTo(memStream);
mapIconStreamReference = RandomAccessStreamReference.CreateFromStream(memStream.AsRandomAccessStream());
The image is either declared as Resource or Content (I tried all combinations).
Whatever I try the map only displays the orange default map pin. The same code works properly within an UWP application. As I understand the MapControl from the toolkit is just a wrapper around the UWP MapControl shown in a XAML island.