0
假設我想通過多個頁面傳遞一個對象(引用)。我可以通過導航並傳遞參數。但是如何正確地將回參考點傳回來?UWP - 在頁面之間傳遞參數的正確方法
protected override void OnNavigatedTo(NavigationEventArgs e) {
if (e.Parameter is SomeClass) {
this.someObject = (SomeClass)e.Parameter;
}
else {
this.someObject = new SomeClass();
}
SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility = AppViewBackButtonVisibility.Visible;
SystemNavigationManager.GetForCurrentView().BackRequested += OnHardwareButtonsBackPressed;
base.OnNavigatedTo(e);
}
private void OnHardwareButtonsBackPressed(object sender, BackRequestedEventArgs e) {
// This is the missing line!
Frame.Navigate(typeof(FirstPage), this.someObject);
}
但是當我按後退按鈕就可以追溯到FirstPage
OnNavigatedTo
不帶參數,然後回到SecondPage
OnHardwareButtonsBackPressed
,然後回到FirstPage
OnNavigatedTo
與填充參數。
你能否請教我一些更好的方法?