51 lines
1.3 KiB
C#
51 lines
1.3 KiB
C#
using Avalonia.Controls;
|
|
using Avalonia.Interactivity;
|
|
|
|
namespace OTSSignsOrchestrator.Desktop.Views;
|
|
|
|
/// <summary>
|
|
/// A simple Yes/No confirmation dialog that can be shown modally.
|
|
/// Use <see cref="ShowAsync"/> for a convenient one-liner.
|
|
/// </summary>
|
|
public partial class ConfirmationDialog : Window
|
|
{
|
|
public bool Result { get; private set; }
|
|
|
|
public ConfirmationDialog()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
public ConfirmationDialog(string title, string message) : this()
|
|
{
|
|
TitleText.Text = title;
|
|
MessageText.Text = message;
|
|
Title = title;
|
|
|
|
ConfirmButton.Click += OnConfirmClicked;
|
|
CancelButton.Click += OnCancelClicked;
|
|
}
|
|
|
|
private void OnConfirmClicked(object? sender, RoutedEventArgs e)
|
|
{
|
|
Result = true;
|
|
Close();
|
|
}
|
|
|
|
private void OnCancelClicked(object? sender, RoutedEventArgs e)
|
|
{
|
|
Result = false;
|
|
Close();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Shows a modal confirmation dialog and returns true if the user confirmed.
|
|
/// </summary>
|
|
public static async Task<bool> ShowAsync(Window owner, string title, string message)
|
|
{
|
|
var dialog = new ConfirmationDialog(title, message);
|
|
await dialog.ShowDialog(owner);
|
|
return dialog.Result;
|
|
}
|
|
}
|