简体   繁体   中英

Determine Current Page

I have an AppBar with a button that launches a popup that contains a list that the user selects and upon one being selected it refreshes the page, but before it refreshes for a certain page I need it to execute a task. The code works great on my other pages. I just need it to execute

await home.DatabaseTest();

before it refreshes the page and I only want it to execute if the current page is Dashboard

private async void customerNamePopUp_Tapped_1(object sender, TappedRoutedEventArgs e)
    {
        //Gets the selected Customer Name and stores it in the Database.
        barCustomerName = db.selectCustomerNumberByCustomerName(customerNamePopUp.SelectedItem);
        rh.appDataHandler(customerNamePopUp.SelectedIndex, barCustomerName);
        if ("WHAT DO I PUT HERE TO TEST IF PAGE EQUALS DASHBOARD")
        {
            await home.DatabaseTest();
        }

        if (this.Frame != null)
        {
            //Refreshes Current Page
            Frame1.Navigate(Frame1.Content.GetType(), RootPage);                
        }
    }

See note in loop before the await task to know what I am asking for.

Thank you

  1. Create a public enum where each item correlates to each page.
  2. On the App page create a static property of the enum created which will signify the current page.
  3. On each page's OnNavigatedTo method set the app static property to that page's enum.
  4. Wherever needed check that variable for the current page.

I figured it out.

if (Frame1.Content.GetType() == typeof(Dashboard))
        {
            await home.DatabaseTest();
        }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM