none
Windows Store Bing Maps App Save State Problem RRS feed

  • Question

  • I have a Windows Store App with Bing Maps.  The map is on the MainPage and I have a button that opens a config page.  When I return from the config page I want the state of the map restored (e.g., all the pushpins that were showing).  I've tried:

    Private _MyMarkerLayer As New Bing.Maps.MapLayer
    
    Private Sub MainPage_Loaded(sender As Object, e As RoutedEventArgs) Handles Me.Loaded
            myMap.Children.Clear()
            myMap.Children.Add(_MyMarkerLayer)
    End Sub
    
    Protected Overrides Sub LoadState(navigationParameter As Object, pageState As Dictionary(Of String, Object))
            If pageState IsNot Nothing Then
                ' If pageState.ContainsKey("Map") Then myMap = pageState("Map")
                'If pageState.ContainsKey("MyMarkerLayer") Then _MyMarkerLayer = pageState("MarkerLayerCyclonesInitial")
            End If
    End Sub
    
    Protected Overrides Sub SaveState(pageState As Dictionary(Of String, Object))
            ' pageState("Map") = myMap
            pageState("MyMarkerLayer") = _MyMarkerLayer
    End Sub
    
    
    

    But I get an error:

    An exception of type 'System.ArgumentException' occurred in mscorlib.dll but was not handled in user code
    WinRT information: The parameter is incorrect.
    Additional information: The parameter is incorrect.

    at the " myMap.Children.Add(_MyMarkerLayer)" line.  I also tried the commented lines for myMap and I did not get the error but nothing showed up.  Can anyone see what I am doing wrong?

    Thanks!

    Sunday, February 24, 2013 10:50 PM

Answers

  • You can't add a XAML control as a child in two places. Remove it from the first place before adding it as a child in the second place.
    • Marked as answer by MiklaDfar Thursday, February 28, 2013 5:50 PM
    Thursday, February 28, 2013 4:45 PM

All replies

  • Is _MyMarkerLayer already a child of another control?

    Tuesday, February 26, 2013 7:36 PM
  • Yes... On initial app load I add _MyMarkerLayer as a child to myMap, so when I save the state of _MyMarkerLayer it is a child.
    Wednesday, February 27, 2013 1:09 AM
  • You can't add a XAML control as a child in two places. Remove it from the first place before adding it as a child in the second place.
    • Marked as answer by MiklaDfar Thursday, February 28, 2013 5:50 PM
    Thursday, February 28, 2013 4:45 PM
  • Oh my... now I feel foolish... guess I was just staring at it too long.  That did the trick... Thanks!
    Thursday, February 28, 2013 5:51 PM