feat: dialog: refactor to support non-generic call, add options and remove parameters.

This commit is contained in:
rabbitism
2024-02-01 19:46:36 +08:00
parent fb323e04bd
commit fb11be0169
4 changed files with 236 additions and 155 deletions

View File

@@ -0,0 +1,77 @@
using Avalonia.Controls;
using Ursa.Common;
namespace Ursa.Controls;
public static class OverlayDialog
{
public static Task<DialogResult> ShowModalAsync<TView, TViewModel>(
TViewModel vm,
string? hostId = null,
string? title = null,
DialogMode mode = DialogMode.None,
DialogButton buttons = DialogButton.OKCancel)
where TView : Control, new()
{
var t = new DefaultDialogControl()
{
Content = new TView(){ DataContext = vm },
DataContext = vm,
Buttons = buttons,
Title = title,
Mode = mode,
};
var host = OverlayDialogManager.GetHost(hostId);
host?.AddModalDialog(t);
return t.ShowAsync<DialogResult>();
}
public static Task<TResult> ShowCustomModalAsync<TView, TViewModel, TResult>(
TViewModel vm,
string? hostId = null)
where TView: Control, new()
{
var t = new DialogControl()
{
Content = new TView() { DataContext = vm },
DataContext = vm,
};
var host = OverlayDialogManager.GetHost(hostId);
host?.AddModalDialog(t);
return t.ShowAsync<TResult>();
}
public static void Show<TView, TViewModel>(
TViewModel vm,
string? hostId = null,
string? title = null,
DialogMode mode = DialogMode.None,
DialogButton buttons = DialogButton.OKCancel)
where TView: Control, new()
{
var t = new DefaultDialogControl()
{
Content = new TView() { DataContext = vm },
DataContext = vm,
Buttons = buttons,
Title = title,
Mode = mode,
};
var host = OverlayDialogManager.GetHost(hostId);
host?.AddDialog(t);
}
public static void ShowCustom<TView, TViewModel>(TViewModel vm, string? hostId = null)
where TView: Control, new()
{
var t = new DialogControl()
{
Content = new TView() { DataContext = vm },
DataContext = vm,
};
var host = OverlayDialogManager.GetHost(hostId);
host?.AddDialog(t);
}
}