I am migrating a Xamarin project with UWP to a .NET MAUI project with WinUI 3. In my Xamarin project, I used Acr.UserDialogs.IProgressDialog and Acr.UserDialogs.UserDialogs.Instance.Alert for displaying progress dialogs and alerts. Since Acr.UserDialogs does not support platforms outside of Android, iOS, and UWP, I need to find an equivalent solution in MAUI with WinUI 3.
Here is my current UWP code:
using Acr.UserDialogs;
public class ImportDataForWin : IImportDataForWin
{
private IProgressDialog progress;
public async Task ImportData()
{
var picker = new Windows.Storage.Pickers.FileOpenPicker
{
ViewMode = Windows.Storage.Pickers.PickerViewMode.Thumbnail,
SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.PicturesLibrary
};
picker.FileTypeFilter.Add(".xlsx");
picker.FileTypeFilter.Add(".xls");
var file = await picker.PickSingleFileAsync();
if (file != null)
{
var config = new ProgressDialogConfig()
.SetTitle("Importing Data")
.SetIsDeterministic(false);
progress = UserDialogs.Instance.Progress(config);
progress.PercentComplete = 0;
progress.Show();
// Some code
var countMax = itemsToAdd.Count();
var rowCount = 0;
foreach (var item in itemsToAdd)
{
rowCount++;
await SaveData(item);
progress.PercentComplete = (rowCount * 100) / countMax;
}
progress.Hide();
UserDialogs.Instance.Alert("errorMessage");
}
}
}
How can I achieve similar functionality in MAUI with WinUI 3?
Specifically, I need help with:
Displaying a progress dialog during the data import. Showing an alert dialog when the import is complete or if there is an error.
Any guidance or code examples would be greatly appreciated.
Maui progress bar (with usage):
https://learn.microsoft.com/en-us/dotnet/api/microsoft.maui.controls.progressbar?view=net-maui-8.0
Maui pop-ups ("alerts"; actions; prompts):
https://learn.microsoft.com/en-us/dotnet/maui/user-interface/pop-ups?view=net-maui-8.0