feat: WIP
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user