feat: add overlay dialog sample.
This commit is contained in:
@@ -47,7 +47,7 @@ public static class DialogBox
|
||||
}
|
||||
|
||||
|
||||
public static async Task<object?> ShowOverlayAsync<TView, TViewModel>(TViewModel vm, string hostId)
|
||||
public static Task<TResult> ShowOverlayAsync<TView, TViewModel, TResult>(TViewModel vm, string hostId)
|
||||
where TView : Control, new()
|
||||
where TViewModel: new()
|
||||
{
|
||||
@@ -59,6 +59,6 @@ public static class DialogBox
|
||||
t.DataContext = vm;
|
||||
var host = OverlayDialogManager.GetOverlayDialogHost(hostId);
|
||||
host?.AddDialog(t);
|
||||
return null;
|
||||
return t.ShowAsync<TResult>();
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user