Files
Wino-Mail/Wino.Mail/Dialogs/BaseAccountCreationDialog.cs
2024-07-12 02:29:17 +02:00

59 lines
1.6 KiB
C#

using Wino.Core.Domain.Enums;
using Wino.Core.Domain.Interfaces;
#if NET8_0
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
#else
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
#endif
namespace Wino.Dialogs
{
public abstract class BaseAccountCreationDialog : ContentDialog, IAccountCreationDialog
{
public AccountCreationDialogState State
{
get { return (AccountCreationDialogState)GetValue(StateProperty); }
set { SetValue(StateProperty, value); }
}
public static readonly DependencyProperty StateProperty = DependencyProperty.Register(nameof(State), typeof(AccountCreationDialogState), typeof(BaseAccountCreationDialog), new PropertyMetadata(AccountCreationDialogState.Idle, OnStateChanged));
// Prevent users from dismissing it by ESC key.
private void DialogClosing(ContentDialog sender, ContentDialogClosingEventArgs args)
{
if (args.Result == ContentDialogResult.None)
{
args.Cancel = true;
}
}
public void ShowDialog()
{
_ = ShowAsync();
}
public void Complete()
{
State = AccountCreationDialogState.Completed;
// Unregister from closing event.
Closing -= DialogClosing;
Hide();
}
private static void OnStateChanged(DependencyObject obj, DependencyPropertyChangedEventArgs args)
{
if (obj is BaseAccountCreationDialog dialog)
{
dialog.UpdateState();
}
}
public abstract void UpdateState();
}
}