C# UWP Page, trigger a routine when leaving or returning to a Page

Paul Ryan 321 Reputation points
2022-08-21T15:52:02.093+00:00

Hi, I am fairly new to UWP, XAML.

  1. I have a Pivot Menu with a few pages.
  2. In each page I have two Buttons (Mic on, Mic Off) used at least three times in each page
  3. I use a tag to figure out which Button to Collapse and make Visible when button is clicked

This works with no issues
My issue is when the users leaves the page with Mic On (I can turn off voice using a Static Bool, in the Pivot Page xaml.cs )

I am trying to figure out how to set the Buttons to default value (I can write routine in XAML.cs to do this but cannot figure out how to trigger the routine when leaving or returning to the page).

QUESTION: how can I set the visibility button when leaving or returning to a page or should I be doing something different

Thank you and I appreciate the help
Paul

Universal Windows Platform (UWP)
0 comments No comments
{count} votes

Accepted answer
  1. Roy Li - MSFT 32,231 Reputation points Microsoft Vendor
    2022-08-22T02:01:31.29+00:00

    Hello,

    Welcome to Microsoft Q&A!

    >how can I set the visibility button when leaving or returning to a page or should I be doing something different

    A common way is that you could override the Page.OnNavigatedTo Method and Page.OnNavigatedFrom Method.

    Page.OnNavigatedTo Method is invoked when the Page is loaded and becomes the current source of a parent Frame.

    Page.OnNavigatedFrom Method is invoked immediately after the Page is unloaded and is no longer the current source of a parent Frame.

    In these methods, you could perform tasks such as initializing and saving the page state.

    Thank you.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful