I’m new to Avalonia UI, I’m building simple app and am using MessageBox.Avalonia.
I want to write a service for showing dialogs.
I came up with this:
public class UserDialogService {
public async Task<ButtonResult> ShowDialog(string title, string message, ButtonEnum button = ButtonEnum.Ok) {
var dialog = MessageBoxManager.GetMessageBoxStandard(title, message, button);
var result = await dialog.ShowAsync();
return result;
}
}
My problem is that this MessageBox freezes and it’s buttons cannot be clicked.
I’m using it like that:
try {
CreateAppDirectoryIfNotExists();
Settings = DbSettings.ReadDbSettings();
} catch (Exception exc) {
if (exc is ConfigurationException) {
var result = DialogService.ShowDialog("Configuration Error", "The configuration file was not found or was invalid. Should default configuration be written?", ButtonEnum.YesNo).GetAwaiter().GetResult();
if (result == ButtonResult.Yes) {
Settings = new DbSettings();
Settings.WriteDbSettings();
}
}
throw new Exception("Failed to setup application.", exc);
}
I’ve tried to modify the service to launch dialog.ShowAsync()
in new thread using Task.Run()
but nothing was shown.
What am I doing wrong?