2

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!

Community
  • 1
  • 1
Raspi User
  • 33
  • 3
  • Could you try to follow the getting started from scratch and tell me where it goes wrong? http://mapsui.github.io/Mapsui/documentation/getting-started-wpf.html. Please use Mapsui 1.4.8, the stable version. – pauldendulk Dec 21 '18 at 11:48
  • 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 Dec 21 '18 at 12:09
  • 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 Dec 21 '18 at 14:09
  • 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 Dec 21 '18 at 15:02
  • 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 Dec 21 '18 at 15:11
  • So, you can get it to work following the getting started from scratch but it fails if you try to use it in your main project. Are your test project and your main project the same type? Both WPF? Both the same framework version? – pauldendulk Dec 21 '18 at 19:44
  • In both cases it is a WPF project with the same framework version. I've tried a bit more now. I use tabs in my Main Project. That's why I worked with UserControls. I don't currently use the map in the first tab that is called. If I use the map in the first tab or use a UserControl in the first tab with a map it seems to work. Unfortunately I can't explain the exact difference. – Raspi User Dec 22 '18 at 08:09

1 Answers1

0

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

Gary Kindel
  • 17,071
  • 7
  • 49
  • 66