mirror of
https://github.com/WinDurango/WinDurango.UI.git
synced 2026-01-31 00:55:24 +01:00
77 lines
1.9 KiB
C#
77 lines
1.9 KiB
C#
using Microsoft.UI.Xaml.Controls;
|
|
using System;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace WinDurango.UI.Dialogs
|
|
{
|
|
public class Confirmation
|
|
{
|
|
private string _content;
|
|
private string _title;
|
|
private ContentDialog _confirmationDialog;
|
|
|
|
public Confirmation(string content, string title = "Confirmation")
|
|
{
|
|
_content = content;
|
|
_title = title;
|
|
}
|
|
|
|
public async Task<Dialog.BtnClicked> Show()
|
|
{
|
|
_confirmationDialog = new ContentDialog
|
|
{
|
|
Content = _content,
|
|
Title = _title,
|
|
PrimaryButtonText = "Yes",
|
|
SecondaryButtonText = "No",
|
|
DefaultButton = ContentDialogButton.Secondary,
|
|
XamlRoot = App.MainWindow.Content.XamlRoot
|
|
};
|
|
|
|
var result = await _confirmationDialog.ShowAsync();
|
|
|
|
return result switch
|
|
{
|
|
ContentDialogResult.Primary => Dialog.BtnClicked.Yes,
|
|
ContentDialogResult.Secondary => Dialog.BtnClicked.No,
|
|
_ => throw new InvalidOperationException("Unexpected result."),
|
|
};
|
|
}
|
|
|
|
public string Content
|
|
{
|
|
get => _content;
|
|
set
|
|
{
|
|
_content = value;
|
|
UpdateDialog();
|
|
}
|
|
}
|
|
|
|
public string Title
|
|
{
|
|
get => _title;
|
|
set
|
|
{
|
|
_title = value;
|
|
UpdateDialog();
|
|
}
|
|
}
|
|
|
|
private void UpdateDialog()
|
|
{
|
|
if (_confirmationDialog != null)
|
|
{
|
|
_confirmationDialog.Content = _content;
|
|
_confirmationDialog.Title = _title;
|
|
}
|
|
}
|
|
|
|
public void Remove()
|
|
{
|
|
_confirmationDialog.Hide();
|
|
_confirmationDialog = null;
|
|
}
|
|
}
|
|
}
|