[英]Passing a StorageFile to OnNavigatedTo in a C# WinRT app
在我的C#WinRT應用程序中,我想將一個StorageFile傳遞到一個框架內的新導航頁面,以便該頁面可以打開文檔並將文件的內容放入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)' is a new virtual member in sealed class 'TestApp.Page3'
'TestApp.Page3.OnNavigatedTo(Windows.UI.Xaml.Navigation.NavigationEventArgs, Windows.Storage.StorageFile)': no suitable method found to override
有沒有辦法做一些類似於我想要完成的事情?
您只能覆蓋現有方法。 你無法覆蓋不存在的東西 - 你會創造新的東西。 但是,Windows不會調用它不知道的方法。 所以堅持使用Windows提供的功能:
protected override async void OnNavigatedTo(NavigationEventArgs e)
{
var file = e.Parameter as Windows.Storage.StorageFile;
if (file!=null)
{
...
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.