feat: add overlay dialog sample.

This commit is contained in:
rabbitism
2024-01-22 18:32:24 +08:00
parent 5c62131a0a
commit f0ec32c870
10 changed files with 139 additions and 9 deletions

View File

@@ -27,18 +27,36 @@ public class DialogControl: ContentControl
{
_closeButton.Click += Close;
}
}
public void Show()
if (this.DataContext is IDialogContext context)
{
context.Closed += Close;
}
}
public Task<T> ShowAsync<T>()
{
var tcs = new TaskCompletionSource<T>();
this.OnClose+= (sender, args) =>
{
if (args is T result)
{
tcs.SetResult(result);
}
else
{
tcs.SetResult(default);
}
};
return tcs.Task;
}
private void Close(object sender, object args)
{
if (this.DataContext is IDialogContext context)
{
OnClose?.Invoke(this, context.DefaultCloseResult);
OnClose?.Invoke(this, args);
}
else
{