feat: update demo.

This commit is contained in:
rabbitism
2024-01-25 17:35:52 +08:00
parent b327a7c8ac
commit af02b46adc
7 changed files with 200 additions and 73 deletions

View File

@@ -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">
<StackPanel Margin="24">

View File

@@ -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">
<StackPanel>
<Calendar SelectedDate="{Binding Date}" ></Calendar>

View File

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

View File

@@ -12,29 +12,62 @@
x:DataType="vm:DialogDemoViewModel"
mc:Ignorable="d">
<Grid ColumnDefinitions="Auto, *">
<StackPanel Grid.Column="0">
<TextBlock>
<Run Text="Result: "></Run>
<Run Text="{Binding Result}"></Run>
</TextBlock>
<TextBlock>
<Run Text="Date: "></Run>
<Run Text="{Binding DialogViewModel.Date}"></Run>
</TextBlock>
<Button Command="{Binding ShowDefaultWindowCommand}">Show Default Modal Dialog</Button>
<Button Command="{Binding ShowGlobalModalDialogCommand}">Show Custom Modal Dialog</Button>
<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>
</StackPanel>
<TabControl Grid.Column="0" Width="300">
<TabItem Header="Default">
<StackPanel>
<ToggleSwitch
Name="overlay"
IsChecked="{Binding IsWindow}"
OffContent="Overlay"
OnContent="Window" />
<ToggleSwitch
IsVisible="{Binding !#overlay.IsChecked}"
IsChecked="{Binding IsGlobal}"
OffContent="Local"
OnContent="Global" />
<ToggleSwitch
IsVisible="{Binding !#overlay.IsChecked}"
IsChecked="{Binding IsModal}"
OffContent="Regular"
OnContent="Modal" />
<StackPanel Orientation="Horizontal">
<TextBlock Text="Buttons" />
<ComboBox ItemsSource="{Binding Buttons}" SelectedItem="{Binding SelectedButton}" />
</StackPanel>
<StackPanel Orientation="Horizontal">
<TextBlock Text="Mode" />
<ComboBox ItemsSource="{Binding Modes}" SelectedItem="{Binding SelectedMode}"/>
</StackPanel>
<Button Content="Show Dialog" Command="{Binding ShowDialogCommand}" />
<TextBlock>
<Run Text="Default Result: "></Run>
<Run Text="{Binding DefaultResult}"/>
</TextBlock>
<TextBlock>
<Run Text="Dialog Date: "></Run>
<Run Text="{Binding Date}"/>
</TextBlock>
</StackPanel>
</TabItem>
<TabItem Header="Custom">
<StackPanel>
<ToggleSwitch OffContent="Overlay" OnContent="Window" IsChecked="{Binding IsWindow}" Name="overlay2" />
<ToggleSwitch IsVisible="{Binding !#overlay2.IsChecked}" OffContent="Local" OnContent="Global" IsChecked="{Binding IsGlobal}" />
<ToggleSwitch IsVisible="{Binding !#overlay2.IsChecked}" OffContent="Regular" OnContent="Modal" IsChecked="{Binding IsModal}" />
<Button Content="Show Dialog" Command="{Binding ShowCustomDialogCommand}" />
<TextBlock>
<Run Text="Custom Result: "></Run>
<Run Text="{Binding Result}"/>
</TextBlock>
<TextBlock>
<Run Text="Dialog Date: "></Run>
<Run Text="{Binding Date}"/>
</TextBlock>
</StackPanel>
</TabItem>
</TabControl>
<Grid Grid.Column="1">
<Button
HorizontalAlignment="Center"
VerticalAlignment="Center"
Command="{Binding ShowLocalOverlayModalDialogCommand}">
Show Local Overlay Dialog
</Button>
<Border CornerRadius="20" ClipToBounds="True">
<Border ClipToBounds="True" CornerRadius="20" BorderThickness="1" BorderBrush="{DynamicResource SemiGrey1}">
<u:OverlayDialogHost HostId="LocalHost" />
</Border>
</Grid>

View File

@@ -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<DialogMode> Modes { get; set; }
private DialogButton _selectedButton;
public DialogButton SelectedButton
{
get => _selectedButton;
set => SetProperty(ref _selectedButton, value);
}
public ObservableCollection<DialogButton> 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<DialogMode>(Enum.GetValues<DialogMode>());
Buttons = new ObservableCollection<DialogButton>(Enum.GetValues<DialogButton>());
}
private async Task ShowDefaultWindow()
private async Task ShowDialog()
{
var result = await Dialog.ShowModalAsync<PlainDialog, PlainDialogViewModel>(new PlainDialogViewModel(),
mode: DialogMode.Error, buttons: DialogButton.OKCancel, title:"确定取消预约吗?");
Result = result;
return;
var vm = new PlainDialogViewModel();
if (IsWindow)
{
DefaultResult = await Dialog.ShowModalAsync<PlainDialog, PlainDialogViewModel>(
vm,
"Please select a date",
SelectedMode,
SelectedButton);
Date = vm.Date;
}
else
{
if (IsModal)
{
DefaultResult = await OverlayDialog.ShowModalAsync<PlainDialog, PlainDialogViewModel>(
vm,
IsGlobal ? null : "LocalHost",
"Please select a date",
SelectedMode,
SelectedButton
);
Date = vm.Date;
}
else
{
OverlayDialog.Show<PlainDialog, PlainDialogViewModel>(
new PlainDialogViewModel(),
IsGlobal ? null : "LocalHost",
"Please select a date",
SelectedMode,
SelectedButton);
}
}
}
private void ShowGlobalOverlayDialog()
{
OverlayDialog.ShowCustom<DialogWithAction, DialogWithActionViewModel>(new DialogWithActionViewModel());
}
private async Task ShowGlobalModalDialog()
{
var result = await Dialog.ShowCustomModalAsync<DialogWithAction, DialogWithActionViewModel, bool>(DialogViewModel);
Result = result;
}
private async Task ShowGlobalOverlayModalDialog()
{
Result = await OverlayDialog.ShowModalAsync<PlainDialog, PlainDialogViewModel>(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<DialogWithAction, DialogWithActionViewModel, bool>(
vm, "LocalHost");
Result = result;
if (IsWindow)
{
Result = await Dialog.ShowCustomModalAsync<DialogWithAction, DialogWithActionViewModel, bool>(
vm);
Date = vm.Date;
}
else
{
if (IsModal)
{
Result = await OverlayDialog.ShowCustomModalAsync<DialogWithAction, DialogWithActionViewModel, bool>(
vm, IsGlobal ? null : "LocalHost");
Date = vm.Date;
}
else
{
OverlayDialog.ShowCustom<DialogWithAction, DialogWithActionViewModel>(new DialogWithActionViewModel(),
IsGlobal ? null : "LocalHost");
}
}
}
}