問題描述
如何在 xamarin 表單中將一個內容頁面從客戶端項目導航到另一個內容頁面?
How to navigate one content page to another content page from client project in xamarin forms?
我已經以不同的方式在每個平臺上實現了推送通知.我需要從當前內容頁面導航到另一個內容.
I have done implementing push notification in each platform in different way. I need to navigate to another content from current content page.
我嘗試在 GCMService 的 OnMessage 方法中使用以下代碼.我的問題是第二個導航內容頁面的構造函數被調用并成功調試.但是我的屏幕仍然顯示當前頁面而不顯示第二個導航內容頁面.
i try to use below code in GCMService's OnMessage method. My Problem is Second navigation content page's constructor are called and debug successfully. but my screen still display current page not to display second navigation content page.
App.Current.MainPage.Navigation.PushAsync (new SecondNavigationContentPage());
推薦答案
主頁"必須是導航頁面才能使用推送彈出導航進行導航.你有幾個選擇.
"Main Page" has to be a navigation page in order to navigate with the push pop navigation. You have a couple of options.
選項 1:
用您的新頁面替換 MainPage 并使用內容頁面.
Swap out MainPage with your new page and use content pages.
App.Current.MainPage = your new content page
選項2:(可能是更好的選擇)
Option 2: (Probably the better option)
使 App.Current.MainPage 成為 NavigationPage 而不是 ContentPage,然后將您的第一個內容頁面推送到它.當您需要轉到第二個內容頁面時,請使用推送導航架構.
Make App.Current.MainPage a NavigationPage rather than a ContentPage then push your first content page to it. When you need to go to the second content page use the push navigation architecture.
App.Current.MainPage = new NavigationPage;
App.Current.MainPage.Navigation.PushAsync(Page1);
App.Current.MainPage.Navigation.PushAsync(Page2);
文檔:http://developer.xamarin.com/guides/cross-platform/xamarin-forms/controls/pages/
更新
請注意,由于這個答案已經出現了更好的導航方式,例如 docs.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/... app shell routing.
Note that since this answer much better ways have come along for navigation such as docs.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/… app shell routing.
其他選擇是 Prism MVVM 或您自己的視圖模型定位器 prismlibrary.com/docs/viewmodel-locator.html.使用這種內置導航的缺點是它缺少視圖模型來查看模型導航,并且依賴于頁面到頁面,這會導致不必要的視圖耦合以及簡單笨拙的導航.
Other choices are Prism MVVM or your own view model locator prismlibrary.com/docs/viewmodel-locator.html. The short coming in using this built in navigation is it lacks view model to view model navigation and depends on page to page which causes unwanted coupling of views and just plain clunky navigation.
這篇關于如何以 xamarin 形式將一個內容頁面從客戶端項目(IOS/Android)導航到另一個內容頁面?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!