简体   繁体   中英

UWP Navigate to same Page

I have a Page (showDocuments) that shows documents and folders (like in Dropbox or Google Drive). When a user clicks on a folder I'm trying to navigate to a new instance of the showDocuments Page in order to show the content of the clicked folder. However, when I render the new information, it appears both the new documents and the previous ones.

I could do it by just having one page and cleaning it each time, but I need different pages in order to go back to the parent folders using frame.GoBack(), since it is much faster rather than using frame.Navigate(...) and compute and print everything again.

I'm not using a MVVM model, I just have a page and I decide which objects I need to show on the xaml.cs file.

Should I use views instead of pages?

Thanks for your time.

Try by handle the back button operation to catch parameters and navigating back.
You could have global vars of parent folder: the value (parentFolderVar) you pass to showDocuments Page and isReturn that is setted in OnNavigatedTo Method:

App.parentFolderVar = someValue;

So, when you handle tha back operation in App.xaml.cs:

private void OnBackRequested(object sender, BackRequestedEventArgs e)
{
    if (rootFrame.SourcePageType == typeof(showDocuments))
        App.isReturn = true;
    e.Handled = true;
    Pause();
}

And in showDocuments navigation:

protected override void OnNavigatedTo(object sender, NavigationEventArgs e)
{
    if(App.isReturn)
        //You know the parent folder with App.parentFolderVar
    //Make operations
    App.parentFolderVar  = updatedParentFolderValue;
    App.isReturn = false;
}

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