2
votes

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
Could you try to follow the getting started from scratch and tell me where it goes wrong? mapsui.github.io/Mapsui/documentation/getting-started-wpf.html. Please use Mapsui 1.4.8, the stable version.pauldendulk
So in my test project I started from scratch and it worked fine. I have now created a new UserControl with the code from your link. I then integrated this UserControl into my app. But also here it comes to the error.Raspi User
Why do you need a UserControl? What are you trying to achieve? Have you created a UserControl before? PresentationSource is not a field or class in Mapsui. It seems your problem is at the level of the UserControl, not in Mapsui.pauldendulk
First I tried it without UserControl. But as I said I have the problem in both cases. I don't need a UserControl. I just want to display a map in a certain cell of a grid.Raspi User
I have now also tried it in my test project with a UserControl. I don't have any problems here. It doesn't seem to be that.Raspi User

1 Answers

0
votes

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