Search code examples
c#uwpmvvm-light

Receive the page from which an item in the navigation bar is clicked


I would like to know if I click by mouse an item in the navigation bar, located in the main page, from which landing page the click was made.

The click of an menu item generated an event by a methode in the main page. The landig page is loaded by a frame. The landing page is a own page with View and behind code.

The view and view model are separeted by implemented mvvm light.

Load landing page:

if (args.InvokedItemContainer == MenuItemWriteEntry)
               MainContentFrame.NavigateToType(typeof(WriteEntryPage), null, navOptions);

Click event in the main page (code behind):

private void ButtonSaveEntry_OnClick(object sender, RoutedEventArgs e) {}

The information about the landing page, from where I clicked the item menu, is not described in the routed event args. i can find only a reference to the clicked menu item


Solution

  • You can use the MainContentFrame to retrieve the currently displayed page instance:

    if (MainContentFrame.Content is WriteEntryPage writeEntryPage)
    {
       //WriteEntryPage is currently displayed, now stored in writeEntryPage variable
    }