如何在 Xamarin Forms 中检查 RgPlugn PopUp 是否为空?

问题描述 投票:0回答:1

我在我的 xamarin 应用程序中使用 RgPlugn PopUp 页面,我想检查此弹出页面是否打开,因为当会话时间结束时我将用户从应用程序中踢出。如果没有 RgPlugn PopUp 页面,则会出现 null 异常错误。 如何检查 RgPlugn PopUp 页面是否为空?我使用此代码来踢出用户。

 private void RedirectAndInformInactivity()
    {
        Device.BeginInvokeOnMainThread(async () =>
        {
            await Application.Current.MainPage.DisplayAlert("Oturum Sonlandı!", "İşlem yapmadığınız için oturumunuz sonlandırılıyor!", "Tamam");
            await PopupNavigation.Instance.PopAsync();
            await Application.Current.MainPage.Navigation.PushAsync(new LogoutPage());

        });
    }
xamarin xamarin.forms plugins popup
1个回答
0
投票

您可以检查是否有弹窗打开。

//Verifying whether any popup pages are present in the PopupStack
//It returns true if there are any pop-up pages in the PopupStack.
if (Rg.Plugins.Popup.Services.PopupNavigation.Instance.PopupStack.Any())
{
    List<PopupPage> popupPageList = new List<PopupPage>();
    popupPageList = Rg.Plugins.Popup.Services.PopupNavigation.Instance.PopupStack.ToList();
    
    // popupPageList contains all of the pages that are present in the PopupStack, which you can validate according to your requirements.
}
else
{
    //Popup stack is empty
}
© www.soinside.com 2019 - 2024. All rights reserved.