I created a Win UI 3 application with multiple pages using MVVM.
sample Page.Xaml.cs:
public sealed partial class InformationPage : Page
{
public InformationViewModel ViewModel
{
get;
}
public InformationPage()
{
ViewModel = App.GetService<InformationViewModel>();
InitializeComponent();
}
}
sample ViewModel.cs:
public partial class InformationViewModel : ObservableRecipient, INavigationAware
{
private readonly IDetails _DetailsService;
public Core.Models.InformationModel? Information;
public ObservableCollection<Core.Models.DetailsModel> Source
{
get;
} = new ObservableCollection<Core.Models.DetailsModel>();
public InformationViewModel(IDetails DetailsService)
{
_DetailsService = DetailsService;
}
public void OnNavigatedFrom()
{
}
public async void OnNavigatedToAsync(object parameter)
{
var data = await _DetailsService.GetDetailsAsync(Views.ShellPage.CurrentMID, Views.ShellPage.CurrentPID);
if (!Source.Any() || Source[0] != data)
{
Source.Clear();
Source.Add(data);
Views.ShellPage.Details = Source[0];
}
if (Views.ShellPage.Details != null)
{
Information = Views.ShellPage.Details.Information;
}
}
Each page parses different queries from a server and some pages require multiple queries.
The server is slow in responding, each query usually takes between 1 - 7 seconds and multiple queries sometimes reach one minute of wait time.
Querying the data happens at ViewModel. When navigation to a page is triggered, it first requests the data and after receiving it, the application will show the selected page.
During this time, the application seems frozen or bugged and nothing works. it may seem there is a problem with the application, so I have decided to show a loading screen while this happens to inform the user that something is going on and the application is doing its work.
so I tried using a ContentDialog and removed all buttons with just a text and an indeterminate progress bar. but ContentDialog does have a DefualtButton property which triggers when pressing Enter key, so the application crashes, while this dialog is showing, or the dialog closes if I define it.
The goal is to show the user a loading screen while blocking it from interacting with other parts of the application until ViewModel has finished receiving the data, on which it will be automatically dismissed.
What solution should I try?