Mapsui Error: How to fix PresentationSource is null?

459 Views Asked by At

I have started to develop a WPF application with Mapsui. First I tried to get familiar with Mapsui in a seperat Visual Studio project. Now I want to include my code to my main project.

At the moment I get the following error message from which I can't figure out:

System.Exception: "PresentationSource is null"

In my test project for Mapsui I did not get this error.

I also tried to include my application code into the test project. But here I also get this error message.

<Grid Grid.Column="1" Grid.Row="0" Margin="10,10,10,10">
        <xaml:MapControl Name="MapControl"></xaml:MapControl>
</Grid>

Maybe someone knows ideas I should take a closer look at or has a direct solution. Many thanks for your help!

1

There are 1 best solutions below

0
On

The error may be caused by an error in the viewmodel constructor. I received this error in a WPF view hosting a usercontrol containing the Mapsui mapcontrol in WPF MVVM application.

System.Exception HResult=0x80131500 Message=PresentationSource is null Source=Mapsui.UI.Wpf StackTrace: at Mapsui.UI.Wpf.MapControl.DetermineSkiaScale() at Mapsui.UI.Wpf.MapControl.DetermineScale()

If I set RenderMode='Skia' or leave it blank I get the error. Fixed error by setting RenderMode to Wpf in xaml in the usercontrol. Setting this RenderMode to wpf also worked in code behind the usercontrol, setting it in the usercontrol's constructor.

<Wpf:MapControl RenderMode="Wpf" Name="myMapControl" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" />

or

this.myMapControl.RenderMode = Mapsui.UI.Wpf.RenderMode.Wpf;

The purpose beneath my user control was so I could create binding to Mapsui.MapControl.Map to a viewmodel.

Screen shot of Mapsui.mapcontrol hosted in a WPF usercontrol.

enter image description here