using System.Threading.Tasks; using Avalonia.Controls; using Avalonia.Threading; namespace DHT.Desktop.Dialogs { public static class Dialog { public static async Task ShowOk(Window owner, string title, string message) { if (!Dispatcher.UIThread.CheckAccess()) { await Dispatcher.UIThread.InvokeAsync(() => ShowOk(owner, title, message)); return; } await new MessageDialog { DataContext = new MessageDialogModel { Title = title, Message = message, IsOkVisible = true } }.ShowDialog(owner); } public static async Task ShowOkCancel(Window owner, string title, string message) { if (!Dispatcher.UIThread.CheckAccess()) { return await Dispatcher.UIThread.InvokeAsync(() => ShowOkCancel(owner, title, message)); } var result = await new MessageDialog { DataContext = new MessageDialogModel { Title = title, Message = message, IsOkVisible = true, IsCancelVisible = true } }.ShowDialog(owner); return result.ToOkCancel(); } public static async Task ShowYesNo(Window owner, string title, string message) { if (!Dispatcher.UIThread.CheckAccess()) { return await Dispatcher.UIThread.InvokeAsync(() => ShowYesNo(owner, title, message)); } var result = await new MessageDialog { DataContext = new MessageDialogModel { Title = title, Message = message, IsYesVisible = true, IsNoVisible = true } }.ShowDialog(owner); return result.ToYesNo(); } public static async Task ShowYesNoCancel(Window owner, string title, string message) { if (!Dispatcher.UIThread.CheckAccess()) { return await Dispatcher.UIThread.InvokeAsync(() => ShowYesNoCancel(owner, title, message)); } var result = await new MessageDialog { DataContext = new MessageDialogModel { Title = title, Message = message, IsYesVisible = true, IsNoVisible = true, IsCancelVisible = true } }.ShowDialog(owner); return result.ToYesNoCancel(); } } }