We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Second popup is not show before is property IsOpen set to false

I created simple dialog service which wrap Popup control.

public class DialogService : IDialogService
{
private SfPopupLayout popupLayout;
public void ShowConfirm(string title, string question, Action okCallback, Action noCallback)
{
var vm = new ConfirmDialogViewModel(okCallback, noCallback) {Question = question};
popupLayout = new SfPopupLayout
{
PopupView =
{
ShowHeader = true,
ShowFooter = true,
ShowCloseButton = false,
HeaderTitle = title,
AppearanceMode = AppearanceMode.TwoButton
}
};
var templateView = new DataTemplate(() => new ConfirmDialogView
{
BindingContext = vm
});
popupLayout.PopupView.ContentTemplate = templateView;
popupLayout.Show();
}
public void HideConfirm()
{
popupLayout.IsOpen = false;
}
}


I scenario when

1. Open popup_1
2. Close popup_1 from code, set property IsOpen to false
3. Open popup_2

Popup 2 is not show.

_dialogService.ShowConfirm("title_1", "question_1", () => {}, ()=>{});
_dialogService.HideConfirm();
_dialogService.ShowConfirm("title_2", "question_2", () => { }, () => { });

What is wrong? I need close popup_1 from code only way I found is set property is IsOpen to false.


3 Replies

VR Vigneshkumar Ramasamy Syncfusion Team November 28, 2018 01:20 PM UTC

Hi Jan,  
  
Thanks for contacting Syncfusion Support.  
  
We checked your code snippet, you are creating the instance of SfPopupLayout each time when you are calling the ShowConfirm() method, you need to create the SfPopupLayout instance globally and call it whenever you need to show the popup. Please find the modified code sample below in which SfPopupLayout is created only once and called whenever needed.  
  
public class DialogService : IDialogService  
{  
  
private SfPopupLayout popupLayout;  
  
public void CreatePopup()  
{  
popupLayout = new SfPopupLayout  
{  
PopupView =  
{  
ShowHeader = true,  
ShowFooter = true,  
ShowCloseButton = false,  
AppearanceMode = AppearanceMode.TwoButton  
}  
};  
}  
  
public void ShowConfirm(string title, string question, Action okCallback, Action noCallback)  
{  
var vm = new ConfirmDialogViewModel(okCallback, noCallback) {Question = question};  
popupLayout.PopupView.HeaderTitle = title;  
  
var templateView = new DataTemplate(() => new ConfirmDialogView  
{  
BindingContext = vm  
});  
popupLayout.PopupView.ContentTemplate = templateView;  
popupLayout.Show();  
}  
public void HideConfirm()  
{  
popupLayout.IsOpen = false;  
}  
}  
  
_ dialogService.CreatePopup();  
_dialogService.ShowConfirm("title_1", "question_1", () => {}, ()=>{});  
_dialogService.HideConfirm();  
_dialogService.ShowConfirm("title_2", "question_2", () => { }, () => { });  
  
  
Please let us know if this is helpful.  
  
Regards,  
Vigneshkumar R 



JN Jan Najlepsi November 28, 2018 02:42 PM UTC

Hello Vigneshkumar

Your solution not work for me. I use syncfusion xamarin forms controls in MVVM scenerio (Xamarin forms, PRISM, Syncfusion).

I created singleton DialogService which is injected in ViewModels classes.

Complete code of DialogService is in the attachments.


Usages:

  _dialogService.Init();
  _dialogService.ShowBusyDialog("Doing something amazing");
  _dialogService.HideBusyDialog();
  _dialogService.ShowError("Error message', () => { });

Same behavior as before. Second popup is open and close.




Attachment: DialogService_6d626df9.zip


VR Vigneshkumar Ramasamy Syncfusion Team November 29, 2018 07:23 AM UTC

Hi Jan,  
 
We checked your query, “Second Popup Open and Close”, as in the below screenshot.  
 
   
We are able to reproduce it, when all the actions as in the below screenshot is done one by one immediately.   
 
   
 
The popup opens and closes immediately because, the popup will be opened and closed asynchronously, since the animation is running in popup for opening and closing. So, you cannot show the popup again before it closes. You can fix this issue in sample by either setting theSfPopupLayout.PopupView.AnimationMode as None or showing the popup 1 and closing it and again opening the popup 2 asynchronously. Please find the code snippet of the same below.  
 
Code snippet for Solution 1: SfPopupLayout.PopupView.AnimationMode as None  
public void Init()  
{  
    popupLayout = new SfPopupLayout  
    {  
        PopupView =  
        {  
            ShowHeader = true,  
            ShowFooter = true,  
            ShowCloseButton = false,  
            AppearanceMode = AppearanceMode.TwoButton,  
            AnimationMode = AnimationMode.None,  
        }  
    };  
}  
 
Code snippet for Solution 2: showing the popup 1 and closing it and again opening the popup 2 asynchronously  
Close1PopupAndShow2 = new Command(async () =>  
{  
    dialog.Show("Show Popup1", null, null, null);  
    await Task.Delay(100);  
    dialog.HideConfirm();  
    await Task.Delay(100);  
    dialog.Show("Show Popup2", null, null, null);  
});  
 
We have prepared the sample as per your requirement, you can download the same from the below link.  
 
Regards,  
Vigneshkumar R  


Loader.
Up arrow icon