本文介紹了無法使用 c# 導航到 Windows Metro App 上的頁面的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
當我的 UserLogin
頁面加載時,我想檢查用戶數據庫,如果它不存在或無法讀取,我想將其定向到 NewUser
頁面.
When my UserLogin
page loads, i want to check for user database, and if it doesn't exist, or can't be read, i want to direct it to NewUser
page.
protected override void OnNavigatedTo(NavigationEventArgs e)
{
CheckForUser();
if (UserExists == false)
this.Frame.Navigate(typeof(NewUser));
}
問題是它永遠不會導航到 NewUser
,即使我注釋掉 if
條件.
The problem is that it never navigates to NewUser
, even when i comment out the if
condition.
推薦答案
Navigate
不能直接從 OnNavigatedTo
方法調用.您應該通過 Dispatcher
調用您的代碼,它會起作用:
Navigate
can't be called directly form OnNavigatedTo
method. You should invoke your code through Dispatcher
and it will work:
protected override void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);
CheckForUser();
if (UserExists == false)
Dispatcher.RunAsync(CoreDispatcherPriority.Normal,
() => this.Frame.Navigate(typeof(NewUser)));
}
這篇關于無法使用 c# 導航到 Windows Metro App 上的頁面的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!