diff --git a/demo/Ursa.Demo/Dialogs/DialogWithAction.axaml b/demo/Ursa.Demo/Dialogs/DialogWithAction.axaml index 104e746..3a0d2ac 100644 --- a/demo/Ursa.Demo/Dialogs/DialogWithAction.axaml +++ b/demo/Ursa.Demo/Dialogs/DialogWithAction.axaml @@ -5,6 +5,7 @@ xmlns:local="clr-namespace:Ursa.Demo.Dialogs" x:DataType="local:DialogWithActionViewModel" x:CompileBindings="True" + Background="{DynamicResource SemiYellow1}" mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450" x:Class="Ursa.Demo.Dialogs.DialogWithAction"> diff --git a/demo/Ursa.Demo/Dialogs/PlainDialog.axaml b/demo/Ursa.Demo/Dialogs/PlainDialog.axaml index 2f0565e..89dbb0d 100644 --- a/demo/Ursa.Demo/Dialogs/PlainDialog.axaml +++ b/demo/Ursa.Demo/Dialogs/PlainDialog.axaml @@ -3,6 +3,9 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450" + xmlns:local="clr-namespace:Ursa.Demo.Dialogs" + x:DataType="local:PlainDialogViewModel" + x:CompileBindings="True" x:Class="Ursa.Demo.Dialogs.PlainDialog"> diff --git a/demo/Ursa.Demo/Dialogs/PlainDialogViewModel.cs b/demo/Ursa.Demo/Dialogs/PlainDialogViewModel.cs index e7105f2..2e199a6 100644 --- a/demo/Ursa.Demo/Dialogs/PlainDialogViewModel.cs +++ b/demo/Ursa.Demo/Dialogs/PlainDialogViewModel.cs @@ -1,8 +1,15 @@ -using CommunityToolkit.Mvvm.ComponentModel; +using System; +using CommunityToolkit.Mvvm.ComponentModel; namespace Ursa.Demo.Dialogs; public class PlainDialogViewModel: ObservableObject { - + private DateTime? _date; + + public DateTime? Date + { + get => _date; + set => SetProperty(ref _date, value); + } } \ No newline at end of file diff --git a/demo/Ursa.Demo/Pages/DialogDemo.axaml b/demo/Ursa.Demo/Pages/DialogDemo.axaml index d6ddd48..f5f24e9 100644 --- a/demo/Ursa.Demo/Pages/DialogDemo.axaml +++ b/demo/Ursa.Demo/Pages/DialogDemo.axaml @@ -12,29 +12,62 @@ x:DataType="vm:DialogDemoViewModel" mc:Ignorable="d"> - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + - + diff --git a/demo/Ursa.Demo/ViewModels/DialogDemoViewModel.cs b/demo/Ursa.Demo/ViewModels/DialogDemoViewModel.cs index ec6126f..163e7b7 100644 --- a/demo/Ursa.Demo/ViewModels/DialogDemoViewModel.cs +++ b/demo/Ursa.Demo/ViewModels/DialogDemoViewModel.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.ObjectModel; using System.Threading.Tasks; using System.Windows.Input; using CommunityToolkit.Mvvm.ComponentModel; @@ -12,68 +13,140 @@ namespace Ursa.Demo.ViewModels; public class DialogDemoViewModel: ObservableObject { - public ICommand ShowLocalOverlayModalDialogCommand { get; } - public ICommand ShowGlobalOverlayModalDialogCommand { get; } - public ICommand ShowGlobalModalDialogCommand { get; } - public ICommand ShowGlobalOverlayDialogCommand { get; } - public ICommand ShowDefaultWindowCommand { get; } + public ICommand ShowDialogCommand { get; set; } + public ICommand ShowCustomDialogCommand { get; set; } - private object? _result; - public object? Result + private DialogMode _selectedMode; + public DialogMode SelectedMode + { + get => _selectedMode; + set => SetProperty(ref _selectedMode, value); + } + + public ObservableCollection Modes { get; set; } + + private DialogButton _selectedButton; + public DialogButton SelectedButton + { + get => _selectedButton; + set => SetProperty(ref _selectedButton, value); + } + + public ObservableCollection Buttons { get; set; } + + private bool _isWindow; + public bool IsWindow + { + get => _isWindow; + set => SetProperty(ref _isWindow, value); + } + + private bool _isGlobal; + public bool IsGlobal + { + get => _isGlobal; + set => SetProperty(ref _isGlobal, value); + } + + private bool _isModal; + public bool IsModal + { + get => _isModal; + set => SetProperty(ref _isModal, value); + } + + private DialogResult? _defaultResult; + public DialogResult? DefaultResult + { + get => _defaultResult; + set => SetProperty(ref _defaultResult, value); + } + + private bool _result; + public bool Result { get => _result; set => SetProperty(ref _result, value); } - private DateTime _date; - - public DateTime Date + private DateTime? _date; + public DateTime? Date { get => _date; set => SetProperty(ref _date, value); } - - public DialogWithActionViewModel DialogViewModel { get; set; } = new DialogWithActionViewModel(); - + + public DialogDemoViewModel() { - ShowLocalOverlayModalDialogCommand = new AsyncRelayCommand(ShowLocalOverlayModalDialog); - ShowGlobalOverlayModalDialogCommand = new AsyncRelayCommand(ShowGlobalOverlayModalDialog); - ShowGlobalModalDialogCommand = new AsyncRelayCommand(ShowGlobalModalDialog); - ShowGlobalOverlayDialogCommand = new RelayCommand(ShowGlobalOverlayDialog); - ShowDefaultWindowCommand = new AsyncRelayCommand(ShowDefaultWindow); + ShowDialogCommand = new AsyncRelayCommand(ShowDialog); + ShowCustomDialogCommand = new AsyncRelayCommand(ShowCustomDialog); + Modes = new ObservableCollection(Enum.GetValues()); + Buttons = new ObservableCollection(Enum.GetValues()); } - - private async Task ShowDefaultWindow() + + private async Task ShowDialog() { - var result = await Dialog.ShowModalAsync(new PlainDialogViewModel(), - mode: DialogMode.Error, buttons: DialogButton.OKCancel, title:"确定取消预约吗?"); - Result = result; - return; + var vm = new PlainDialogViewModel(); + if (IsWindow) + { + DefaultResult = await Dialog.ShowModalAsync( + vm, + "Please select a date", + SelectedMode, + SelectedButton); + Date = vm.Date; + } + else + { + if (IsModal) + { + DefaultResult = await OverlayDialog.ShowModalAsync( + vm, + IsGlobal ? null : "LocalHost", + "Please select a date", + SelectedMode, + SelectedButton + ); + Date = vm.Date; + } + else + { + OverlayDialog.Show( + new PlainDialogViewModel(), + IsGlobal ? null : "LocalHost", + "Please select a date", + SelectedMode, + SelectedButton); + } + } + } - - private void ShowGlobalOverlayDialog() - { - OverlayDialog.ShowCustom(new DialogWithActionViewModel()); - } - - private async Task ShowGlobalModalDialog() - { - var result = await Dialog.ShowCustomModalAsync(DialogViewModel); - Result = result; - } - - private async Task ShowGlobalOverlayModalDialog() - { - Result = await OverlayDialog.ShowModalAsync(new PlainDialogViewModel(), - title: "Please select a date", mode: DialogMode.Error, buttons: DialogButton.YesNoCancel); - } - - private async Task ShowLocalOverlayModalDialog() + + private async Task ShowCustomDialog() { var vm = new DialogWithActionViewModel(); - var result = await OverlayDialog.ShowCustomModalAsync( - vm, "LocalHost"); - Result = result; + if (IsWindow) + { + + Result = await Dialog.ShowCustomModalAsync( + vm); + Date = vm.Date; + } + else + { + if (IsModal) + { + Result = await OverlayDialog.ShowCustomModalAsync( + vm, IsGlobal ? null : "LocalHost"); + Date = vm.Date; + } + else + { + OverlayDialog.ShowCustom(new DialogWithActionViewModel(), + IsGlobal ? null : "LocalHost"); + } + } + } } \ No newline at end of file diff --git a/src/Ursa.Themes.Semi/Controls/Dialog.axaml b/src/Ursa.Themes.Semi/Controls/Dialog.axaml index 8307975..08338af 100644 --- a/src/Ursa.Themes.Semi/Controls/Dialog.axaml +++ b/src/Ursa.Themes.Semi/Controls/Dialog.axaml @@ -129,6 +129,7 @@ VerticalAlignment="Center" Height="16" /> + @@ -386,7 +390,7 @@ - + @@ -455,6 +459,7 @@ VerticalAlignment="Center" Height="16" /> - + diff --git a/src/Ursa.Themes.Semi/Controls/MessageBox.axaml b/src/Ursa.Themes.Semi/Controls/MessageBox.axaml index 80d3ebd..3b146fd 100644 --- a/src/Ursa.Themes.Semi/Controls/MessageBox.axaml +++ b/src/Ursa.Themes.Semi/Controls/MessageBox.axaml @@ -41,6 +41,7 @@ Grid.Column="0" Width="24" Height="24" + Margin="0 0 8 0" IsHitTestVisible="False" VerticalAlignment="Center" />