From 4df98148faab3dcef3b37b5a0a2425de52261cb3 Mon Sep 17 00:00:00 2001 From: Florian Stinglmayr Date: Fri, 8 Nov 2024 10:24:48 +0100 Subject: [PATCH] add Helper API to workaround shitty Avalonia API --- Avalonia.EliteBGS/Helper.cs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 Avalonia.EliteBGS/Helper.cs diff --git a/Avalonia.EliteBGS/Helper.cs b/Avalonia.EliteBGS/Helper.cs new file mode 100644 index 0000000..c6f690b --- /dev/null +++ b/Avalonia.EliteBGS/Helper.cs @@ -0,0 +1,31 @@ +using Avalonia; +using Avalonia.Controls; +using MsBox.Avalonia; + +namespace EliteBGS; + +public class Helper { + public static void MessageBox(Window owner, string caption, string text) { + var box = MessageBoxManager + .GetMessageBoxStandard(caption, text) + ; + var result = box.ShowAsPopupAsync(owner); + result.Wait(); + } + + public static string? OpenFileDialog(Window owner) { + OpenFileDialog dlg = new OpenFileDialog(); + + dlg.AllowMultiple = false; + + var result = dlg.ShowAsync(owner); + result.Wait(); + var filename = result.Result; + + if (filename == null || filename.Length <= 0) { + return null; + } + + return filename[0]; + } +}