ErrorAppletWindow.axaml.cs
1 using Avalonia.Controls; 2 using Avalonia.Interactivity; 3 using Avalonia.Threading; 4 using Ryujinx.Ava.Common.Locale; 5 using Ryujinx.Ava.UI.Windows; 6 using System.Threading.Tasks; 7 8 namespace Ryujinx.Ava.UI.Applet 9 { 10 internal partial class ErrorAppletWindow : StyleableWindow 11 { 12 private readonly Window _owner; 13 private object _buttonResponse; 14 15 public ErrorAppletWindow(Window owner, string[] buttons, string message) 16 { 17 _owner = owner; 18 Message = message; 19 DataContext = this; 20 InitializeComponent(); 21 22 int responseId = 0; 23 24 if (buttons != null) 25 { 26 foreach (string buttonText in buttons) 27 { 28 AddButton(buttonText, responseId); 29 responseId++; 30 } 31 } 32 else 33 { 34 AddButton(LocaleManager.Instance[LocaleKeys.InputDialogOk], 0); 35 } 36 } 37 38 public ErrorAppletWindow() 39 { 40 DataContext = this; 41 InitializeComponent(); 42 } 43 44 public string Message { get; set; } 45 46 private void AddButton(string label, object tag) 47 { 48 Dispatcher.UIThread.InvokeAsync(() => 49 { 50 Button button = new() { Content = label, Tag = tag }; 51 52 button.Click += Button_Click; 53 ButtonStack.Children.Add(button); 54 }); 55 } 56 57 private void Button_Click(object sender, RoutedEventArgs e) 58 { 59 if (sender is Button button) 60 { 61 _buttonResponse = button.Tag; 62 } 63 64 Close(); 65 } 66 67 public async Task<object> Run() 68 { 69 await ShowDialog(_owner); 70 71 return _buttonResponse; 72 } 73 } 74 }