feat: implement default button for dialog control.

This commit is contained in:
rabbitism
2024-01-24 12:40:45 +08:00
parent a174f0cd85
commit a17f1076d0
10 changed files with 181 additions and 28 deletions

View File

@@ -12,7 +12,7 @@ public partial class DialogWithActionViewModel: ObservableObject, IDialogContext
[ObservableProperty] private string _title;
[ObservableProperty] private DateTime _date;
public object? DefaultCloseResult { get; set; } = true;
public event EventHandler<object>? Closed;
public event EventHandler<object?>? Closed;
public ICommand OKCommand { get; set; }
public ICommand CancelCommand { get; set; }

View File

@@ -4,5 +4,8 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="Ursa.Demo.Dialogs.PlainDialog">
<StackPanel Margin="8">
<TextBlock Classes="Strong" Margin="8" Text="{Binding Title}"></TextBlock>
<Calendar SelectedDate="{Binding Date}" ></Calendar>
</StackPanel>
</UserControl>

View File

@@ -25,6 +25,7 @@
<Button Command="{Binding ShowLocalOverlayModalDialogCommand}">Show Local Overlay Modal Dialog</Button>
<Button Command="{Binding ShowGlobalOverlayModalDialogCommand}"> Show Global Overlay Modal Dialog </Button>
<Button Command="{Binding ShowGlobalOverlayDialogCommand}">Show Global Overlay Dialog</Button>
<Button Command="{Binding ShowPlainGlobalOverlayDialogCommand}">Default Buttons</Button>
</StackPanel>
<Grid Grid.Column="1">
<Button

View File

@@ -3,6 +3,7 @@ using System.Threading.Tasks;
using System.Windows.Input;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using Ursa.Common;
using Ursa.Controls;
using Ursa.Demo.Dialogs;
using Ursa.Demo.Pages;
@@ -16,6 +17,8 @@ public class DialogDemoViewModel: ObservableObject
public ICommand ShowGlobalModalDialogCommand { get; }
public ICommand ShowGlobalOverlayDialogCommand { get; }
public ICommand ShowPlainGlobalOverlayDialogCommand { get; }
private object? _result;
@@ -41,6 +44,7 @@ public class DialogDemoViewModel: ObservableObject
ShowGlobalOverlayModalDialogCommand = new AsyncRelayCommand(ShowGlobalOverlayModalDialog);
ShowGlobalModalDialogCommand = new AsyncRelayCommand(ShowGlobalModalDialog);
ShowGlobalOverlayDialogCommand = new RelayCommand(ShowGlobalOverlayDialog);
ShowPlainGlobalOverlayDialogCommand = new AsyncRelayCommand(ShowPlainGlobalOverlayDialog);
}
private void ShowGlobalOverlayDialog()
@@ -63,7 +67,18 @@ public class DialogDemoViewModel: ObservableObject
{
var vm = new DialogWithActionViewModel();
var result = await OverlayDialog.ShowModalAsync<DialogWithAction, DialogWithActionViewModel, bool>(
DialogViewModel, new DialogOptions() { ExtendToClientArea = true }, "LocalHost");
DialogViewModel, new DialogOptions() { ExtendToClientArea = true}, "LocalHost");
Result = result;
}
public async Task ShowPlainGlobalOverlayDialog()
{
var result = await OverlayDialog.ShowModalAsync<PlainDialog, PlainDialogViewModel, object?>(
new PlainDialogViewModel(),
new DialogOptions()
{
DefaultButtons = DialogButton.OKCancel,
},
"LocalHost");
}
}