How to pass QueryString or Parameter to new page? RRS feed

  • Question

  • I would like to post Message value to BasicPage1.xaml into a label box.

            <mui:ModernTab Layout="List">
                    <!-- TODO: set @Source -->
                    <mui:Link DisplayName="Item 1" Source="/Pages/BasicPage1.xaml?Message=TestItem1" />
                    <mui:Link DisplayName="Item 2" Source="/Pages/BasicPage1.xaml?Message=TestItem2"/>

    Can I have some guideline?

    Thursday, August 17, 2017 6:30 AM

All replies

  • Please see this thread:


    You can do something like:

    string theUrl = NavigationService.CurrentSource();

    As Paul explains here:


    This is not how I would usually handle this sort of thing.

    WPF is not a web app, url parameters are necessary on the web because of it's stateless nature.

    You can pass in parameters via constructor injection in wpf, because your code can new up the View or whatever object you like itself rather than passing stuff over to IIS to route.


    If I explain roughly how I work.

    I rarely use pages, instead using usercontrols which are presented inside contentcontrols.

    I use MVVM, so there's a viewmodel as well as a usercontrol involved and the logic for handling testitem1 differently to testitem2 would go into the viewmodel. 

    I would consider using templating and viewmodel first.

    EG I'd have a Page1ViewModel and a Page2ViewModel. They are associated with their view by a datatemplate with datatype={x:Type local:Page1ViewModel};

    The viewmodel would then be bound as content of a contentcontrol.

    Change the viewmodel for another and the view changes between page1 and page 2. New up another instance of Page1ViewModel passing some different parameters and that is templated into a new page1.


    Hope that helps.

    Technet articles: WPF: Layout Lab; All my Technet Articles

    Thursday, August 17, 2017 9:40 AM