locked
How to navigate and pass parameters between a UserControl and a Page

    Question

  • In my app, a Windows::UI::Xaml::Controls::UserControl page (including a Popup control) is popped up for users to change settings. From this UserControl page, users expect to navigate to a color picker page (of the type Windows::UI::Xaml::Controls::Page) to change the color, and then return to the UserControl page.  Meanwhile the color information need to be passed. So how can I do this? 
    Wednesday, December 26, 2012 4:35 PM

Answers

  • Brief Notes on Page Navigation in C++
    =====================================

    Essentially, you use a Frame->Navigate( TypeName sourcePageType, Object^ navigationParameter ) method
    to start a new page, passing the navigationParameter .
    http://msdn.microsoft.com/en-us/library/windows/apps/hh702394.aspx?cs-save-lang=1&cs-lang=cpp#code-snippet-1

    SourcePageType,  is TypeName( TheDestinationPage::typeid )  (needs TheDestinationage.h somewhere)
    parameter  is any WinRT type

    Here is a sample:

    String ^ navigationParameter(  "pooh" );
    this->Frame->Navigate( Windows::UI::Xaml::Interop::TypeName( TheDestinationPage::typeid ), navigationParameter );

    C# was this.Frame.Navigate(typeof(TheDestinationPage), tb1.Text);


    The navigationParameter appears in:

    void TheDestinationPage::LoadState(Object^ navigationParameter, IMap<String^, Object^>^ pageState)
    {
     String ^ passed= (String ^)navigationParameter;
     ...
    }


    See also "Navigating between pages" from "Tutorial: Create your first Windows Store app using C++"
    http://msdn.microsoft.com/en-us/library/windows/apps/hh465045.aspx

    • Marked as answer by Leonard Friday, December 28, 2012 3:59 PM
    Thursday, December 27, 2012 5:37 PM

All replies

  •  

    "Quickstart: Navigating between pages (Windows Store apps using C#/VB/C++ and XAML) "

    http://msdn.microsoft.com/en-us/library/windows/apps/xaml/Hh771188.aspx

    Use the second parameter The missing C++ specific code sample
    this->Frame->Navigate( Windows::UI::Xaml::Interop::TypeName(MyPage::typeid), ss );
     

    Wednesday, December 26, 2012 11:00 PM
  • Thanks a lot Andrew7Webb.

    That's what I'm looking for. Unfortunately the sample code in only in C#, not C++. I tried to translate C# into C++ but failed. Could you help, or point me some C++ tutorial on page navigation?


    • Edited by Leonard Thursday, December 27, 2012 4:33 PM
    Thursday, December 27, 2012 4:33 PM
  • Brief Notes on Page Navigation in C++
    =====================================

    Essentially, you use a Frame->Navigate( TypeName sourcePageType, Object^ navigationParameter ) method
    to start a new page, passing the navigationParameter .
    http://msdn.microsoft.com/en-us/library/windows/apps/hh702394.aspx?cs-save-lang=1&cs-lang=cpp#code-snippet-1

    SourcePageType,  is TypeName( TheDestinationPage::typeid )  (needs TheDestinationage.h somewhere)
    parameter  is any WinRT type

    Here is a sample:

    String ^ navigationParameter(  "pooh" );
    this->Frame->Navigate( Windows::UI::Xaml::Interop::TypeName( TheDestinationPage::typeid ), navigationParameter );

    C# was this.Frame.Navigate(typeof(TheDestinationPage), tb1.Text);


    The navigationParameter appears in:

    void TheDestinationPage::LoadState(Object^ navigationParameter, IMap<String^, Object^>^ pageState)
    {
     String ^ passed= (String ^)navigationParameter;
     ...
    }


    See also "Navigating between pages" from "Tutorial: Create your first Windows Store app using C++"
    http://msdn.microsoft.com/en-us/library/windows/apps/hh465045.aspx

    • Marked as answer by Leonard Friday, December 28, 2012 3:59 PM
    Thursday, December 27, 2012 5:37 PM
  • Thank you very much Andrew7Webb. I can run through the example with your help.

    However, I find that a Frame is a member of Windows::UI::Xaml::Controls::Page, but not of Windows::UI::Xaml::Controls::UserControl.  This means I cannot navigate between a UserControl and a Page. So is there any way to accomplish this?

    Friday, December 28, 2012 4:03 PM
  • You might try to get to the previous page via the parent property, since UserControl is a FrameworkElement.

    http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.frameworkelement.parent.aspx

    But I have not tried this.

    Friday, December 28, 2012 5:12 PM