feat: implement closing related features.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
namespace Ursa.Controls;
|
||||
|
||||
public record OverlayDialogOptions
|
||||
public record DialogOptions
|
||||
{
|
||||
public bool ShowCloseButton { get; set; } = true;
|
||||
}
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user