簡體   English   中英

如何根據當前向用戶顯示的頁面有條件地 PopAsync

[英]How to conditionally PopAsync based on what page is currently show to user

在我的應用程序的同一頁面中,用戶可以發送兩個 websocket 請求。 然后我得到兩個 websocket 響應。 在每個響應中,我都會從導航堆棧中彈出頁面。 這是在他們的個人資料頁面中,他們可以在其中編輯一些基本信息或更改密碼。 希望他們通常只做一個,但如果他們兩個都做,然后點擊保存,它會彈出兩次頁面。

我一直在嘗試檢查當前頁面,如果他們仍然在前面的 go 的配置文件頁面上並彈出它,但如果它們沒有,則跳過彈出。

似乎 popasync 實際上並沒有從堆棧中刪除頁面,因為我會在之后將導航堆棧調用到列表中進行檢查,並且它仍然存在。 我嘗試檢查堆棧中的任何頁面是否是配置文件頁面,然后將其彈出。 如果堆棧中有多個實例,這仍然可能是草率的,但它至少會讓我朝着正確的方向前進。

我還嘗試使用 MessagingCenter 將其帶回后面的代碼,但這也沒有奏效。

這里的主要問題是我只想彈出用戶當前正在查看的頁面。

如果有人能指出我正確的方向,那將不勝感激。

else if (root.payload?.data?.updateUserFields != null)
                {
                    DabGraphQlUpdateUserFields fields = root.payload.data.updateUserFields;

                    dbSettings.StoreSetting("Email", fields.email);
                    dbSettings.StoreSetting("FirstName", fields.firstName);
                    dbSettings.StoreSetting("LastName", fields.lastName);

                    GlobalResources.WaitStop();
                    var UserName = GlobalResources.GetUserName().Split(' ');
                    GuestStatus.Current.UserName = GlobalResources.GetUserName();
                    Device.BeginInvokeOnMainThread(() => { Application.Current.MainPage.DisplayAlert("Success", "User profile information has been updated", "OK"); ; });
                    DabProfileManagementPage profilePage = new DabProfileManagementPage();
                    Device.BeginInvokeOnMainThread(() =>
                    {
                        if (Application.Current.MainPage.Navigation.NavigationStack.Any(p => p is DabProfileManagementPage))
                        {
                            var existingPagess = Application.Current.MainPage.Navigation.NavigationStack.ToList();
                            Application.Current.MainPage.Navigation.PopAsync();
                            var _lastPage = Application.Current.MainPage.Navigation.NavigationStack.LastOrDefault();
                            Application.Current.MainPage.Navigation.RemovePage(_lastPage);
                            var existingPages = Application.Current.MainPage.Navigation.NavigationStack.ToList();
                        }
                    });

                    //Device.BeginInvokeOnMainThread(() => { Application.Current.MainPage.Navigation.PopAsync(); });
                }
                else if (root.payload?.data?.updatePassword != null)
                {
                    GlobalResources.WaitStop();
                    if (root.payload.data.updatePassword == true)
                    {
                        Device.BeginInvokeOnMainThread(() => { Application.Current.MainPage.DisplayAlert("Success", "Your password has been updated", "OK"); ; });
                        Device.BeginInvokeOnMainThread(() =>
                        {
                            if (Application.Current.MainPage.Navigation.NavigationStack.Any(p => p is DabProfileManagementPage))
                            {
                                var existingPagess = Application.Current.MainPage.Navigation.NavigationStack.ToList();
                                Application.Current.MainPage.Navigation.PopAsync();
                                var _lastPage = Application.Current.MainPage.Navigation.NavigationStack.LastOrDefault();
                                Application.Current.MainPage.Navigation.RemovePage(_lastPage);
                                var existingPages = Application.Current.MainPage.Navigation.NavigationStack.ToList();
                            }
                        });

                        //Device.BeginInvokeOnMainThread(() => { Application.Current.MainPage.Navigation.PopAsync(); });
                    }
                }

正如 Jason 指出的那樣,我剛剛添加了 int 類型的變量,並在發生彈出后增加了它,並在它嘗試 go 超過 2 時將其重置。一旦用戶單擊以再次打開頁面,我也將其重置為 0。 唯一不應該經常發生的問題是,如果用戶嘗試 go 並在不離開頁面的情況下第三次更改信息。 不會發生流行音樂。 我考慮過添加一個計時器,但之前我的應用程序會因為計時器而變得混亂,所以我選擇暫時保持原樣。 希望我能找到一種每次彈出一次的方法,無論用戶決定點擊 function 多少次。

                else if (root.payload?.data?.updateUserFields != null)
                {
                    DabGraphQlUpdateUserFields fields = root.payload.data.updateUserFields;

                    dbSettings.StoreSetting("Email", fields.email);
                    dbSettings.StoreSetting("FirstName", fields.firstName);
                    dbSettings.StoreSetting("LastName", fields.lastName);

                    GlobalResources.WaitStop();
                    var UserName = GlobalResources.GetUserName().Split(' ');
                    GuestStatus.Current.UserName = GlobalResources.GetUserName();
                    Device.BeginInvokeOnMainThread(() => { Application.Current.MainPage.DisplayAlert("Success", "User profile information has been updated", "OK"); ; });
                    if (popRequests < 1)
                    {
                        popRequests = popRequests + 1;
                        Device.BeginInvokeOnMainThread(() => { Application.Current.MainPage.Navigation.PopAsync(); });
                    }
                    else
                        popRequests = 0;
                }
                else if (root.payload?.data?.updatePassword != null)
                {
                    GlobalResources.WaitStop();
                    if (root.payload.data.updatePassword == true)
                    {
                        Device.BeginInvokeOnMainThread(() => { Application.Current.MainPage.DisplayAlert("Success", "Your password has been updated", "OK"); ; });
                        if (popRequests < 2)
                        {
                            popRequests = popRequests + 1;
                            Device.BeginInvokeOnMainThread(() => { Application.Current.MainPage.Navigation.PopAsync(); });
                        }
                        else
                            popRequests = 1;
                    }
                }

暫無
暫無

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

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