charlenni / Mapsui.Forms

Xamarin.Forms wrapper around Mapsui
MIT License
6 stars 3 forks source link

UWP - Element is already the child of another element. #1

Open spaddlewit opened 7 years ago

spaddlewit commented 7 years ago

I created a repro project, based on your existing Mapsui.Forms.Samples PCL project, just drop it in as a replacement: http://www.spaddlewit.com/UWPError.zip

The issue is when you Navigation.PushAsync or Navigation.PushModalAsync another form on top, and then pop back to the forms with the Mapsui control:

"System.Runtime.InteropServices.COMException: No installed components were detected.\r\n\r\nElement is already the child of another element.\r\n at System.Runtime.InteropServices.WindowsRuntime.IVector`1.Append(T value)\r\n at System.Runtime.InteropServices.WindowsRuntime.VectorToCollectionAdapter.Add[T](T item)\r\n at Mapsui.UI.Uwp.MapControl.InitAnimation()\r\n at Mapsui.UI.Uwp.MapControl.MapControlLoaded(Object sender, RoutedEventArgs e)"

Any idea what's going on here?

spaddlewit commented 7 years ago

Here's the fix, in Mapsui.UI.Uwp.MapControl.InitAnimation():

Check if the children collection already contains '_zoomAnimation' before adding it.

        if (!_zoomStoryBoard.Children.Contains(_zoomAnimation))
            _zoomStoryBoard.Children.Add(_zoomAnimation);
spaddlewit commented 7 years ago

This might also not be the completely 'correct' fix... should MapControlLoaded be allowed to potentially fire multiple times? Or should the event be removed inside of the MapControlLoaded event callback?