locked
Share Data/Informations between pages. RRS feed

  • Question

  • Hi,

    I foun this awesome guide ( http://msdn.microsoft.com/en-us/library/windows/apps/hh771188.aspx ) what explain just how pass one information from OnePage to the Second.

    Me.Frame.Navigate(GetType(BasicPage2), tb1.Text)

    I have 5 TextBox in my MainPage, where i do some questions, and a SecondPage,where I do my mathematical calculations and give the result, called "Total". How i can share this information from MainPage to the SecondPage?

    Thanks in advance and sorry for my little knowledge of the language.

    Wednesday, August 7, 2013 11:49 PM

Answers

  • The code below was translated from C#, but hopefully it will give you some ideas.

    Create a class (Answer) that has two properties Name and Value.

    Public Class Answer
        Public Property Name() As String
            Get
                Return m_Name
            End Get
            Set(value As String)
                m_Name = value
            End Set
        End Property
        Private m_Name As String
        Public Property Value() As String
            Get
                Return m_Value
            End Get
            Set(value As String)
                m_Value = value
            End Set
        End Property
        Private m_Value As String
    End Class
    

    Before you navigate to Page 2 create a list of answers.

    Dim answers As New List(Of Answer)()

    Add each TextBox name and Text to the list as answers.

    answers.Add(New Answer() With { _
        .Name = tb1.Name, _
        .Value = tb1.Text _
    })
    answers.Add(New Answer() With { _
        .Name = tb2.Name, _
        .Value = tb2.Text _
    })
    answers.Add(New Answer() With { _
        .Name = tb3.Name, _
        .Value = tb3.Text _
    })
    answers.Add(New Answer() With { _
        .Name = tb4.Name, _
        .Value = tb4.Text _
    })
    answers.Add(New Answer() With { _
        .Name = tb5.Name, _
        .Value = tb5.Text _
    })
    

    Navigate to page 2 passing the answers as parameter.

    Me.Frame.Navigate(GetType(BasicPage1), answers)

    In the LoadState method of page 2 cast the navigation parameter as list of answers.

    Protected Overrides Sub LoadState(navigationParameter As Object, pageState As Dictionary(Of String, Object))
        Dim answers As List(Of Answer) = TryCast(navigationParameter, List(Of Answer))
    
    End Sub
    

    Look into using Model View ViewModel and this process will get easier.

    Hope this helps,

    Hassan

    • Marked as answer by Korstrax Thursday, August 8, 2013 3:48 PM
    Thursday, August 8, 2013 1:50 AM

All replies

  • The code below was translated from C#, but hopefully it will give you some ideas.

    Create a class (Answer) that has two properties Name and Value.

    Public Class Answer
        Public Property Name() As String
            Get
                Return m_Name
            End Get
            Set(value As String)
                m_Name = value
            End Set
        End Property
        Private m_Name As String
        Public Property Value() As String
            Get
                Return m_Value
            End Get
            Set(value As String)
                m_Value = value
            End Set
        End Property
        Private m_Value As String
    End Class
    

    Before you navigate to Page 2 create a list of answers.

    Dim answers As New List(Of Answer)()

    Add each TextBox name and Text to the list as answers.

    answers.Add(New Answer() With { _
        .Name = tb1.Name, _
        .Value = tb1.Text _
    })
    answers.Add(New Answer() With { _
        .Name = tb2.Name, _
        .Value = tb2.Text _
    })
    answers.Add(New Answer() With { _
        .Name = tb3.Name, _
        .Value = tb3.Text _
    })
    answers.Add(New Answer() With { _
        .Name = tb4.Name, _
        .Value = tb4.Text _
    })
    answers.Add(New Answer() With { _
        .Name = tb5.Name, _
        .Value = tb5.Text _
    })
    

    Navigate to page 2 passing the answers as parameter.

    Me.Frame.Navigate(GetType(BasicPage1), answers)

    In the LoadState method of page 2 cast the navigation parameter as list of answers.

    Protected Overrides Sub LoadState(navigationParameter As Object, pageState As Dictionary(Of String, Object))
        Dim answers As List(Of Answer) = TryCast(navigationParameter, List(Of Answer))
    
    End Sub
    

    Look into using Model View ViewModel and this process will get easier.

    Hope this helps,

    Hassan

    • Marked as answer by Korstrax Thursday, August 8, 2013 3:48 PM
    Thursday, August 8, 2013 1:50 AM
  • You can store your class into a static value, and then read it in the second page.
    Thursday, August 8, 2013 6:39 AM
  • Hi Mo_Hassan,

    Thank you, problem solved.


    • Edited by Korstrax Thursday, August 8, 2013 3:47 PM
    Thursday, August 8, 2013 3:01 PM