feat: refactor OverlayDialog and add options.
This commit is contained in:
@@ -38,6 +38,13 @@ public static class Dialog
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Show a Window Dialog that with all content fully customized. And the owner of the dialog is specified.
|
||||
/// </summary>
|
||||
/// <param name="view">View to show in Dialog Window</param>
|
||||
/// <param name="vm">ViewModel</param>
|
||||
/// <param name="owner">Owner Window</param>
|
||||
/// <param name="options">Dialog options to configure the window. </param>
|
||||
public static void ShowCustom(Control view, object? vm, Window? owner = null, DialogOptions? options = null)
|
||||
{
|
||||
var window = new DialogWindow
|
||||
@@ -57,6 +64,15 @@ public static class Dialog
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Show a Modal Dialog Window with default style.
|
||||
/// </summary>
|
||||
/// <param name="vm"></param>
|
||||
/// <param name="owner"></param>
|
||||
/// <param name="options"></param>
|
||||
/// <typeparam name="TView"></typeparam>
|
||||
/// <typeparam name="TViewModel"></typeparam>
|
||||
/// <returns></returns>
|
||||
public static Task<DialogResult> ShowModal<TView, TViewModel>(TViewModel vm, Window? owner = null,
|
||||
DialogOptions? options = null)
|
||||
where TView: Control, new()
|
||||
@@ -76,6 +92,14 @@ public static class Dialog
|
||||
return window.ShowDialog<DialogResult>(owner);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Show a Modal Dialog Window with default style.
|
||||
/// </summary>
|
||||
/// <param name="view"></param>
|
||||
/// <param name="vm"></param>
|
||||
/// <param name="owner"></param>
|
||||
/// <param name="options"></param>
|
||||
/// <returns></returns>
|
||||
public static Task<DialogResult> ShowModal(Control view, object? vm, Window? owner = null, DialogOptions? options = null)
|
||||
{
|
||||
var window = new DefaultDialogWindow
|
||||
@@ -93,6 +117,16 @@ public static class Dialog
|
||||
return window.ShowDialog<DialogResult>(owner);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Show a Modal Dialog Window with all content fully customized.
|
||||
/// </summary>
|
||||
/// <param name="vm"></param>
|
||||
/// <param name="owner"></param>
|
||||
/// <param name="options"></param>
|
||||
/// <typeparam name="TView"></typeparam>
|
||||
/// <typeparam name="TViewModel"></typeparam>
|
||||
/// <typeparam name="TResult"></typeparam>
|
||||
/// <returns></returns>
|
||||
public static Task<TResult?> ShowCustomModal<TView, TViewModel, TResult>(TViewModel vm, Window? owner = null,
|
||||
DialogOptions? options = null)
|
||||
where TView: Control, new()
|
||||
@@ -112,6 +146,15 @@ public static class Dialog
|
||||
return window.ShowDialog<TResult?>(owner);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Show a Modal Dialog Window with all content fully customized.
|
||||
/// </summary>
|
||||
/// <param name="view"></param>
|
||||
/// <param name="vm"></param>
|
||||
/// <param name="owner"></param>
|
||||
/// <param name="options"></param>
|
||||
/// <typeparam name="TResult"></typeparam>
|
||||
/// <returns></returns>
|
||||
public static Task<TResult?> ShowCustomModal<TResult>(Control view, object? vm, Window? owner = null,
|
||||
DialogOptions? options = null)
|
||||
{
|
||||
@@ -130,12 +173,21 @@ public static class Dialog
|
||||
return window.ShowDialog<TResult?>(owner);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the main window of the application as default owner of the dialog.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
private static Window? GetMainWindow()
|
||||
{
|
||||
var lifetime = Application.Current?.ApplicationLifetime;
|
||||
return lifetime is IClassicDesktopStyleApplicationLifetime { MainWindow: { } w } ? w : null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Attach options to dialog window.
|
||||
/// </summary>
|
||||
/// <param name="window"></param>
|
||||
/// <param name="options"></param>
|
||||
private static void AssignOptionsToDialogWindow(DialogWindow window, DialogOptions? options)
|
||||
{
|
||||
if (options is null)
|
||||
@@ -157,6 +209,11 @@ public static class Dialog
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Attach options to default dialog window.
|
||||
/// </summary>
|
||||
/// <param name="window"></param>
|
||||
/// <param name="options"></param>
|
||||
private static void AssignOptionsToDefaultDialogWindow(DefaultDialogWindow window, DialogOptions? options)
|
||||
{
|
||||
if (options is null)
|
||||
@@ -179,6 +236,4 @@ public static class Dialog
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user