Merge pull request #85 from ForkFunny/main
DialogControl 增加 ShowCustom 方法
This commit is contained in:
@@ -56,7 +56,7 @@
|
|||||||
<StackPanel>
|
<StackPanel>
|
||||||
<ToggleSwitch Content="Window/Overlay" OffContent="Overlay" OnContent="Window" IsChecked="{Binding IsWindow}" Name="overlay2" />
|
<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="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}" />
|
<Button Content="Show Dialog" Command="{Binding ShowCustomDialogCommand}" />
|
||||||
<TextBlock>
|
<TextBlock>
|
||||||
<Run Text="Custom Result: "></Run>
|
<Run Text="Custom Result: "></Run>
|
||||||
|
|||||||
@@ -129,9 +129,18 @@ public class DialogDemoViewModel: ObservableObject
|
|||||||
if (IsWindow)
|
if (IsWindow)
|
||||||
{
|
{
|
||||||
|
|
||||||
Result = await Dialog.ShowCustomModalAsync<DialogWithAction, DialogWithActionViewModel, bool>(
|
if (IsModal)
|
||||||
vm);
|
{
|
||||||
Date = vm.Date;
|
Result = await Dialog.ShowCustomModalAsync<DialogWithAction, DialogWithActionViewModel, bool>(
|
||||||
|
vm);
|
||||||
|
Date = vm.Date;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Dialog.ShowCustom<DialogWithAction, DialogWithActionViewModel>(
|
||||||
|
vm);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -24,6 +24,19 @@ public static class Dialog
|
|||||||
return await ShowCustomModalAsync<TView, TViewModel, TResult>(mainWindow, vm);
|
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>
|
/// <summary>
|
||||||
/// Show a Window Modal Dialog that with all content fully customized. And the owner of the dialog is specified.
|
/// 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>(
|
public static async Task<DialogResult> ShowModalAsync<TView, TViewModel>(
|
||||||
Window? owner,
|
Window? owner,
|
||||||
TViewModel vm,
|
TViewModel vm,
|
||||||
@@ -170,4 +210,5 @@ public static class OverlayDialog
|
|||||||
host?.AddDialog(t);
|
host?.AddDialog(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user