【问题标题】:UWP Navigate to same PageUWP 导航到同一页面
【发布时间】:2017-02-13 22:06:53
【问题描述】:

我有一个页面 (showDocuments) 显示文档和文件夹(例如在 Dropbox 或 Google Drive 中)。当用户单击文件夹时,我试图导航到 showDocuments 页面的新实例,以显示单击文件夹的内容。但是,当我呈现新信息时,它会同时显示新文档和以前的文档。

我可以通过只拥有一页并每次清理它来做到这一点,但我需要不同的页面才能使用 frame.GoBack() 返回到父文件夹,因为它比使用 frame.Navigate 快得多(...) 并再次计算和打印所有内容。

我没有使用 MVVM 模型,我只有一个页面,我决定需要在 xaml.cs 文件中显示哪些对象。

我应该使用视图而不是页面吗?

感谢您的宝贵时间。

【问题讨论】:

  • 请显示您已经尝试过的内容(代码)
  • “但是,当我呈现新信息时,它会同时显示新文档和以前的文档。”是什么意思?这没有意义。
  • 我的意思是它打印我在前一页上的文档(数据),以及应该在同一页的新“实例”上打印的文档。 @AndrewBares

标签: c# mvvm uwp windows-10-universal


【解决方案1】:

尝试通过处理返回按钮操作来捕获参数并导航返回。
您可以拥有父文件夹的全局变量:您传递给 showDocuments 页面的 value (parentFolderVar) 和在 OnNavigatedTo 方法中设置的 isReturn:

App.parentFolderVar = someValue;

所以,当您在 App.xaml.cs 中处理返回操作时:

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

在 showDocuments 导航中:

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;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-30
    • 2021-11-29
    • 2018-08-01
    • 1970-01-01
    • 2018-06-26
    • 2020-12-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多