Files
Wino-Mail/Wino.Core.UWP/Dialogs/BaseAccountCreationDialog.cs

61 lines
2.0 KiB
C#
Raw Normal View History

using System.Threading;
using Windows.UI.Xaml;
2024-04-18 01:44:37 +02:00
using Windows.UI.Xaml.Controls;
using Wino.Core.Domain.Enums;
using Wino.Core.Domain.Interfaces;
namespace Wino.Dialogs
{
public abstract class BaseAccountCreationDialog : ContentDialog, IAccountCreationDialog
{
public AccountCreationDialogState State
{
get { return (AccountCreationDialogState)GetValue(StateProperty); }
set { SetValue(StateProperty, value); }
}
public CancellationTokenSource CancellationTokenSource { get; private set; }
public static readonly DependencyProperty StateProperty = DependencyProperty.Register(nameof(State), typeof(AccountCreationDialogState), typeof(BaseAccountCreationDialog), new PropertyMetadata(AccountCreationDialogState.Idle, OnStateChanged));
private static void OnStateChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var dialog = d as BaseAccountCreationDialog;
dialog.OnStateChanged((AccountCreationDialogState)e.NewValue);
}
public abstract void OnStateChanged(AccountCreationDialogState state);
2024-04-18 01:44:37 +02:00
// Prevent users from dismissing it by ESC key.
public void DialogClosing(ContentDialog sender, ContentDialogClosingEventArgs args)
2024-04-18 01:44:37 +02:00
{
if (args.Result == ContentDialogResult.None)
{
args.Cancel = true;
}
}
public void ShowDialog(CancellationTokenSource cancellationTokenSource)
2024-04-18 01:44:37 +02:00
{
CancellationTokenSource = cancellationTokenSource;
2024-04-18 01:44:37 +02:00
_ = ShowAsync();
}
public void Complete(bool cancel)
2024-04-18 01:44:37 +02:00
{
State = cancel ? AccountCreationDialogState.Canceled : AccountCreationDialogState.Completed;
2024-04-18 01:44:37 +02:00
// Unregister from closing event.
Closing -= DialogClosing;
if (cancel && !CancellationTokenSource.IsCancellationRequested)
2024-04-18 01:44:37 +02:00
{
CancellationTokenSource.Cancel();
2024-04-18 01:44:37 +02:00
}
Hide();
}
2024-04-18 01:44:37 +02:00
}
}