feat: ultimate refactoring to separate default dialog and custom dialog.

This commit is contained in:
rabbitism
2024-01-25 00:50:27 +08:00
parent a17f1076d0
commit 430dccc958
16 changed files with 605 additions and 255 deletions

View File

@@ -0,0 +1,133 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.Metadata;
using Avalonia.Controls.Primitives;
using Avalonia.Input;
using Avalonia.Interactivity;
using Ursa.Common;
namespace Ursa.Controls;
[TemplatePart(PART_OKButton, typeof(Button))]
[TemplatePart(PART_CancelButton, typeof(Button))]
[TemplatePart(PART_YesButton, typeof(Button))]
[TemplatePart(PART_NoButton, typeof(Button))]
[TemplatePart(PART_TitleArea, typeof(Panel))]
public class DefaultDialogControl: DialogControl
{
public const string PART_OKButton = "PART_OKButton";
public const string PART_CancelButton = "PART_CancelButton";
public const string PART_YesButton = "PART_YesButton";
public const string PART_NoButton = "PART_NoButton";
private Button? _okButton;
private Button? _cancelButton;
private Button? _yesButton;
private Button? _noButton;
public static readonly StyledProperty<string?> TitleProperty = AvaloniaProperty.Register<DefaultDialogControl, string?>(
nameof(Title));
public string? Title
{
get => GetValue(TitleProperty);
set => SetValue(TitleProperty, value);
}
public static readonly StyledProperty<DialogButton> ButtonsProperty = AvaloniaProperty.Register<DefaultDialogControl, DialogButton>(
nameof(Buttons));
public DialogButton Buttons
{
get => GetValue(ButtonsProperty);
set => SetValue(ButtonsProperty, value);
}
public static readonly StyledProperty<DialogIcon> IconProperty = AvaloniaProperty.Register<DefaultDialogControl, DialogIcon>(
nameof(Icon));
public DialogIcon Icon
{
get => GetValue(IconProperty);
set => SetValue(IconProperty, value);
}
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
{
base.OnApplyTemplate(e);
EventHelper.UnregisterClickEvent(DefaultButtonsClose, _okButton, _cancelButton, _yesButton, _noButton);
_okButton = e.NameScope.Find<Button>(PART_OKButton);
_cancelButton = e.NameScope.Find<Button>(PART_CancelButton);
_yesButton = e.NameScope.Find<Button>(PART_YesButton);
_noButton = e.NameScope.Find<Button>(PART_NoButton);
EventHelper.RegisterClickEvent(DefaultButtonsClose, _yesButton, _noButton, _okButton, _cancelButton);
SetButtonVisibility();
}
private void SetButtonVisibility()
{
switch (Buttons)
{
case DialogButton.None:
SetVisibility(_okButton, false);
SetVisibility(_cancelButton, false);
SetVisibility(_yesButton, false);
SetVisibility(_noButton, false);
break;
case DialogButton.OK:
SetVisibility(_okButton, true);
SetVisibility(_cancelButton, false);
SetVisibility(_yesButton, false);
SetVisibility(_noButton, false);
break;
case DialogButton.OKCancel:
SetVisibility(_okButton, true);
SetVisibility(_cancelButton, true);
SetVisibility(_yesButton, false);
SetVisibility(_noButton, false);
break;
case DialogButton.YesNo:
SetVisibility(_okButton, false);
SetVisibility(_cancelButton, false);
SetVisibility(_yesButton, true);
SetVisibility(_noButton, true);
break;
case DialogButton.YesNoCancel:
SetVisibility(_okButton, false);
SetVisibility(_cancelButton, true);
SetVisibility(_yesButton, true);
SetVisibility(_noButton, true);
break;
}
}
private void SetVisibility(Button? button, bool visible)
{
if (button is not null) button.IsVisible = visible;
}
private void DefaultButtonsClose(object sender, RoutedEventArgs args)
{
if (sender is Button button)
{
if (button == _okButton)
{
OnDialogControlClosing(this, DialogResult.OK);
}
else if (button == _cancelButton)
{
OnDialogControlClosing(this, DialogResult.Cancel);
}
else if (button == _yesButton)
{
OnDialogControlClosing(this, DialogResult.Yes);
}
else if (button == _noButton)
{
OnDialogControlClosing(this, DialogResult.No);
}
}
}
}

View File

@@ -0,0 +1,125 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.Metadata;
using Avalonia.Controls.Primitives;
using Avalonia.Interactivity;
using Ursa.Common;
namespace Ursa.Controls;
[TemplatePart(PART_YesButton, typeof(Button))]
[TemplatePart(PART_NoButton, typeof(Button))]
[TemplatePart(PART_OKButton, typeof(Button))]
[TemplatePart(PART_CancelButton, typeof(Button))]
public class DefaultDialogWindow: DialogWindow
{
protected override Type StyleKeyOverride { get; } = typeof(DefaultDialogWindow);
public const string PART_YesButton = "PART_YesButton";
public const string PART_NoButton = "PART_NoButton";
public const string PART_OKButton = "PART_OKButton";
public const string PART_CancelButton = "PART_CancelButton";
private Button? _yesButton;
private Button? _noButton;
private Button? _okButton;
private Button? _cancelButton;
public static readonly StyledProperty<DialogButton> ButtonsProperty = AvaloniaProperty.Register<DefaultDialogWindow, DialogButton>(
nameof(Buttons));
public DialogButton Buttons
{
get => GetValue(ButtonsProperty);
set => SetValue(ButtonsProperty, value);
}
public new static readonly StyledProperty<DialogIcon> IconProperty = AvaloniaProperty.Register<DefaultDialogWindow, DialogIcon>(
nameof(Icon));
public new DialogIcon Icon
{
get => GetValue(IconProperty);
set => SetValue(IconProperty, value);
}
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
{
base.OnApplyTemplate(e);
EventHelper.UnregisterClickEvent(OnDefaultClose, _okButton, _cancelButton, _yesButton, _noButton);
_okButton = e.NameScope.Find<Button>(PART_OKButton);
_cancelButton = e.NameScope.Find<Button>(PART_CancelButton);
_yesButton = e.NameScope.Find<Button>(PART_YesButton);
_noButton = e.NameScope.Find<Button>(PART_NoButton);
EventHelper.RegisterClickEvent(OnDefaultClose, _yesButton, _noButton, _okButton, _cancelButton);
SetButtonVisibility();
}
private void OnDefaultClose(object sender, RoutedEventArgs e)
{
if (sender == _yesButton)
{
Close(DialogResult.Yes);
return;
}
if(sender == _noButton)
{
Close(DialogResult.No);
return;
}
if(sender == _okButton)
{
Close(DialogResult.OK);
return;
}
if(sender == _cancelButton)
{
Close(DialogResult.Cancel);
return;
}
}
private void SetButtonVisibility()
{
switch (Buttons)
{
case DialogButton.None:
SetVisibility(_okButton, false);
SetVisibility(_cancelButton, false);
SetVisibility(_yesButton, false);
SetVisibility(_noButton, false);
break;
case DialogButton.OK:
SetVisibility(_okButton, true);
SetVisibility(_cancelButton, false);
SetVisibility(_yesButton, false);
SetVisibility(_noButton, false);
break;
case DialogButton.OKCancel:
SetVisibility(_okButton, true);
SetVisibility(_cancelButton, true);
SetVisibility(_yesButton, false);
SetVisibility(_noButton, false);
break;
case DialogButton.YesNo:
SetVisibility(_okButton, false);
SetVisibility(_cancelButton, false);
SetVisibility(_yesButton, true);
SetVisibility(_noButton, true);
break;
case DialogButton.YesNoCancel:
SetVisibility(_okButton, false);
SetVisibility(_cancelButton, true);
SetVisibility(_yesButton, true);
SetVisibility(_noButton, true);
break;
}
}
private void SetVisibility(Button? button, bool visible)
{
if (button is not null) button.IsVisible = visible;
}
}

View File

@@ -3,79 +3,162 @@ using Avalonia.Controls;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Controls.Shapes;
using Avalonia.Media;
using Ursa.Common;
namespace Ursa.Controls;
public static class Dialog
{
public static async Task<TResult?> ShowModalAsync<TView, TViewModel, TResult>(TViewModel vm)
/// <summary>
/// Show a Window Modal Dialog that with all content fully customized.
/// </summary>
/// <param name="vm"></param>
/// <typeparam name="TView"></typeparam>
/// <typeparam name="TViewModel"></typeparam>
/// <typeparam name="TResult"></typeparam>
/// <returns></returns>
public static async Task<TResult?> ShowCustomModalAsync<TView, TViewModel, TResult>(TViewModel vm)
where TView : Control, new()
{
var lifetime = Application.Current?.ApplicationLifetime;
if (lifetime is IClassicDesktopStyleApplicationLifetime classLifetime)
{
var window = new DialogWindow
{
Content = new TView { DataContext = vm },
DataContext = vm,
};
if (classLifetime.MainWindow is not { } main)
{
window.Show();
return default;
}
var result = await window.ShowDialog<TResult>(main);
return result;
}
return default(TResult);
var mainWindow = GetMainWindow();
return await ShowCustomModalAsync<TView, TViewModel, TResult>(mainWindow, vm);
}
public static async Task<TResult> ShowModalAsync<TView, TViewModel, TResult>(Window owner, TViewModel? vm)
/// <summary>
/// Show a Window Modal Dialog that with all content fully customized. And the owner of the dialog is specified.
/// </summary>
/// <param name="owner"></param>
/// <param name="vm"></param>
/// <typeparam name="TView"></typeparam>
/// <typeparam name="TViewModel"></typeparam>
/// <typeparam name="TResult"></typeparam>
/// <returns></returns>
public static async Task<TResult> ShowCustomModalAsync<TView, TViewModel, TResult>(Window? owner, TViewModel? vm)
where TView: Control, new()
{
var window = new DialogWindow
{
Content = new TView() { DataContext = vm },
DataContext = vm
Content = new TView { DataContext = vm },
DataContext = vm,
};
return await window.ShowDialog<TResult>(owner);
if (owner is null)
{
window.Show();
return default;
}
else
{
var result = await window.ShowDialog<TResult>(owner);
return result;
}
}
public static async Task<DialogResult> ShowModalAsync<TView, TViewModel>(
Window? owner,
TViewModel vm,
string? title = null,
DialogIcon icon = DialogIcon.None,
DialogButton buttons = DialogButton.OKCancel)
where TView : Control, new()
{
var window = new DefaultDialogWindow()
{
Content = new TView() { DataContext = vm },
DataContext = vm,
Buttons = buttons,
Title = title,
Icon = icon,
};
if (owner is null)
{
window.Show();
return DialogResult.None;
}
else
{
var result = await window.ShowDialog<DialogResult>(owner);
return result;
}
}
public static async Task<DialogResult> ShowModalAsync<TView, TViewModel>(
TViewModel vm,
string? title = null,
DialogIcon icon = DialogIcon.None,
DialogButton buttons = DialogButton.OKCancel)
where TView: Control, new()
{
var mainWindow = GetMainWindow();
return await ShowModalAsync<TView, TViewModel>(mainWindow, vm, title, icon, buttons);
}
private static Window? GetMainWindow()
{
var lifetime = Application.Current?.ApplicationLifetime;
return lifetime is IClassicDesktopStyleApplicationLifetime { MainWindow: { } w } ? w : null;
}
}
public static class OverlayDialog
{
public static Task<TResult> ShowModalAsync<TView, TViewModel, TResult>(TViewModel vm, string? hostId = null)
public static Task<DialogResult> ShowModalAsync<TView, TViewModel>(
TViewModel vm,
string? hostId = null,
string? title = null,
DialogIcon icon = DialogIcon.None,
DialogButton buttons = DialogButton.OKCancel)
where TView : Control, new()
{
var t = new DialogControl()
var t = new DefaultDialogControl()
{
Content = new TView(){ DataContext = vm },
DataContext = vm,
Buttons = buttons,
Title = title,
Icon = icon,
};
var host = OverlayDialogManager.GetHost(hostId);
host?.AddModalDialog(t);
return t.ShowAsync<TResult>();
return t.ShowAsync<DialogResult>();
}
public static Task<TResult> ShowModalAsync<TView, TViewModel, TResult>(TViewModel vm, DialogOptions options, string? hostId = null)
where TView : Control, new()
public static Task<TResult> ShowCustomModalAsync<TView, TViewModel, TResult>(
TViewModel vm,
string? hostId = null)
where TView: Control, new()
{
var t = new DialogControl()
{
Content = new TView() { DataContext = vm },
DataContext = vm,
ExtendToClientArea = options.ExtendToClientArea,
Title = options.Title,
Buttons = options.DefaultButtons,
};
var host = OverlayDialogManager.GetHost(hostId);
host?.AddModalDialog(t);
return t.ShowAsync<TResult>();
}
public static void Show<TView, TViewModel>(TViewModel vm, string? hostId = null)
public static void Show<TView, TViewModel>(
TViewModel vm,
string? hostId = null,
string? title = null,
DialogIcon icon = DialogIcon.None,
DialogButton buttons = DialogButton.OKCancel)
where TView: Control, new()
{
var t = new DefaultDialogControl()
{
Content = new TView() { DataContext = vm },
DataContext = vm,
Buttons = buttons,
Title = title,
Icon = icon,
};
var host = OverlayDialogManager.GetHost(hostId);
host?.AddDialog(t);
}
public static void ShowCustom<TView, TViewModel>(TViewModel vm, string? hostId = null)
where TView: Control, new()
{
var t = new DialogControl()
@@ -86,19 +169,5 @@ public static class OverlayDialog
var host = OverlayDialogManager.GetHost(hostId);
host?.AddDialog(t);
}
public static void Show<TView, TViewModel>(TViewModel vm, DialogOptions options, string? hostId)
where TView: Control, new()
{
var t = new DialogControl()
{
Content = new TView() { DataContext = vm },
DataContext = vm,
ExtendToClientArea = options.ExtendToClientArea,
Title = options.Title,
Buttons = options.DefaultButtons,
};
var host = OverlayDialogManager.GetHost(hostId);
host?.AddModalDialog(t);
}
}

View File

@@ -1,4 +1,4 @@
using Avalonia;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.Metadata;
using Avalonia.Controls.Primitives;
@@ -9,57 +9,22 @@ using Ursa.Common;
namespace Ursa.Controls;
[TemplatePart(PART_CloseButton, typeof(Button))]
[TemplatePart(PART_OKButton, typeof(Button))]
[TemplatePart(PART_CancelButton, typeof(Button))]
[TemplatePart(PART_YesButton, typeof(Button))]
[TemplatePart(PART_NoButton, typeof(Button))]
[TemplatePart(PART_TitleArea, typeof(Panel))]
[PseudoClasses(PC_ExtendClientArea)]
[PseudoClasses(PC_Modal)]
public class DialogControl: ContentControl
{
public const string PART_CloseButton = "PART_CloseButton";
public const string PART_OKButton = "PART_OKButton";
public const string PART_CancelButton = "PART_CancelButton";
public const string PART_YesButton = "PART_YesButton";
public const string PART_NoButton = "PART_NoButton";
public const string PART_TitleArea = "PART_TitleArea";
public const string PC_ExtendClientArea = ":extend";
public const string PC_Modal = ":modal";
private Button? _closeButton;
private Button? _okButton;
private Button? _cancelButton;
private Button? _yesButton;
private Button? _noButton;
private Panel? _titleArea;
public event EventHandler<object?>? OnDialogControlClose;
public event EventHandler<DialogLayerChangeEventArgs>? OnLayerChange;
public static readonly StyledProperty<string?> TitleProperty = AvaloniaProperty.Register<DialogControl, string?>(
nameof(Title));
public string? Title
{
get => GetValue(TitleProperty);
set => SetValue(TitleProperty, value);
}
public static readonly StyledProperty<bool> ExtendToClientAreaProperty = AvaloniaProperty.Register<DialogControl, bool>(
nameof(ExtendToClientArea));
public bool ExtendToClientArea
{
get => GetValue(ExtendToClientAreaProperty);
set => SetValue(ExtendToClientAreaProperty, value);
}
internal DialogButton Buttons { get; set; }
public event EventHandler<DialogLayerChangeEventArgs>? LayerChanged;
public event EventHandler<object?>? DialogControlClosing;
static DialogControl()
{
DataContextProperty.Changed.AddClassHandler<DialogControl, object?>((o, e) => o.OnDataContextChange(e));
ExtendToClientAreaProperty.Changed.AddClassHandler<DialogControl, bool>((o, e) => o.PseudoClasses.Set(PC_ExtendClientArea, e.NewValue.Value));
}
private void OnDataContextChange(AvaloniaPropertyChangedEventArgs<object?> args)
@@ -79,81 +44,18 @@ public class DialogControl: ContentControl
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
{
base.OnApplyTemplate(e);
UnRegisterClickEvent(Close, _closeButton);
UnRegisterClickEvent(DefaultButtonsClose, _okButton, _cancelButton, _yesButton, _noButton);
EventHelper.UnregisterClickEvent(Close, _closeButton);
_titleArea?.RemoveHandler(PointerMovedEvent, OnTitlePointerMove);
_titleArea?.RemoveHandler(PointerPressedEvent, OnTitlePointerPressed);
_closeButton = e.NameScope.Find<Button>(PART_CloseButton);
_titleArea = e.NameScope.Find<Panel>(PART_TitleArea);
_okButton = e.NameScope.Find<Button>(PART_OKButton);
_cancelButton = e.NameScope.Find<Button>(PART_CancelButton);
_yesButton = e.NameScope.Find<Button>(PART_YesButton);
_noButton = e.NameScope.Find<Button>(PART_NoButton);
_titleArea?.AddHandler(PointerMovedEvent, OnTitlePointerMove, RoutingStrategies.Bubble);
_titleArea?.AddHandler(PointerPressedEvent, OnTitlePointerPressed, RoutingStrategies.Bubble);
RegisterClickEvent(Close, _closeButton);
RegisterClickEvent(DefaultButtonsClose, _yesButton, _noButton, _okButton, _cancelButton);
SetButtonVisibility();
}
private void UnRegisterClickEvent(EventHandler<RoutedEventArgs> action, params Button?[] buttons)
{
foreach (var button in buttons)
{
if(button is not null) button.Click -= action;
}
}
private void RegisterClickEvent(EventHandler<RoutedEventArgs> action, params Button?[] buttons)
{
foreach (var button in buttons)
{
if(button is not null) button.Click += action;
}
}
private void SetButtonVisibility()
{
switch (Buttons)
{
case DialogButton.None:
SetVisibility(_okButton, false);
SetVisibility(_cancelButton, false);
SetVisibility(_yesButton, false);
SetVisibility(_noButton, false);
break;
case DialogButton.OK:
SetVisibility(_okButton, true);
SetVisibility(_cancelButton, false);
SetVisibility(_yesButton, false);
SetVisibility(_noButton, false);
break;
case DialogButton.OKCancel:
SetVisibility(_okButton, true);
SetVisibility(_cancelButton, true);
SetVisibility(_yesButton, false);
SetVisibility(_noButton, false);
break;
case DialogButton.YesNo:
SetVisibility(_okButton, false);
SetVisibility(_cancelButton, false);
SetVisibility(_yesButton, true);
SetVisibility(_noButton, true);
break;
case DialogButton.YesNoCancel:
SetVisibility(_okButton, false);
SetVisibility(_cancelButton, true);
SetVisibility(_yesButton, true);
SetVisibility(_noButton, true);
break;
}
}
private void SetVisibility(Button? button, bool visible)
{
if (button is not null) button.IsVisible = visible;
EventHelper.RegisterClickEvent(Close, _closeButton);
}
private void OnTitlePointerPressed(object sender, PointerPressedEventArgs e)
@@ -170,22 +72,21 @@ public class DialogControl: ContentControl
public Task<T> ShowAsync<T>()
{
var tcs = new TaskCompletionSource<T>();
PseudoClasses.Set(PC_Modal, true);
void OnCloseHandler(object sender, object? args)
{
if (args is T result)
{
tcs.SetResult(result);
OnDialogControlClose-= OnCloseHandler;
DialogControlClosing-= OnCloseHandler;
}
else
{
tcs.SetResult(default(T));
OnDialogControlClose-= OnCloseHandler;
DialogControlClosing-= OnCloseHandler;
}
}
this.OnDialogControlClose += OnCloseHandler;
this.DialogControlClosing += OnCloseHandler;
return tcs.Task;
}
@@ -193,12 +94,11 @@ public class DialogControl: ContentControl
{
if (this.DataContext is IDialogContext context)
{
OnDialogControlClose?.Invoke(this, context.DefaultCloseResult);
context.Close();
}
else
{
OnDialogControlClose?.Invoke(this, null);
DialogControlClosing?.Invoke(this, DialogResult.None);
}
}
@@ -206,38 +106,26 @@ public class DialogControl: ContentControl
{
if (this.DataContext is IDialogContext context)
{
OnDialogControlClose?.Invoke(this, args);
}
}
private void DefaultButtonsClose(object sender, RoutedEventArgs args)
{
if (sender is Button button)
{
if (button == _okButton)
{
OnDialogControlClose?.Invoke(this, DialogResult.OK);
}
else if (button == _cancelButton)
{
OnDialogControlClose?.Invoke(this, DialogResult.Cancel);
}
else if (button == _yesButton)
{
OnDialogControlClose?.Invoke(this, DialogResult.Yes);
}
else if (button == _noButton)
{
OnDialogControlClose?.Invoke(this, DialogResult.No);
}
DialogControlClosing?.Invoke(this, args);
}
}
public void UpdateLayer(object? o)
{
if (o is DialogLayerChangeType t)
{
OnLayerChange?.Invoke(this, new DialogLayerChangeEventArgs(t));
LayerChanged?.Invoke(this, new DialogLayerChangeEventArgs(t));
}
}
protected virtual void OnDialogControlClosing(object sender, object? args)
{
DialogControlClosing?.Invoke(this, args);
}
internal void SetAsModal(bool modal)
{
PseudoClasses.Set(PC_Modal, modal);
}
}

View File

@@ -0,0 +1,11 @@
namespace Ursa.Controls;
public enum DialogIcon
{
Info,
Warning,
Error,
Question,
None,
Success,
}

View File

@@ -1,11 +0,0 @@
using Ursa.Common;
namespace Ursa.Controls;
public record DialogOptions
{
public bool ShowCloseButton { get; set; } = true;
public string? Title { get; set; }
public bool ExtendToClientArea { get; set; } = false;
public DialogButton DefaultButtons { get; set; } = DialogButton.None;
}

View File

@@ -4,6 +4,7 @@ using Avalonia.Controls.Metadata;
using Avalonia.Controls.Primitives;
using Avalonia.Input;
using Avalonia.Interactivity;
using Ursa.Common;
namespace Ursa.Controls;
@@ -25,27 +26,24 @@ public class DialogWindow: Window
{
if (args.OldValue.Value is IDialogContext oldContext)
{
oldContext.Closed-= OnDialogClose;
oldContext.Closed-= OnDialogContextClose;
}
if (args.NewValue.Value is IDialogContext newContext)
{
newContext.Closed += OnDialogClose;
newContext.Closed += OnDialogContextClose;
}
}
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
{
base.OnApplyTemplate(e);
EventHelper.UnregisterClickEvent(OnDefaultClose, _closeButton);
_closeButton = e.NameScope.Find<Button>(PART_CloseButton);
if (_closeButton != null)
{
_closeButton.Click += OnDefaultClose;
}
EventHelper.RegisterClickEvent(OnDefaultClose, _closeButton);
}
private void OnDialogClose(object? sender, object? args)
private void OnDialogContextClose(object? sender, object? args)
{
Close(args);
}
@@ -54,7 +52,7 @@ public class DialogWindow: Window
{
if (DataContext is IDialogContext context)
{
Close(context.DefaultCloseResult);
context.Close();
}
else
{

View File

@@ -2,6 +2,6 @@ namespace Ursa.Controls;
public interface IDialogContext
{
object? DefaultCloseResult { get; set; }
void Close();
event EventHandler<object?> Closed;
}

View File

@@ -11,7 +11,7 @@ namespace Ursa.Controls;
public class OverlayDialogHost : Canvas
{
private readonly List<DialogControl> _dialogs = new();
private readonly List<DialogControl> _modalDialogs = new();
private readonly List<DialogControl> _modalDialogs = new();
private readonly List<Border> _masks = new();
public string? HostId { get; set; }
@@ -63,7 +63,7 @@ public class OverlayDialogHost : Canvas
protected override void OnPointerMoved(PointerEventArgs e)
{
base.OnPointerMoved(e);
if (e.Source is DialogControl item)
if (e.Source is DefaultDialogControl item)
{
if (e.GetCurrentPoint(this).Properties.IsLeftButtonPressed)
{
@@ -94,18 +94,18 @@ public class OverlayDialogHost : Canvas
control.Measure(this.Bounds.Size);
control.Arrange(new Rect(control.DesiredSize));
SetToCenter(control);
control.OnDialogControlClose += OnDialogControlDialogClose;
control.OnLayerChange += OnDialogLayerChange;
control.DialogControlClosing += OnDialogControlClosing;
control.LayerChanged += OnDialogLayerChanged;
ResetZIndices();
}
private void OnDialogControlDialogClose(object sender, object? e)
private void OnDialogControlClosing(object sender, object? e)
{
if (sender is DialogControl control)
{
this.Children.Remove(control);
control.OnDialogControlClose -= OnDialogControlDialogClose;
control.OnLayerChange -= OnDialogLayerChange;
control.DialogControlClosing -= OnDialogControlClosing;
control.LayerChanged -= OnDialogLayerChanged;
if (_dialogs.Contains(control))
{
_dialogs.Remove(control);
@@ -137,6 +137,7 @@ public class OverlayDialogHost : Canvas
var mask = CreateOverlayMask();
_masks.Add(mask);
_modalDialogs.Add(control);
control.SetAsModal(true);
for (int i = 0; i < _masks.Count-1; i++)
{
_masks[i].Opacity = 0.5;
@@ -147,14 +148,14 @@ public class OverlayDialogHost : Canvas
control.Measure(this.Bounds.Size);
control.Arrange(new Rect(control.DesiredSize));
SetToCenter(control);
control.OnDialogControlClose += OnDialogControlDialogClose;
control.OnLayerChange += OnDialogLayerChange;
control.DialogControlClosing += OnDialogControlClosing;
control.LayerChanged += OnDialogLayerChanged;
}
// Handle dialog layer change event
private void OnDialogLayerChange(object sender, DialogLayerChangeEventArgs e)
private void OnDialogLayerChanged(object sender, DialogLayerChangeEventArgs e)
{
if (sender is not DialogControl control)
if (sender is not DefaultDialogControl control)
return;
if (!_dialogs.Contains(control))
return;