Merge pull request #85 from ForkFunny/main

DialogControl 增加 ShowCustom 方法
This commit is contained in:
Dong Bin
2024-02-01 10:28:05 +08:00
committed by GitHub
3 changed files with 54 additions and 4 deletions

View File

@@ -56,7 +56,7 @@
<StackPanel>
<ToggleSwitch Content="Window/Overlay" OffContent="Overlay" OnContent="Window" IsChecked="{Binding IsWindow}" Name="overlay2" />
<ToggleSwitch Content="Global/Local" IsVisible="{Binding !#overlay2.IsChecked}" OffContent="Local" OnContent="Global" IsChecked="{Binding IsGlobal}" />
<ToggleSwitch Content="Modal/Regular" IsVisible="{Binding !#overlay2.IsChecked}" OffContent="Regular" OnContent="Modal" IsChecked="{Binding IsModal}" />
<ToggleSwitch Content="Modal/Regular" OffContent="Regular" OnContent="Modal" IsChecked="{Binding IsModal}" />
<Button Content="Show Dialog" Command="{Binding ShowCustomDialogCommand}" />
<TextBlock>
<Run Text="Custom Result: "></Run>

View File

@@ -128,10 +128,19 @@ public class DialogDemoViewModel: ObservableObject
var vm = new DialogWithActionViewModel();
if (IsWindow)
{
if (IsModal)
{
Result = await Dialog.ShowCustomModalAsync<DialogWithAction, DialogWithActionViewModel, bool>(
vm);
Date = vm.Date;
}
else
{
Dialog.ShowCustom<DialogWithAction, DialogWithActionViewModel>(
vm);
}
Result = await Dialog.ShowCustomModalAsync<DialogWithAction, DialogWithActionViewModel, bool>(
vm);
Date = vm.Date;
}
else
{

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);
}
}