feat: OverlayDialogHost remake: support host with same id in different toplevel. support modal status propagation.
This commit is contained in:
@@ -8,14 +8,14 @@ namespace Ursa.Controls;
|
||||
public static class Drawer
|
||||
{
|
||||
public static void Show<TView, TViewModel>(TViewModel vm, string? hostId = null, DrawerOptions? options = null)
|
||||
where TView: Control, new()
|
||||
where TView : Control, new()
|
||||
{
|
||||
var host = OverlayDialogManager.GetHost(hostId);
|
||||
var host = OverlayDialogManager.GetHost(hostId, options?.TopLevelHashCode);
|
||||
if (host is null) return;
|
||||
var drawer = new DefaultDrawerControl()
|
||||
var drawer = new DefaultDrawerControl
|
||||
{
|
||||
Content = new TView(),
|
||||
DataContext = vm,
|
||||
DataContext = vm
|
||||
};
|
||||
ConfigureDefaultDrawer(drawer, options);
|
||||
host.AddDrawer(drawer);
|
||||
@@ -24,12 +24,12 @@ public static class Drawer
|
||||
public static void Show(Control control, object? vm, string? hostId = null,
|
||||
DrawerOptions? options = null)
|
||||
{
|
||||
var host = OverlayDialogManager.GetHost(hostId);
|
||||
var host = OverlayDialogManager.GetHost(hostId, options?.TopLevelHashCode);
|
||||
if (host is null) return;
|
||||
var drawer = new DefaultDrawerControl()
|
||||
var drawer = new DefaultDrawerControl
|
||||
{
|
||||
Content = control,
|
||||
DataContext = vm,
|
||||
DataContext = vm
|
||||
};
|
||||
ConfigureDefaultDrawer(drawer, options);
|
||||
host.AddDrawer(drawer);
|
||||
@@ -37,29 +37,30 @@ public static class Drawer
|
||||
|
||||
public static void Show(object? vm, string? hostId = null, DrawerOptions? options = null)
|
||||
{
|
||||
var host = OverlayDialogManager.GetHost(hostId);
|
||||
var host = OverlayDialogManager.GetHost(hostId, options?.TopLevelHashCode);
|
||||
if (host is null) return;
|
||||
var view = host.GetDataTemplate(vm)?.Build(vm);
|
||||
if (view is null) view = new ContentControl() { Padding = new Thickness(24) };
|
||||
if (view is null) view = new ContentControl { Padding = new Thickness(24) };
|
||||
view.DataContext = vm;
|
||||
var drawer = new DefaultDrawerControl()
|
||||
var drawer = new DefaultDrawerControl
|
||||
{
|
||||
Content = view,
|
||||
DataContext = vm,
|
||||
DataContext = vm
|
||||
};
|
||||
ConfigureDefaultDrawer(drawer, options);
|
||||
host.AddDrawer(drawer);
|
||||
}
|
||||
|
||||
public static Task<DialogResult> ShowModal<TView, TViewModel>(TViewModel vm, string? hostId = null, DrawerOptions? options = null)
|
||||
where TView: Control, new()
|
||||
|
||||
public static Task<DialogResult> ShowModal<TView, TViewModel>(TViewModel vm, string? hostId = null,
|
||||
DrawerOptions? options = null)
|
||||
where TView : Control, new()
|
||||
{
|
||||
var host = OverlayDialogManager.GetHost(hostId);
|
||||
var host = OverlayDialogManager.GetHost(hostId, options?.TopLevelHashCode);
|
||||
if (host is null) return Task.FromResult(DialogResult.None);
|
||||
var drawer = new DefaultDrawerControl()
|
||||
var drawer = new DefaultDrawerControl
|
||||
{
|
||||
Content = new TView(),
|
||||
DataContext = vm,
|
||||
DataContext = vm
|
||||
};
|
||||
ConfigureDefaultDrawer(drawer, options);
|
||||
host.AddModalDrawer(drawer);
|
||||
@@ -69,12 +70,12 @@ public static class Drawer
|
||||
public static Task<DialogResult> ShowModal(Control control, object? vm, string? hostId = null,
|
||||
DrawerOptions? options = null)
|
||||
{
|
||||
var host = OverlayDialogManager.GetHost(hostId);
|
||||
var host = OverlayDialogManager.GetHost(hostId, options?.TopLevelHashCode);
|
||||
if (host is null) return Task.FromResult(DialogResult.None);
|
||||
var drawer = new DefaultDrawerControl()
|
||||
var drawer = new DefaultDrawerControl
|
||||
{
|
||||
Content = control,
|
||||
DataContext = vm,
|
||||
DataContext = vm
|
||||
};
|
||||
ConfigureDefaultDrawer(drawer, options);
|
||||
host.AddModalDrawer(drawer);
|
||||
@@ -83,110 +84,114 @@ public static class Drawer
|
||||
|
||||
public static Task<DialogResult> ShowModal(object? vm, string? hostId = null, DrawerOptions? options = null)
|
||||
{
|
||||
var host = OverlayDialogManager.GetHost(hostId);
|
||||
var host = OverlayDialogManager.GetHost(hostId, options?.TopLevelHashCode);
|
||||
if (host is null) return Task.FromResult(DialogResult.None);
|
||||
var view = host.GetDataTemplate(vm)?.Build(vm);
|
||||
if (view is null) view = new ContentControl() { Padding = new Thickness(24) };
|
||||
if (view is null) view = new ContentControl { Padding = new Thickness(24) };
|
||||
view.DataContext = vm;
|
||||
var drawer = new DefaultDrawerControl()
|
||||
var drawer = new DefaultDrawerControl
|
||||
{
|
||||
Content = view,
|
||||
DataContext = vm,
|
||||
DataContext = vm
|
||||
};
|
||||
ConfigureDefaultDrawer(drawer, options);
|
||||
host.AddModalDrawer(drawer);
|
||||
return drawer.ShowAsync<DialogResult>();
|
||||
}
|
||||
|
||||
public static void ShowCustom<TView, TViewModel>(TViewModel vm, string? hostId = null, DrawerOptions? options = null)
|
||||
where TView: Control, new()
|
||||
|
||||
public static void ShowCustom<TView, TViewModel>(TViewModel vm, string? hostId = null,
|
||||
DrawerOptions? options = null)
|
||||
where TView : Control, new()
|
||||
{
|
||||
var host = OverlayDialogManager.GetHost(hostId);
|
||||
var host = OverlayDialogManager.GetHost(hostId, options?.TopLevelHashCode);
|
||||
if (host is null) return;
|
||||
var dialog = new CustomDrawerControl()
|
||||
var dialog = new CustomDrawerControl
|
||||
{
|
||||
Content = new TView(),
|
||||
DataContext = vm,
|
||||
DataContext = vm
|
||||
};
|
||||
ConfigureCustomDrawer(dialog, options);
|
||||
host.AddDrawer(dialog);
|
||||
}
|
||||
|
||||
|
||||
public static void ShowCustom(Control control, object? vm, string? hostId = null, DrawerOptions? options = null)
|
||||
{
|
||||
var host = OverlayDialogManager.GetHost(hostId);
|
||||
var host = OverlayDialogManager.GetHost(hostId, options?.TopLevelHashCode);
|
||||
if (host is null) return;
|
||||
var dialog = new CustomDrawerControl()
|
||||
var dialog = new CustomDrawerControl
|
||||
{
|
||||
Content = control,
|
||||
DataContext = vm,
|
||||
DataContext = vm
|
||||
};
|
||||
ConfigureCustomDrawer(dialog, options);
|
||||
host.AddDrawer(dialog);
|
||||
}
|
||||
|
||||
|
||||
public static void ShowCustom(object? vm, string? hostId = null, DrawerOptions? options = null)
|
||||
{
|
||||
var host = OverlayDialogManager.GetHost(hostId);
|
||||
var host = OverlayDialogManager.GetHost(hostId, options?.TopLevelHashCode);
|
||||
if (host is null) return;
|
||||
var view = host.GetDataTemplate(vm)?.Build(vm);
|
||||
if (view is null) view = new ContentControl() { Padding = new Thickness(24) };
|
||||
if (view is null) view = new ContentControl { Padding = new Thickness(24) };
|
||||
view.DataContext = vm;
|
||||
var dialog = new CustomDrawerControl()
|
||||
var dialog = new CustomDrawerControl
|
||||
{
|
||||
Content = view,
|
||||
DataContext = vm,
|
||||
DataContext = vm
|
||||
};
|
||||
ConfigureCustomDrawer(dialog, options);
|
||||
host.AddDrawer(dialog);
|
||||
}
|
||||
|
||||
public static Task<TResult?> ShowCustomModal<TView, TViewModel, TResult>(TViewModel vm, string? hostId = null, DrawerOptions? options = null)
|
||||
where TView: Control, new()
|
||||
|
||||
public static Task<TResult?> ShowCustomModal<TView, TViewModel, TResult>(TViewModel vm, string? hostId = null,
|
||||
DrawerOptions? options = null)
|
||||
where TView : Control, new()
|
||||
{
|
||||
var host = OverlayDialogManager.GetHost(hostId);
|
||||
var host = OverlayDialogManager.GetHost(hostId, options?.TopLevelHashCode);
|
||||
if (host is null) return Task.FromResult<TResult?>(default);
|
||||
var dialog = new CustomDrawerControl()
|
||||
var dialog = new CustomDrawerControl
|
||||
{
|
||||
Content = new TView(),
|
||||
DataContext = vm,
|
||||
DataContext = vm
|
||||
};
|
||||
ConfigureCustomDrawer(dialog, options);
|
||||
host.AddModalDrawer(dialog);
|
||||
return dialog.ShowAsync<TResult?>();
|
||||
}
|
||||
|
||||
public static Task<TResult?> ShowCustomModal<TResult>(Control control, object? vm, string? hostId = null, DrawerOptions? options = null)
|
||||
|
||||
public static Task<TResult?> ShowCustomModal<TResult>(Control control, object? vm, string? hostId = null,
|
||||
DrawerOptions? options = null)
|
||||
{
|
||||
var host = OverlayDialogManager.GetHost(hostId);
|
||||
var host = OverlayDialogManager.GetHost(hostId, options?.TopLevelHashCode);
|
||||
if (host is null) return Task.FromResult<TResult?>(default);
|
||||
var dialog = new CustomDrawerControl()
|
||||
var dialog = new CustomDrawerControl
|
||||
{
|
||||
Content = control,
|
||||
DataContext = vm,
|
||||
DataContext = vm
|
||||
};
|
||||
ConfigureCustomDrawer(dialog, options);
|
||||
host.AddModalDrawer(dialog);
|
||||
return dialog.ShowAsync<TResult?>();
|
||||
}
|
||||
|
||||
public static Task<TResult?> ShowCustomModal<TResult>(object? vm, string? hostId = null, DrawerOptions? options = null)
|
||||
|
||||
public static Task<TResult?> ShowCustomModal<TResult>(object? vm, string? hostId = null,
|
||||
DrawerOptions? options = null)
|
||||
{
|
||||
var host = OverlayDialogManager.GetHost(hostId);
|
||||
var host = OverlayDialogManager.GetHost(hostId, options?.TopLevelHashCode);
|
||||
if (host is null) return Task.FromResult<TResult?>(default);
|
||||
var view = host.GetDataTemplate(vm)?.Build(vm);
|
||||
if (view is null) view = new ContentControl() { Padding = new Thickness(24) };
|
||||
if (view is null) view = new ContentControl { Padding = new Thickness(24) };
|
||||
view.DataContext = vm;
|
||||
var dialog = new CustomDrawerControl()
|
||||
var dialog = new CustomDrawerControl
|
||||
{
|
||||
Content = view,
|
||||
DataContext = vm,
|
||||
DataContext = vm
|
||||
};
|
||||
ConfigureCustomDrawer(dialog, options);
|
||||
host.AddModalDrawer(dialog);
|
||||
return dialog.ShowAsync<TResult?>();
|
||||
}
|
||||
|
||||
|
||||
private static void ConfigureCustomDrawer(CustomDrawerControl drawer, DrawerOptions? options)
|
||||
{
|
||||
options ??= DrawerOptions.Default;
|
||||
@@ -198,13 +203,14 @@ public static class Drawer
|
||||
drawer.MinWidth = options.MinWidth ?? 0.0;
|
||||
drawer.MaxWidth = options.MaxWidth ?? double.PositiveInfinity;
|
||||
}
|
||||
|
||||
if (options.Position is Position.Top or Position.Bottom)
|
||||
{
|
||||
drawer.MinHeight = options.MinHeight ?? 0.0;
|
||||
drawer.MaxHeight = options.MaxHeight ?? double.PositiveInfinity;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static void ConfigureDefaultDrawer(DefaultDrawerControl drawer, DrawerOptions? options)
|
||||
{
|
||||
options ??= DrawerOptions.Default;
|
||||
@@ -218,6 +224,7 @@ public static class Drawer
|
||||
drawer.MinWidth = options.MinWidth ?? 0.0;
|
||||
drawer.MaxWidth = options.MaxWidth ?? double.PositiveInfinity;
|
||||
}
|
||||
|
||||
if (options.Position is Position.Top or Position.Bottom)
|
||||
{
|
||||
drawer.MinHeight = options.MinHeight ?? 0.0;
|
||||
|
||||
@@ -15,4 +15,8 @@ public class DrawerOptions
|
||||
public DialogButton Buttons { get; set; } = DialogButton.OKCancel;
|
||||
public string? Title { get; set; }
|
||||
public bool ShowCloseButton { get; set; } = true;
|
||||
/// <summary>
|
||||
/// The hash code of the top level dialog host. This is used to identify the dialog host if there are multiple dialog hosts with the same id. If this is not provided, the dialog will be added to the first dialog host with the same id.
|
||||
/// </summary>
|
||||
public int? TopLevelHashCode { get; set; }
|
||||
}
|
||||
Reference in New Issue
Block a user