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" xmlns:local="clr-namespace:Ursa.Demo.Dialogs"
x:DataType="local:DialogWithActionViewModel" x:DataType="local:DialogWithActionViewModel"
x:CompileBindings="True" x:CompileBindings="True"
Background="{DynamicResource SemiYellow1}"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450" mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="Ursa.Demo.Dialogs.DialogWithAction"> x:Class="Ursa.Demo.Dialogs.DialogWithAction">
<StackPanel Margin="24"> <StackPanel Margin="24">

View File

@@ -3,6 +3,9 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450" 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"> x:Class="Ursa.Demo.Dialogs.PlainDialog">
<StackPanel> <StackPanel>
<Calendar SelectedDate="{Binding Date}" ></Calendar> <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; namespace Ursa.Demo.Dialogs;
public class PlainDialogViewModel: ObservableObject 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" x:DataType="vm:DialogDemoViewModel"
mc:Ignorable="d"> mc:Ignorable="d">
<Grid ColumnDefinitions="Auto, *"> <Grid ColumnDefinitions="Auto, *">
<StackPanel Grid.Column="0"> <TabControl Grid.Column="0" Width="300">
<TextBlock> <TabItem Header="Default">
<Run Text="Result: "></Run> <StackPanel>
<Run Text="{Binding Result}"></Run> <ToggleSwitch
</TextBlock> Name="overlay"
<TextBlock> IsChecked="{Binding IsWindow}"
<Run Text="Date: "></Run> OffContent="Overlay"
<Run Text="{Binding DialogViewModel.Date}"></Run> OnContent="Window" />
</TextBlock> <ToggleSwitch
<Button Command="{Binding ShowDefaultWindowCommand}">Show Default Modal Dialog</Button> IsVisible="{Binding !#overlay.IsChecked}"
<Button Command="{Binding ShowGlobalModalDialogCommand}">Show Custom Modal Dialog</Button> IsChecked="{Binding IsGlobal}"
<Button Command="{Binding ShowLocalOverlayModalDialogCommand}">Show Local Overlay Modal Dialog</Button> OffContent="Local"
<Button Command="{Binding ShowGlobalOverlayModalDialogCommand}"> Show Global Overlay Modal Dialog </Button> OnContent="Global" />
<Button Command="{Binding ShowGlobalOverlayDialogCommand}">Show Global Overlay Dialog</Button> <ToggleSwitch
</StackPanel> 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"> <Grid Grid.Column="1">
<Button <Border ClipToBounds="True" CornerRadius="20" BorderThickness="1" BorderBrush="{DynamicResource SemiGrey1}">
HorizontalAlignment="Center"
VerticalAlignment="Center"
Command="{Binding ShowLocalOverlayModalDialogCommand}">
Show Local Overlay Dialog
</Button>
<Border CornerRadius="20" ClipToBounds="True">
<u:OverlayDialogHost HostId="LocalHost" /> <u:OverlayDialogHost HostId="LocalHost" />
</Border> </Border>
</Grid> </Grid>

View File

@@ -1,4 +1,5 @@
using System; using System;
using System.Collections.ObjectModel;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Input; using System.Windows.Input;
using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.ComponentModel;
@@ -12,68 +13,140 @@ namespace Ursa.Demo.ViewModels;
public class DialogDemoViewModel: ObservableObject public class DialogDemoViewModel: ObservableObject
{ {
public ICommand ShowLocalOverlayModalDialogCommand { get; } public ICommand ShowDialogCommand { get; set; }
public ICommand ShowGlobalOverlayModalDialogCommand { get; } public ICommand ShowCustomDialogCommand { get; set; }
public ICommand ShowGlobalModalDialogCommand { get; }
public ICommand ShowGlobalOverlayDialogCommand { get; }
public ICommand ShowDefaultWindowCommand { get; }
private object? _result; private DialogMode _selectedMode;
public object? Result 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; get => _result;
set => SetProperty(ref _result, value); set => SetProperty(ref _result, value);
} }
private DateTime _date; private DateTime? _date;
public DateTime? Date
public DateTime Date
{ {
get => _date; get => _date;
set => SetProperty(ref _date, value); set => SetProperty(ref _date, value);
} }
public DialogWithActionViewModel DialogViewModel { get; set; } = new DialogWithActionViewModel();
public DialogDemoViewModel() public DialogDemoViewModel()
{ {
ShowLocalOverlayModalDialogCommand = new AsyncRelayCommand(ShowLocalOverlayModalDialog); ShowDialogCommand = new AsyncRelayCommand(ShowDialog);
ShowGlobalOverlayModalDialogCommand = new AsyncRelayCommand(ShowGlobalOverlayModalDialog); ShowCustomDialogCommand = new AsyncRelayCommand(ShowCustomDialog);
ShowGlobalModalDialogCommand = new AsyncRelayCommand(ShowGlobalModalDialog); Modes = new ObservableCollection<DialogMode>(Enum.GetValues<DialogMode>());
ShowGlobalOverlayDialogCommand = new RelayCommand(ShowGlobalOverlayDialog); Buttons = new ObservableCollection<DialogButton>(Enum.GetValues<DialogButton>());
ShowDefaultWindowCommand = new AsyncRelayCommand(ShowDefaultWindow);
} }
private async Task ShowDefaultWindow() private async Task ShowDialog()
{ {
var result = await Dialog.ShowModalAsync<PlainDialog, PlainDialogViewModel>(new PlainDialogViewModel(), var vm = new PlainDialogViewModel();
mode: DialogMode.Error, buttons: DialogButton.OKCancel, title:"确定取消预约吗?"); if (IsWindow)
Result = result; {
return; 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() private async Task ShowCustomDialog()
{
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()
{ {
var vm = new DialogWithActionViewModel(); var vm = new DialogWithActionViewModel();
var result = await OverlayDialog.ShowCustomModalAsync<DialogWithAction, DialogWithActionViewModel, bool>( if (IsWindow)
vm, "LocalHost"); {
Result = result;
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");
}
}
} }
} }

View File

@@ -129,6 +129,7 @@
VerticalAlignment="Center" VerticalAlignment="Center"
Height="16" /> Height="16" />
<TextBlock <TextBlock
Name="PART_Title"
Grid.Column="1" Grid.Column="1"
Margin="0 24 0 0 " Margin="0 24 0 0 "
FontWeight="Bold" FontWeight="Bold"
@@ -183,6 +184,9 @@
<Style Selector="^ /template/ PathIcon#PART_Icon"> <Style Selector="^ /template/ PathIcon#PART_Icon">
<Setter Property="IsVisible" Value="False"></Setter> <Setter Property="IsVisible" Value="False"></Setter>
</Style> </Style>
<Style Selector="^ /template/ TextBlock#PART_Title">
<Setter Property="Margin" Value="24 24 0 0"></Setter>
</Style>
<Style Selector="^ /template/ Button#PART_OKButton"> <Style Selector="^ /template/ Button#PART_OKButton">
<Setter Property="theme:ClassHelper.Classes" Value="Primary"></Setter> <Setter Property="theme:ClassHelper.Classes" Value="Primary"></Setter>
</Style> </Style>
@@ -386,7 +390,7 @@
<Grid Grid.Row="0" ColumnDefinitions="*, Auto"> <Grid Grid.Row="0" ColumnDefinitions="*, Auto">
<TextBlock <TextBlock
Grid.Column="0" Grid.Column="0"
Margin="8,8,0,0" Margin="24, 24,0,0"
FontSize="14" FontSize="14"
FontWeight="Bold" FontWeight="Bold"
Text="{TemplateBinding Title}" Text="{TemplateBinding Title}"
@@ -429,7 +433,7 @@
</Setter> </Setter>
<Setter Property="CanResize" Value="False" /> <Setter Property="CanResize" Value="False" />
<Setter Property="Template"> <Setter Property="Template">
<ControlTemplate TargetType="u:DialogWindow"> <ControlTemplate TargetType="u:DefaultDialogWindow">
<Panel> <Panel>
<Border Name="PART_TransparencyFallback" IsHitTestVisible="False" /> <Border Name="PART_TransparencyFallback" IsHitTestVisible="False" />
<Border Background="{TemplateBinding Background}" IsHitTestVisible="False" /> <Border Background="{TemplateBinding Background}" IsHitTestVisible="False" />
@@ -455,6 +459,7 @@
VerticalAlignment="Center" VerticalAlignment="Center"
Height="16" /> Height="16" />
<TextBlock <TextBlock
Name="PART_Title"
Grid.Column="1" Grid.Column="1"
Margin="0 24 0 0 " Margin="0 24 0 0 "
FontWeight="Bold" FontWeight="Bold"
@@ -505,10 +510,13 @@
</Panel> </Panel>
</ControlTemplate> </ControlTemplate>
</Setter> </Setter>
<Style Selector="^[Mode=None]"> <Style Selector="^[Mode=None]">
<Style Selector="^ /template/ PathIcon#PART_Icon"> <Style Selector="^ /template/ PathIcon#PART_Icon">
<Setter Property="IsVisible" Value="False"></Setter> <Setter Property="IsVisible" Value="False"></Setter>
</Style> </Style>
<Style Selector="^ /template/ TextBlock#PART_Title">
<Setter Property="Margin" Value="24 24 0 0"></Setter>
</Style>
<Style Selector="^ /template/ Button#PART_OKButton"> <Style Selector="^ /template/ Button#PART_OKButton">
<Setter Property="theme:ClassHelper.Classes" Value="Primary"></Setter> <Setter Property="theme:ClassHelper.Classes" Value="Primary"></Setter>
</Style> </Style>

View File

@@ -41,6 +41,7 @@
Grid.Column="0" Grid.Column="0"
Width="24" Width="24"
Height="24" Height="24"
Margin="0 0 8 0"
IsHitTestVisible="False" IsHitTestVisible="False"
VerticalAlignment="Center" /> VerticalAlignment="Center" />
<TextBlock <TextBlock
@@ -48,6 +49,7 @@
FontSize="16" FontSize="16"
FontWeight="Bold" FontWeight="Bold"
IsHitTestVisible="False" IsHitTestVisible="False"
VerticalAlignment="Center"
Text="{TemplateBinding Title}" Text="{TemplateBinding Title}"
TextTrimming="CharacterEllipsis" TextTrimming="CharacterEllipsis"
TextWrapping="NoWrap" /> TextWrapping="NoWrap" />