簡體   English   中英

Xamarin 表單中的導航問題

[英]Navigation Issue in Xamarin Forms

我需要路由頁面 A -> B -> C -> D,一旦我進入 D,我需要使用導航按鈕返回頁面 D -> A。我正在嘗試在 Xamarin Forms 中實現這個場景 IOS 和 Android .

請幫忙

你的情況使用Navigation.PopToRootAsync ();

Navigation.PopToRootAsync (); 此方法從導航堆棧中彈出除RootPage之外的所有頁面,從而使應用程序的根頁面成為活動頁面。

Navigation.PopAsync (); 這會導致Page2Xaml實例從導航堆棧中刪除,新的最頂層頁面成為活動頁面。

以下文檔很好地解釋了Xamarin.Forms導航。 https://docs.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/navigation/hierarchical

在“D”頁面內覆蓋“OnBackButtonPressed”,並在函數內部遍歷您不再需要的頁面並一一刪除它們。

偽代碼:

    protected override bool OnBackButtonPressed()
    {
        foreach (var page in Navigation.NavigationStack)
        {

            //find the pages you want to remove
            Navigation.RemovePage(PageYouFound);
        }
        //Set new page
        return base.OnBackButtonPressed();

    }

您可以監控 OnBackButtonPressed 事件並使用 Navigation.PopToRootAsync

protected override bool OnBackButtonPressed()
    {
        Navigation.PopToRootAsync();
        return base.OnBackButtonPressed();

    }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM