feat: set result.
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Controls.Metadata;
|
||||
using Avalonia.Controls.Primitives;
|
||||
@@ -11,7 +12,26 @@ public class DialogControl: ContentControl
|
||||
public const string PART_CloseButton = "PART_CloseButton";
|
||||
|
||||
private Button? _closeButton;
|
||||
public event EventHandler<object?> OnClose;
|
||||
public event EventHandler<object?>? OnClose;
|
||||
|
||||
static DialogControl()
|
||||
{
|
||||
DataContextProperty.Changed.AddClassHandler<DialogControl, object?>((o, e) => o.OnDataContextChange(e));
|
||||
}
|
||||
|
||||
private void OnDataContextChange(AvaloniaPropertyChangedEventArgs<object?> args)
|
||||
{
|
||||
if (args.OldValue.Value is IDialogContext oldContext)
|
||||
{
|
||||
oldContext.Closed-= Close;
|
||||
}
|
||||
|
||||
if (args.NewValue.Value is IDialogContext newContext)
|
||||
{
|
||||
newContext.Closed += Close;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
|
||||
{
|
||||
@@ -25,11 +45,6 @@ public class DialogControl: ContentControl
|
||||
{
|
||||
_closeButton.Click += Close;
|
||||
}
|
||||
|
||||
if (this.DataContext is IDialogContext context)
|
||||
{
|
||||
context.Closed += Close;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user