feat: WIP

This commit is contained in:
rabbitism
2024-01-22 11:36:45 +08:00
parent 2c361f9f3c
commit 9cff01c032
4 changed files with 43 additions and 13 deletions

View File

@@ -1,6 +1,7 @@
using Avalonia.Controls;
using Avalonia.Controls.Metadata;
using Avalonia.Controls.Primitives;
using Avalonia.Interactivity;
namespace Ursa.Controls;
@@ -13,6 +14,24 @@ public class DialogWindow: Window
private Button? _closeButton;
protected override void OnDataContextBeginUpdate()
{
base.OnDataContextBeginUpdate();
if (DataContext is IDialogContext context)
{
context.Closed-= OnDialogClose;
}
}
protected override void OnDataContextEndUpdate()
{
base.OnDataContextEndUpdate();
if (DataContext is IDialogContext context)
{
context.Closed += OnDialogClose;
}
}
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
{
base.OnApplyTemplate(e);
@@ -20,11 +39,24 @@ public class DialogWindow: Window
if (_closeButton != null)
{
_closeButton.Click += (sender, args) =>
{
Close();
};
_closeButton.Click += OnDefaultClose;
}
}
private void OnDialogClose(object? sender, object? args)
{
Close(args);
}
private void OnDefaultClose(object sender, RoutedEventArgs args)
{
if (DataContext is IDialogContext context)
{
Close(context.DefaultCloseResult);
}
else
{
Close(null);
}
}
}