在C#WinRT应用程序中将存储文件传递给OnNavigatedTo

在C#WinRT应用程序中将存储文件传递给OnNavigatedTo,c#,xaml,windows-runtime,storagefile,C#,Xaml,Windows Runtime,Storagefile,在我的C#WinRT应用程序中,我希望将一个存储文件传递到框架内的新导航页面,以便该页面可以打开文档并将文件内容放入RichEditBox。我尝试使用StorageFile向OnNavigatedTo添加可选参数,但这会导致应用程序崩溃 我尝试将其设置为可以从另一个包含框架的页面导航到如下页面: RootFrame.Navigate(typeof(Editor), file); 然后启动框架页面,如下所示: protected override async void OnNavigatedTo

在我的C#WinRT应用程序中,我希望将一个存储文件传递到框架内的新导航页面,以便该页面可以打开文档并将文件内容放入RichEditBox。我尝试使用StorageFile向OnNavigatedTo添加可选参数,但这会导致应用程序崩溃

我尝试将其设置为可以从另一个包含框架的页面导航到如下页面:

RootFrame.Navigate(typeof(Editor), file);
然后启动框架页面,如下所示:

protected override async void OnNavigatedTo(Windows.UI.Xaml.Navigation.NavigationEventArgs e, Windows.Storage.StorageFile file)
        {
            if (file)
            {
                try
                {
                    EditorBox.Document.SetText(Windows.UI.Text.TextSetOptions.None, await Windows.Storage.FileIO.ReadTextAsync(file));
                }
                catch
                {
                }
            }
        }
但这样做,我会得到以下错误:

  • “TestApp.Page3.OnNavigatedTo(Windows.UI.Xaml.Navigation.NavigationEventArgs,Windows.Storage.StorageFile)”是密封类“TestApp.Page3”中的新虚拟成员。
  • 'TestApp.Page3.on导航到(Windows.UI.Xaml.Navigation.NavigationEventArgs,Windows.Storage.StorageFile)∶找不到合适的方法来覆盖

是否有任何方法可以完成类似于我试图完成的任务?

您只能覆盖现有的方法。你不能覆盖不存在的东西——你应该创建一些新的东西。然而,Windows不会调用它不知道的方法。因此,请坚持Windows提供的功能:

protected override async void OnNavigatedTo(NavigationEventArgs e)
{
    var file = e.Parameter as Windows.Storage.StorageFile;
    if (file!=null)
    {
        ...
    }
}