locked
How does target retrieve parameter with rootFrame->Navigate(target, paramenter)?

    Question

  • In my App.xaml.cpp file I have a Presenter provide the TypeName to Navigate() with the assumption that Navigate would pass the Presenter as a parameter into the targets constructor.  I overloaded the MainPage constructor so that it would receive a Platform::Object parameter (the Presenter) but the default constructor gets called and I can't figure out how to grab the parameter from within the View (target).  

    Note:When the View is instantiated I plan on setting a View property on the Presenter (via Interface) with a reference to the View so that the Presenter can wire it up and set its DataContext with the applicable ViewModel (and populate ViewModel as required).

    if (rootFrame->Content == nullptr) { // Instantiate presenter base (later to be derived from) auto presenter = ref new MvpVm::PresenterBase(); presenter->SetArguments(args->Arguments); // When the navigation stack isn't restored navigate to the first
    // page, configuring the new page by passing required information
    // as a navigation parameter if(!rootFrame->Navigate(presenter->GetPresenterView(), presenter)) { throw ref new FailureException("Failed to create initial page"); } }

    UPDATED 8/23/2012

    Looks like this becomes a moot point as passing objects other than basic types is discouraged - I'll have to find a different way...

    Remarks

    To enable serialization of the frame's state using GetNavigationState, you must pass only basic types to this method, such as string, char, numeric, and GUID types. If you pass an object as a parameter, an entry in the frame's navigation stack holds a reference on the object until the frame is released or that entry is released upon a new navigation that diverges from the stack. In general, we discourage passing a non-basic type as a parameter to Navigate because it can’t be serialized when the application is suspended, and can consume more memory because a reference is held by the frame’s navigation stack to allow the application to go forward and back. 


    MCAD.NET C# - http://www.Global-webnet.com/Blog


    • Edited by BillKrat1 Thursday, August 23, 2012 10:34 AM
    Thursday, August 23, 2012 2:26 AM

Answers

  • Yes, maybe you can serialize your pass class as a string, and desterilize it when you receive it.

    Or you can use global value for store the pass value, you can use map or array to store them, and then pass the index to target page.

    Best regards,
    Jesse


    Jesse Jiang [MSFT]
    MSDN Community Support | Feedback to us


    • Edited by Jesse Jiang Friday, August 24, 2012 6:21 AM
    • Marked as answer by BillKrat1 Saturday, August 25, 2012 12:10 AM
    Friday, August 24, 2012 6:18 AM

All replies

  • Yes, maybe you can serialize your pass class as a string, and desterilize it when you receive it.

    Or you can use global value for store the pass value, you can use map or array to store them, and then pass the index to target page.

    Best regards,
    Jesse


    Jesse Jiang [MSFT]
    MSDN Community Support | Feedback to us


    • Edited by Jesse Jiang Friday, August 24, 2012 6:21 AM
    • Marked as answer by BillKrat1 Saturday, August 25, 2012 12:10 AM
    Friday, August 24, 2012 6:18 AM
  • Yes, maybe you can serialize your pass class as a string, and desterilize it when you receive it.

    Or you can use global value for store the pass value, you can use map or array to store them, and then pass the index to target page.

    I like your global value idea, I will pass in a guid for the Presenter and when OnNavigatedTo() fires locate the guid within the map, get a ref to the Presenter, and then set Presenter->View property with a reference to this.   I can have the Presenter->View setter fire the Presenter.Initialize() which will wire-up the Presenter and its ViewModel.

    Best regards

    Bill


    MCAD.NET C# - http://www.Global-webnet.com/Blog

    Saturday, August 25, 2012 12:17 AM