Hello,
I'm able to successfully set up a Xamarin Forms popup from the sample code here. If I add this to a single Xaml page, I'm able to get the popup to open/close from the code-behind.
However I'm going to be using this in multiple areas of my application and wanted to see if it's possible to run this through a service. To be specific, I want to use this to act like a busy indicator, to display an animated icon while data is loading, then close when done. I'm trying to replicate this same type of functionality we're already using with another popup Rg.Plugins.Popup. The difference with Telerik's version is that I want to see if I can avoid having to put the popup Xaml on every one of my pages.
Here's a service we're currently using.
01.
public
class
PopupService : IPopupService
02.
{
03.
private
LoadingPopup indicatorPopup;
04.
05.
//Get a new instance of the page that contains the popup Xaml
06.
public
LoadingPopup IndicatorPopup {
get
{
return
indicatorPopup ?? (indicatorPopup =
new
LoadingPopup()); } }
07.
08.
public
async Task ShowIndicatorAsync()
09.
{
10.
Device.BeginInvokeOnMainThread(async () =>
11.
{
12.
//Open the popup from that page
13.
await PopupNavigation.Instance.PushAsync(IndicatorPopup,
false
);
14.
});
15.
}
16.
17.
public
async Task DismissIndicatorAsync()
18.
{
19.
Device.BeginInvokeOnMainThread(async () =>
20.
{
21.
//Close the popup from that page
22.
await PopupNavigation.Instance.RemovePageAsync(IndicatorPopup,
false
);
23.
});
24.
}
25.
}
The popups are called in the ViewModels by using the service like this.
01.
public
class
SamplePageViewModel : BaseViewModel
02.
{
03.
private
readonly
IFinancialDataService _financialDataService;
04.
05.
public
SamplePageViewModel (IFinancialDataService financialDataService, IPopupService popupService) :
base
(popupService)
06.
{
07.
_financialDataService = financialDataService;
08.
}
09.
10.
public
async Task Init()
11.
{
12.
try
13.
{
14.
//Show popup here
15.
await PopupService.ShowIndicatorAsync();
1617.
var data = await _financialDataService.GetData();
18.
...
19.
}
20.
catch
(Exception e)
21.
{
22.
...
23.
}
24.
finally
25.
{
26.
//Close popup here
27.
await PopupService.DismissIndicatorAsync();
28.
}
29.
}
30.
}
So what I'm trying to do is put the Telerik popup Xaml in a Content Page and call it through the service instead.
I can add public methods to the code-behind of that page like this.
01.
public
void
ShowPopup()
02.
{
03.
popup.IsOpen =
true
;
04.
}
05.
06.
public
void
ClosePopup()
07.
{
08.
popup.IsOpen =
false
;
09.
}
Then I can call those methods from my same service like this instead.
01.
public
async Task ShowIndicatorAsync()
02.
{
03.
Device.BeginInvokeOnMainThread(async () =>
04.
{
05.
//Now call the open method in the code-behind
06.
IndicatorPopup.ShowPopup();
07.
});
08.
}
09.
10.
public
async Task DismissIndicatorAsync()
11.
{
12.
Device.BeginInvokeOnMainThread(async () =>
13.
{
14.
//Now call the close method in the code-behind
15.
IndicatorPopup.ClosePopup();
16.
});
17.
}
When I do this, I can actually see the Telerik popup's semi-transparent background opening and closing, but can't see my indicator, or anything else I put inside the popup. I can only see it if it's run on a single page. Any suggestions on how to implement something similar with the Telerik popup?