DialogControl 增加 ShowCustom 方法

This commit is contained in:
idea-zone
2024-02-01 08:53:50 +08:00
committed by bug320
parent 6ec1c477c4
commit 4dc0fd9e0c
3 changed files with 54 additions and 4 deletions

View File

@@ -24,6 +24,19 @@ public static class Dialog
return await ShowCustomModalAsync<TView, TViewModel, TResult>(mainWindow, vm);
}
/// <summary>
/// Show a Window Dialog that with all content fully customized.
/// </summary>
/// <param name="vm"></param>
/// <typeparam name="TView"></typeparam>
/// <typeparam name="TViewModel"></typeparam>
/// <returns></returns>
public static void ShowCustom<TView, TViewModel>(TViewModel vm)
where TView : Control, new()
{
var mainWindow = GetMainWindow();
ShowCustom<TView, TViewModel>(mainWindow, vm);
}
/// <summary>
/// Show a Window Modal Dialog that with all content fully customized. And the owner of the dialog is specified.
@@ -54,6 +67,33 @@ 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="owner"></param>
/// <param name="vm"></param>
/// <typeparam name="TView"></typeparam>
/// <typeparam name="TViewModel"></typeparam>
/// <returns></returns>
public static void ShowCustom<TView, TViewModel>(Window? owner, TViewModel? vm)
where TView: Control, new()
{
var window = new DialogWindow
{
Content = new TView { DataContext = vm },
DataContext = vm,
};
if (owner is null)
{
window.Show();
}
else
{
window.Show(owner);
}
}
public static async Task<DialogResult> ShowModalAsync<TView, TViewModel>(
Window? owner,
TViewModel vm,
@@ -170,4 +210,5 @@ public static class OverlayDialog
host?.AddDialog(t);
}
}