I am trying to implement the DialogService in my application to (1) display an alert and do something with the result and (2) display a busy mask while doing background work. My dialogservice is defined in the viewmodel since I want to use this in all my viewmodels.
https://github.com/rezamohamed/SfBusyIndicator
~~(1) I am a little confused on how to use the dialogservice to do something based on the user interaction, in my code, the dialogservice appears and I return a result based on the user click, however, it seems that the dialogservice doesn't really wait for the user interaction to finish.
what I want to happen: Show Dialog -> user presses Accept or Decline -> based on that interaction do something in the caller method
private void ShowPopup()
{
var result = DisplayAlert("message from Main View Model");
ReturnMessage = result;
}
In the above case, the alertdisplays, and then immediately the ReturnMessage = result is executed (to start its empty, if i press the Show Popup again, it displays what was in the result field prior. How do I wait for user interaction?~~
(2) I would like to show the dialog from a caller method, and also close the same dialog from the caller method...like a busy indicator. I can show the alert, but I am unclear on how to close this from the caller method. There is a DialogeService.ShowDialog(...), but there isn't a simlar DialogService.CloseDialog(..) or something like that.
what I want to happen: Show Busy from a method -> same method makes api calls etc, doing busy work -> once busy work is over, close the dialog
(3) this is more me confusing myself on base classes, so I apologize in advance. Currently I am creating a Base View Model where I am using the Prism DialogService. The dependency service is injected in app.xaml.cs.
public ViewModelBase(INavigationService navigationService, IDialogService dialogService)
{
NavigationService = navigationService;
DialogService = dialogService;
}
I am only using the DialogService directly from my Base ViewModel, but since all my other viewmodels derive from this base, I have to call the base constructor as well and pass a DialogService. this feels redundant if I am going to be using the same DialogService across all my viewmodels, can I get away from not having to declare and pass the dialog service in all my derived viewmodels and only define it in my base view model, in some sense, I am asking the same for the navigation service as well.
ie. not having to pass navigationService and dialogService in every derived viewmodel because its the same. this is how I currently have it.
public MainPageViewModel(INavigationService navigationService, IDialogService dialogService)
: base(navigationService, dialogService)
{
Title = "Main Page";
}