diff options
| author | 魏曹先生 <1992414357@qq.com> | 2026-06-22 07:21:10 +0800 |
|---|---|---|
| committer | 魏曹先生 <1992414357@qq.com> | 2026-06-22 07:21:10 +0800 |
| commit | 5e16ca4f41b2ae0b1e0d57be340cbf28286fe1f7 (patch) | |
| tree | 72e4afcc6b440e3121af79b245e6bd04c7398b7a /manager/MessageBox.axaml.cs | |
| parent | e6bf6f5091caf3b4366894643671bc4586794cda (diff) | |
feat(manager): implement GUI dashboard with config management
Diffstat (limited to 'manager/MessageBox.axaml.cs')
| -rw-r--r-- | manager/MessageBox.axaml.cs | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/manager/MessageBox.axaml.cs b/manager/MessageBox.axaml.cs new file mode 100644 index 0000000..3a6868b --- /dev/null +++ b/manager/MessageBox.axaml.cs @@ -0,0 +1,60 @@ +using System; +using System.Threading.Tasks; +using Avalonia; +using Avalonia.Controls; + +namespace manager; + +public enum MessageBoxResult +{ + Ok, + Yes, + No, + Cancel, +} + +public partial class MessageBox : Window +{ + public static readonly StyledProperty<string> TextProperty = + AvaloniaProperty.Register<MessageBox, string>(nameof(Text)); + + public string Text + { + get => GetValue(TextProperty); + set => SetValue(TextProperty, value); + } + + public MessageBox() + { + InitializeComponent(); + } + + protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change) + { + base.OnPropertyChanged(change); + if (change.Property == TextProperty) + MessageText.Text = change.NewValue as string ?? ""; + } + + public void AddButtons(params (string text, MessageBoxResult result)[] buttons) + { + foreach (var (text, result) in buttons) + { + var btn = new Button { Content = text, Width = 80 }; + btn.Click += (_, _) => Close(result); + ButtonPanel.Children.Add(btn); + } + } + + public static Task<MessageBoxResult> Show(Window owner, string text, string title, + params (string text, MessageBoxResult result)[] buttons) + { + var msgBox = new MessageBox + { + Title = title, + Text = text, + }; + msgBox.AddButtons(buttons); + return msgBox.ShowDialog<MessageBoxResult>(owner); + } +} |
