locked
Correctly pass or give access to data from class MainPage:Page to another class xxPage:Page RRS feed

  • Question

  • This may seem basic but I am having issue trying to figure out how to properly provide access to date when passing between pages.

    Example below:

    I have access data and did some manipulation in the MainPage: Page  Class (below)

    public sealed partial class MainPage : Page

    I would like to access the data in the xxPage:Page class (below) without going against the programing language operating structure

    public sealed partial class xxPage : Page

    Thanks,

    Grim


    Thursday, December 5, 2013 7:40 PM

Answers

  • To pass a parameter from the originating page (it can be of any type):

    Frame.Navigate(typeof(PageClassName), "string parameter");
    

    To receive the parameter in the receiving page:

    protected override void OnNavigatedTo(NavigationEventArgs e)
    {
        string MyReceivedParameter = e.Parameter as string;         
    }


    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    • Marked as answer by A.B.P.Lambert Friday, December 6, 2013 1:12 PM
    Friday, December 6, 2013 12:51 PM
    Moderator

All replies

  • You pass data between pages by passing a parameter in the Frame.Navigate method.  Either that, or create an application-level member object in the App.xaml.cs page and use that.

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Thursday, December 5, 2013 8:19 PM
    Moderator
  • Is there any were I can find example's of both methods. I am trying to implement and I am getting errors.

    Thanks

    Grim

    Friday, December 6, 2013 11:16 AM
  • To pass a parameter from the originating page (it can be of any type):

    Frame.Navigate(typeof(PageClassName), "string parameter");
    

    To receive the parameter in the receiving page:

    protected override void OnNavigatedTo(NavigationEventArgs e)
    {
        string MyReceivedParameter = e.Parameter as string;         
    }


    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    • Marked as answer by A.B.P.Lambert Friday, December 6, 2013 1:12 PM
    Friday, December 6, 2013 12:51 PM
    Moderator