feat: implement closing related features.

This commit is contained in:
rabbitism
2024-01-22 17:27:11 +08:00
parent 9cff01c032
commit 5c62131a0a
6 changed files with 70 additions and 20 deletions

View File

@@ -58,7 +58,7 @@ public static class DialogBox
};
t.DataContext = vm;
var host = OverlayDialogManager.GetOverlayDialogHost(hostId);
host?.Children.Add(t);
host?.AddDialog(t);
return null;
}
}

View File

@@ -13,15 +13,36 @@ public class DialogControl: ContentControl
private Button? _closeButton;
public event EventHandler OnClose;
public event EventHandler<object?> OnClose;
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
{
base.OnApplyTemplate(e);
if (_closeButton != null)
{
_closeButton.Click -= Close;
}
_closeButton = e.NameScope.Find<Button>(PART_CloseButton);
if (_closeButton is not null)
{
_closeButton.Click += Close;
}
}
public void Show()
{
}
private void Close(object sender, object args)
{
if (this.DataContext is IDialogContext context)
{
OnClose?.Invoke(this, context.DefaultCloseResult);
}
else
{
OnClose?.Invoke(this, null);
}
}
}

View File

@@ -1,6 +1,6 @@
namespace Ursa.Controls;
public record OverlayDialogOptions
public record DialogOptions
{
public bool ShowCloseButton { get; set; } = true;
}

View File

@@ -84,6 +84,17 @@ public class OverlayDialogHost: Canvas
public void AddDialog(DialogControl control)
{
this.Children.Add(control);
control.OnClose += OnDialogClose;
}
private void OnDialogClose(object sender, object? e)
{
if (sender is DialogControl control)
{
this.Children.Remove(control);
control.OnClose -= OnDialogClose;
}
}
public void AddModalDialog(DialogControl control)