Merge pull request #149 from irihitech/issue/134-dialog

Dialog Update
This commit is contained in:
Dong Bin
2024-03-27 22:07:28 +08:00
committed by GitHub
13 changed files with 189 additions and 110 deletions

View File

@@ -39,22 +39,27 @@
IsChecked="{Binding CanLightDismiss}" IsChecked="{Binding CanLightDismiss}"
OffContent="No" OffContent="No"
OnContent="Yes" /> OnContent="Yes" />
<ToggleSwitch
Content="FullScreen"
IsChecked="{Binding FullScreen}"
OffContent="No"
OnContent="Yes" />
<StackPanel Orientation="Horizontal"> <StackPanel Orientation="Horizontal">
<TextBlock Text="Buttons" /> <TextBlock VerticalAlignment="Center" Text="Buttons" />
<ComboBox ItemsSource="{Binding Buttons}" SelectedItem="{Binding SelectedButton}" /> <u:EnumSelector EnumType="{x:Type u:DialogButton}" Value="{Binding SelectedButton}" />
</StackPanel> </StackPanel>
<StackPanel Orientation="Horizontal"> <StackPanel Orientation="Horizontal">
<TextBlock Text="Mode" /> <TextBlock VerticalAlignment="Center" Text="Mode" />
<ComboBox ItemsSource="{Binding Modes}" SelectedItem="{Binding SelectedMode}" /> <u:EnumSelector EnumType="{x:Type u:DialogMode}" Value="{Binding SelectedMode}" />
</StackPanel> </StackPanel>
<Button Command="{Binding ShowDialogCommand}" Content="Show Dialog" /> <Button Command="{Binding ShowDialogCommand}" Content="Show Dialog" />
<TextBlock> <TextBlock>
<Run Text="Default Result: " /> <Run Text="Default Result: " />
<Run Text="{Binding DefaultResult}" /> <Run Text="{Binding DefaultResult, FallbackValue=''}" />
</TextBlock> </TextBlock>
<TextBlock> <TextBlock>
<Run Text="Dialog Date: " /> <Run Text="Dialog Date: " />
<Run Text="{Binding Date}" /> <Run Text="{Binding Date, FallbackValue=''}" />
</TextBlock> </TextBlock>
</StackPanel> </StackPanel>
</TabItem> </TabItem>
@@ -73,8 +78,8 @@
OffContent="Local" OffContent="Local"
OnContent="Global" /> OnContent="Global" />
<ToggleSwitch <ToggleSwitch
Content="Modal/Regular"
Name="modal" Name="modal"
Content="Modal/Regular"
IsChecked="{Binding IsModal}" IsChecked="{Binding IsModal}"
OffContent="Regular" OffContent="Regular"
OnContent="Modal" /> OnContent="Modal" />
@@ -83,6 +88,11 @@
IsChecked="{Binding CanLightDismiss}" IsChecked="{Binding CanLightDismiss}"
OffContent="No" OffContent="No"
OnContent="Yes" /> OnContent="Yes" />
<ToggleSwitch
Content="FullScreen"
IsChecked="{Binding FullScreen}"
OffContent="No"
OnContent="Yes" />
<Button Command="{Binding ShowCustomDialogCommand}" Content="Show Dialog" /> <Button Command="{Binding ShowCustomDialogCommand}" Content="Show Dialog" />
<TextBlock> <TextBlock>
<Run Text="Custom Result: " /> <Run Text="Custom Result: " />

View File

@@ -11,85 +11,28 @@ using Ursa.Demo.Pages;
namespace Ursa.Demo.ViewModels; namespace Ursa.Demo.ViewModels;
public class DialogDemoViewModel: ObservableObject public partial class DialogDemoViewModel: ObservableObject
{ {
public ICommand ShowDialogCommand { get; set; } public ICommand ShowDialogCommand { get; set; }
public ICommand ShowCustomDialogCommand { get; set; } public ICommand ShowCustomDialogCommand { get; set; }
private DialogMode _selectedMode; [ObservableProperty] private DialogMode _selectedMode;
public DialogMode SelectedMode [ObservableProperty] private DialogButton _selectedButton;
{ [ObservableProperty] private bool _isWindow;
get => _selectedMode; [ObservableProperty] private bool _isGlobal;
set => SetProperty(ref _selectedMode, value); [ObservableProperty] private bool _isModal;
} [ObservableProperty] private bool _canLightDismiss;
[ObservableProperty] private DialogResult? _defaultResult;
public ObservableCollection<DialogMode> Modes { get; set; } [ObservableProperty] private bool _result;
[ObservableProperty] private DateTime? _date;
private DialogButton _selectedButton; [ObservableProperty] private bool _fullScreen;
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 bool _canLightDismiss;
public bool CanLightDismiss
{
get => _canLightDismiss;
set => SetProperty(ref _canLightDismiss, 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
{
get => _date;
set => SetProperty(ref _date, value);
}
public DialogDemoViewModel() public DialogDemoViewModel()
{ {
ShowDialogCommand = new AsyncRelayCommand(ShowDialog); ShowDialogCommand = new AsyncRelayCommand(ShowDialog);
ShowCustomDialogCommand = new AsyncRelayCommand(ShowCustomDialog); ShowCustomDialogCommand = new AsyncRelayCommand(ShowCustomDialog);
Modes = new ObservableCollection<DialogMode>(Enum.GetValues<DialogMode>()); IsModal = true;
Buttons = new ObservableCollection<DialogButton>(Enum.GetValues<DialogButton>()); IsGlobal = true;
} }
private async Task ShowDialog() private async Task ShowDialog()
@@ -123,6 +66,7 @@ public class DialogDemoViewModel: ObservableObject
HorizontalOffset = 50, HorizontalOffset = 50,
VerticalAnchor = VerticalPosition.Top, VerticalAnchor = VerticalPosition.Top,
VerticalOffset = 50, VerticalOffset = 50,
FullScreen = FullScreen,
} }
); );
Date = vm.Date; Date = vm.Date;
@@ -138,6 +82,7 @@ public class DialogDemoViewModel: ObservableObject
Mode = SelectedMode, Mode = SelectedMode,
Buttons = SelectedButton, Buttons = SelectedButton,
CanLightDismiss = CanLightDismiss, CanLightDismiss = CanLightDismiss,
FullScreen = FullScreen,
}); });
} }
} }
@@ -149,7 +94,6 @@ public class DialogDemoViewModel: ObservableObject
var vm = new DialogWithActionViewModel(); var vm = new DialogWithActionViewModel();
if (IsWindow) if (IsWindow)
{ {
if (IsModal) if (IsModal)
{ {
Result = await Dialog.ShowCustomModal<DialogWithAction, DialogWithActionViewModel, bool>( Result = await Dialog.ShowCustomModal<DialogWithAction, DialogWithActionViewModel, bool>(
@@ -161,7 +105,6 @@ public class DialogDemoViewModel: ObservableObject
Dialog.ShowCustom<DialogWithAction, DialogWithActionViewModel>( Dialog.ShowCustom<DialogWithAction, DialogWithActionViewModel>(
vm); vm);
} }
} }
else else
{ {
@@ -171,6 +114,7 @@ public class DialogDemoViewModel: ObservableObject
vm, IsGlobal ? null : "LocalHost", options: new OverlayDialogOptions() vm, IsGlobal ? null : "LocalHost", options: new OverlayDialogOptions()
{ {
CanLightDismiss = CanLightDismiss, CanLightDismiss = CanLightDismiss,
FullScreen = FullScreen,
}); });
Date = vm.Date; Date = vm.Date;
} }
@@ -178,7 +122,7 @@ public class DialogDemoViewModel: ObservableObject
{ {
OverlayDialog.ShowCustom<DialogWithAction, DialogWithActionViewModel>(new DialogWithActionViewModel(), OverlayDialog.ShowCustom<DialogWithAction, DialogWithActionViewModel>(new DialogWithActionViewModel(),
IsGlobal ? null : "LocalHost", IsGlobal ? null : "LocalHost",
options: new OverlayDialogOptions{ CanLightDismiss = CanLightDismiss }); options: new OverlayDialogOptions{ CanLightDismiss = CanLightDismiss, FullScreen = FullScreen});
} }
} }

View File

@@ -31,6 +31,9 @@ public partial class DrawerDemoViewModel: ObservableObject
{ {
ShowDialogCommand = new AsyncRelayCommand(ShowDefaultDialog); ShowDialogCommand = new AsyncRelayCommand(ShowDefaultDialog);
ShowCustomDialogCommand = new AsyncRelayCommand(ShowCustomDrawer); ShowCustomDialogCommand = new AsyncRelayCommand(ShowCustomDrawer);
SelectedPosition = Position.Right;
IsGlobal = true;
IsModal = true;
} }
private async Task ShowDefaultDialog() private async Task ShowDefaultDialog()

View File

@@ -18,7 +18,7 @@
<Setter Property="Template"> <Setter Property="Template">
<ControlTemplate TargetType="u:CustomDialogControl"> <ControlTemplate TargetType="u:CustomDialogControl">
<Border <Border
Margin="8" Name="PART_Border"
Padding="0" Padding="0"
HorizontalAlignment="Center" HorizontalAlignment="Center"
VerticalAlignment="Center" VerticalAlignment="Center"
@@ -45,15 +45,22 @@
Grid.Column="1" Grid.Column="1"
Margin="0,24,24,0" Margin="0,24,24,0"
DockPanel.Dock="Right" DockPanel.Dock="Right"
Theme="{DynamicResource CloseButton}" /> Theme="{DynamicResource OverlayCloseButton}" />
</Grid> </Grid>
</Grid> </Grid>
</Border> </Border>
</Border> </Border>
</ControlTemplate> </ControlTemplate>
</Setter> </Setter>
<Style Selector="^[IsClosed=True]"> <Style Selector="^:full-screen">
<Setter Property="RenderTransform" Value="scale(0.95)"/> <Setter Property="CornerRadius" Value="0"/>
<Style Selector="^ /template/ Border#PART_Border">
<Setter Property="HorizontalAlignment" Value="Stretch"/>
<Setter Property="VerticalAlignment" Value="Stretch"/>
<Setter Property="Theme" Value="{x:Null}"/>
<Setter Property="Margin" Value="0"/>
<Setter Property="Background" Value="{DynamicResource BorderCardBackground}"></Setter>
</Style>
</Style> </Style>
<Style Selector="^ /template/ Panel#PART_TitleArea"> <Style Selector="^ /template/ Panel#PART_TitleArea">
<Setter Property="ContextFlyout"> <Setter Property="ContextFlyout">
@@ -143,10 +150,10 @@
<Setter Property="Template"> <Setter Property="Template">
<ControlTemplate TargetType="u:DefaultDialogControl"> <ControlTemplate TargetType="u:DefaultDialogControl">
<Border <Border
Margin="10" Name="PART_Border"
Padding="0" Padding="0"
HorizontalAlignment="Center" HorizontalAlignment="{TemplateBinding HorizontalAlignment}"
VerticalAlignment="Center" VerticalAlignment="{TemplateBinding VerticalAlignment}"
BoxShadow="0 0 8 0 #1A000000" BoxShadow="0 0 8 0 #1A000000"
Classes="Shadow" Classes="Shadow"
ClipToBounds="False" ClipToBounds="False"
@@ -159,6 +166,8 @@
<ContentPresenter <ContentPresenter
Name="PART_ContentPresenter" Name="PART_ContentPresenter"
Grid.Row="1" Grid.Row="1"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Margin="24,8" Margin="24,8"
Content="{TemplateBinding Content}" /> Content="{TemplateBinding Content}" />
</ScrollViewer> </ScrollViewer>
@@ -192,7 +201,7 @@
Grid.Column="2" Grid.Column="2"
Margin="0,24,24,0" Margin="0,24,24,0"
DockPanel.Dock="Right" DockPanel.Dock="Right"
Theme="{DynamicResource CloseButton}" /> Theme="{DynamicResource OverlayCloseButton}" />
</Grid> </Grid>
<StackPanel <StackPanel
Grid.Row="2" Grid.Row="2"
@@ -228,8 +237,15 @@
</Border> </Border>
</ControlTemplate> </ControlTemplate>
</Setter> </Setter>
<Style Selector="^[IsClosed=True]"> <Style Selector="^:full-screen">
<Setter Property="RenderTransform" Value="scale(0.95)"/> <Setter Property="CornerRadius" Value="0"/>
</Style>
<Style Selector="^:full-screen /template/ Border#PART_Border">
<Setter Property="HorizontalAlignment" Value="Stretch"/>
<Setter Property="VerticalAlignment" Value="Stretch"/>
<Setter Property="Theme" Value="{x:Null}"/>
<Setter Property="Margin" Value="0"></Setter>
<Setter Property="Background" Value="{DynamicResource BorderCardBackground}"></Setter>
</Style> </Style>
<Style Selector="^[Mode=None]"> <Style Selector="^[Mode=None]">
<Style Selector="^ /template/ PathIcon#PART_Icon"> <Style Selector="^ /template/ PathIcon#PART_Icon">

View File

@@ -1,6 +1,5 @@
<ResourceDictionary xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> <ResourceDictionary xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<!-- Add Resources Here --> <!-- Add Resources Here -->
<ControlTheme x:Key="CloseButton" TargetType="Button"> <ControlTheme x:Key="CloseButton" TargetType="Button">
<Setter Property="CornerRadius" Value="6" /> <Setter Property="CornerRadius" Value="6" />
<Setter Property="Margin" Value="0, 4" /> <Setter Property="Margin" Value="0, 4" />
@@ -39,4 +38,34 @@
</Style> </Style>
</ControlTheme> </ControlTheme>
<ControlTheme x:Key="OverlayCloseButton" TargetType="Button">
<Setter Property="CornerRadius" Value="6" />
<Setter Property="Margin" Value="0, 4" />
<Setter Property="Padding" Value="4" />
<Setter Property="Height" Value="28" />
<Setter Property="Width" Value="28" />
<Setter Property="Cursor" Value="Hand" />
<Setter Property="VerticalAlignment" Value="Stretch" />
<Setter Property="Template">
<ControlTemplate TargetType="Button">
<Border
Name="PART_Border"
Padding="{TemplateBinding Padding}"
Background="Transparent"
CornerRadius="{TemplateBinding CornerRadius}">
<PathIcon
Width="12"
Height="12"
Data="{DynamicResource WindowCloseIconGlyph}"/>
</Border>
</ControlTemplate>
</Setter>
<Style Selector="^:pointerover /template/ Border">
<Setter Property="Background" Value="{DynamicResource ButtonDefaultPointeroverBackground}" />
</Style>
<Style Selector="^:pressed /template/ Border">
<Setter Property="Background" Value="{DynamicResource ButtonDefaultPressedBackground}" />
</Style>
</ControlTheme>
</ResourceDictionary> </ResourceDictionary>

View File

@@ -35,7 +35,7 @@
Grid.Column="1" Grid.Column="1"
Margin="0,24,24,0" Margin="0,24,24,0"
DockPanel.Dock="Right" DockPanel.Dock="Right"
Theme="{DynamicResource CloseButton}" /> Theme="{DynamicResource OverlayCloseButton}" />
</Grid> </Grid>
</Grid> </Grid>
</Border> </Border>
@@ -107,7 +107,7 @@
Grid.Column="1" Grid.Column="1"
Margin="0,24,24,0" Margin="0,24,24,0"
DockPanel.Dock="Right" DockPanel.Dock="Right"
Theme="{DynamicResource CloseButton}" /> Theme="{DynamicResource OverlayCloseButton}" />
</Grid> </Grid>
<StackPanel <StackPanel
Grid.Row="2" Grid.Row="2"

View File

@@ -150,6 +150,7 @@
<ControlTheme x:Key="{x:Type u:MessageBoxControl}" TargetType="u:MessageBoxControl"> <ControlTheme x:Key="{x:Type u:MessageBoxControl}" TargetType="u:MessageBoxControl">
<Setter Property="CornerRadius" Value="12" /> <Setter Property="CornerRadius" Value="12" />
<Setter Property="Padding" Value="48 24" /> <Setter Property="Padding" Value="48 24" />
<Setter Property="u:DialogControlBase.CanDragMove" Value="True"></Setter>
<Setter Property="Template"> <Setter Property="Template">
<ControlTemplate TargetType="u:MessageBoxControl"> <ControlTemplate TargetType="u:MessageBoxControl">
<Border <Border
@@ -192,7 +193,7 @@
Name="{x:Static u:MessageBoxWindow.PART_CloseButton}" Name="{x:Static u:MessageBoxWindow.PART_CloseButton}"
Grid.Column="2" Grid.Column="2"
Margin="0,24,24,0" Margin="0,24,24,0"
Theme="{DynamicResource CloseButton}" /> Theme="{DynamicResource OverlayCloseButton}" />
</Grid> </Grid>
<Grid <Grid
Grid.Row="1" Grid.Row="1"

View File

@@ -14,12 +14,13 @@ namespace Ursa.Controls;
[TemplatePart(PART_CloseButton, typeof(Button))] [TemplatePart(PART_CloseButton, typeof(Button))]
[TemplatePart(PART_TitleArea, typeof(Panel))] [TemplatePart(PART_TitleArea, typeof(Panel))]
[PseudoClasses(PC_Modal)] [PseudoClasses(PC_Modal, PC_FullScreen)]
public abstract class DialogControlBase : OverlayFeedbackElement public abstract class DialogControlBase : OverlayFeedbackElement
{ {
public const string PART_CloseButton = "PART_CloseButton"; public const string PART_CloseButton = "PART_CloseButton";
public const string PART_TitleArea = "PART_TitleArea"; public const string PART_TitleArea = "PART_TitleArea";
public const string PC_Modal = ":modal"; public const string PC_Modal = ":modal";
public const string PC_FullScreen = ":full-screen";
internal HorizontalPosition HorizontalAnchor { get; set; } = HorizontalPosition.Center; internal HorizontalPosition HorizontalAnchor { get; set; } = HorizontalPosition.Center;
internal VerticalPosition VerticalAnchor { get; set; } = VerticalPosition.Center; internal VerticalPosition VerticalAnchor { get; set; } = VerticalPosition.Center;
@@ -30,7 +31,17 @@ public abstract class DialogControlBase : OverlayFeedbackElement
internal double? HorizontalOffsetRatio { get; set; } internal double? HorizontalOffsetRatio { get; set; }
internal double? VerticalOffsetRatio { get; set; } internal double? VerticalOffsetRatio { get; set; }
internal bool CanLightDismiss { get; set; } internal bool CanLightDismiss { get; set; }
internal bool CanDragMove { get; set; }
private bool _isFullScreen;
public static readonly DirectProperty<DialogControlBase, bool> IsFullScreenProperty = AvaloniaProperty.RegisterDirect<DialogControlBase, bool>(
nameof(IsFullScreen), o => o.IsFullScreen, (o, v) => o.IsFullScreen = v);
public bool IsFullScreen
{
get => _isFullScreen;
set => SetAndRaise(IsFullScreenProperty, ref _isFullScreen, value);
}
protected internal Button? _closeButton; protected internal Button? _closeButton;
private Panel? _titleArea; private Panel? _titleArea;
@@ -134,6 +145,7 @@ public abstract class DialogControlBase : OverlayFeedbackElement
{ {
CanDragMoveProperty.Changed.AddClassHandler<InputElement, bool>(OnCanDragMoveChanged); CanDragMoveProperty.Changed.AddClassHandler<InputElement, bool>(OnCanDragMoveChanged);
CanCloseProperty.Changed.AddClassHandler<InputElement, bool>(OnCanCloseChanged); CanCloseProperty.Changed.AddClassHandler<InputElement, bool>(OnCanCloseChanged);
IsFullScreenProperty.AffectsPseudoClass<DialogControlBase>(PC_FullScreen);
} }
@@ -143,7 +155,7 @@ public abstract class DialogControlBase : OverlayFeedbackElement
{ {
base.OnApplyTemplate(e); base.OnApplyTemplate(e);
_titleArea = e.NameScope.Find<Panel>(PART_TitleArea); _titleArea = e.NameScope.Find<Panel>(PART_TitleArea);
if (CanDragMove) if (GetCanDragMove(this))
{ {
_titleArea?.RemoveHandler(PointerMovedEvent, OnTitlePointerMove); _titleArea?.RemoveHandler(PointerMovedEvent, OnTitlePointerMove);
_titleArea?.RemoveHandler(PointerPressedEvent, OnTitlePointerPressed); _titleArea?.RemoveHandler(PointerPressedEvent, OnTitlePointerPressed);

View File

@@ -17,6 +17,7 @@ public enum VerticalPosition
public class OverlayDialogOptions public class OverlayDialogOptions
{ {
internal static OverlayDialogOptions Default { get; } = new OverlayDialogOptions(); internal static OverlayDialogOptions Default { get; } = new OverlayDialogOptions();
public bool FullScreen { get; set; }
public HorizontalPosition HorizontalAnchor { get; set; } = HorizontalPosition.Center; public HorizontalPosition HorizontalAnchor { get; set; } = HorizontalPosition.Center;
public VerticalPosition VerticalAnchor { get; set; } = VerticalPosition.Center; public VerticalPosition VerticalAnchor { get; set; } = VerticalPosition.Center;
/// <summary> /// <summary>

View File

@@ -1,5 +1,6 @@
using Avalonia; using Avalonia;
using Avalonia.Controls; using Avalonia.Controls;
using Avalonia.Layout;
using Ursa.Common; using Ursa.Common;
namespace Ursa.Controls; namespace Ursa.Controls;
@@ -181,6 +182,12 @@ public static class OverlayDialog
private static void ConfigureCustomDialogControl(CustomDialogControl control, OverlayDialogOptions? options) private static void ConfigureCustomDialogControl(CustomDialogControl control, OverlayDialogOptions? options)
{ {
options ??= OverlayDialogOptions.Default; options ??= OverlayDialogOptions.Default;
control.IsFullScreen = options.FullScreen;
if (options.FullScreen)
{
control.HorizontalAlignment = HorizontalAlignment.Stretch;
control.VerticalAlignment = VerticalAlignment.Stretch;
}
control.HorizontalAnchor = options.HorizontalAnchor; control.HorizontalAnchor = options.HorizontalAnchor;
control.VerticalAnchor = options.VerticalAnchor; control.VerticalAnchor = options.VerticalAnchor;
control.ActualHorizontalAnchor = options.HorizontalAnchor; control.ActualHorizontalAnchor = options.HorizontalAnchor;
@@ -191,12 +198,18 @@ public static class OverlayDialog
options.VerticalAnchor == VerticalPosition.Center ? null : options.VerticalOffset; options.VerticalAnchor == VerticalPosition.Center ? null : options.VerticalOffset;
control.IsCloseButtonVisible = options.ShowCloseButton; control.IsCloseButtonVisible = options.ShowCloseButton;
control.CanLightDismiss = options.CanLightDismiss; control.CanLightDismiss = options.CanLightDismiss;
control.CanDragMove = options.CanDragMove; DialogControlBase.SetCanDragMove(control, options.CanDragMove);
} }
private static void ConfigureDefaultDialogControl(DefaultDialogControl control, OverlayDialogOptions? options) private static void ConfigureDefaultDialogControl(DefaultDialogControl control, OverlayDialogOptions? options)
{ {
if (options is null) options = new OverlayDialogOptions(); if (options is null) options = new OverlayDialogOptions();
control.IsFullScreen = options.FullScreen;
if (options.FullScreen)
{
control.HorizontalAlignment = HorizontalAlignment.Stretch;
control.VerticalAlignment = VerticalAlignment.Stretch;
}
control.HorizontalAnchor = options.HorizontalAnchor; control.HorizontalAnchor = options.HorizontalAnchor;
control.VerticalAnchor = options.VerticalAnchor; control.VerticalAnchor = options.VerticalAnchor;
control.ActualHorizontalAnchor = options.HorizontalAnchor; control.ActualHorizontalAnchor = options.HorizontalAnchor;
@@ -209,7 +222,7 @@ public static class OverlayDialog
control.Buttons = options.Buttons; control.Buttons = options.Buttons;
control.Title = options.Title; control.Title = options.Title;
control.CanLightDismiss = options.CanLightDismiss; control.CanLightDismiss = options.CanLightDismiss;
control.CanDragMove = options.CanDragMove; DialogControlBase.SetCanDragMove(control, options.CanDragMove);
} }
internal static T? Recall<T>(string? hostId) where T: Control internal static T? Recall<T>(string? hostId) where T: Control

View File

@@ -14,6 +14,14 @@ public partial class OverlayDialogHost
private static void ResetDialogPosition(DialogControlBase control, Size newSize) private static void ResetDialogPosition(DialogControlBase control, Size newSize)
{ {
if (control.IsFullScreen)
{
control.Width = newSize.Width;
control.Height = newSize.Height;
SetLeft(control, 0);
SetTop(control, 0);
return;
}
var width = newSize.Width - control.Bounds.Width; var width = newSize.Width - control.Bounds.Width;
var height = newSize.Height - control.Bounds.Height; var height = newSize.Height - control.Bounds.Height;
var newLeft = width * control.HorizontalOffsetRatio??0; var newLeft = width * control.HorizontalOffsetRatio??0;
@@ -84,6 +92,11 @@ public partial class OverlayDialogHost
} }
this.Children.Add(control); this.Children.Add(control);
_layers.Add(new DialogPair(mask, control, false)); _layers.Add(new DialogPair(mask, control, false));
if (control.IsFullScreen)
{
control.Width = Bounds.Width;
control.Height = Bounds.Height;
}
control.Measure(this.Bounds.Size); control.Measure(this.Bounds.Size);
control.Arrange(new Rect(control.DesiredSize)); control.Arrange(new Rect(control.DesiredSize));
SetToPosition(control); SetToPosition(control);
@@ -113,9 +126,12 @@ public partial class OverlayDialogHost
{ {
_modalCount--; _modalCount--;
HasModal = _modalCount > 0; HasModal = _modalCount > 0;
if (!IsAnimationDisabled)
{
await _maskDisappearAnimation.RunAsync(layer.Mask); await _maskDisappearAnimation.RunAsync(layer.Mask);
} }
} }
}
ResetZIndices(); ResetZIndices();
} }
@@ -133,12 +149,20 @@ public partial class OverlayDialogHost
ResetZIndices(); ResetZIndices();
this.Children.Add(mask); this.Children.Add(mask);
this.Children.Add(control); this.Children.Add(control);
if (control.IsFullScreen)
{
control.Width = Bounds.Width;
control.Height = Bounds.Height;
}
control.Measure(this.Bounds.Size); control.Measure(this.Bounds.Size);
control.Arrange(new Rect(control.DesiredSize)); control.Arrange(new Rect(control.DesiredSize));
SetToPosition(control); SetToPosition(control);
control.AddHandler(OverlayFeedbackElement.ClosedEvent, OnDialogControlClosing); control.AddHandler(OverlayFeedbackElement.ClosedEvent, OnDialogControlClosing);
control.AddHandler(DialogControlBase.LayerChangedEvent, OnDialogLayerChanged); control.AddHandler(DialogControlBase.LayerChangedEvent, OnDialogLayerChanged);
if (!IsAnimationDisabled)
{
_maskAppearAnimation.RunAsync(mask); _maskAppearAnimation.RunAsync(mask);
}
_modalCount++; _modalCount++;
HasModal = _modalCount > 0; HasModal = _modalCount > 0;
control.IsClosed = false; control.IsClosed = false;

View File

@@ -28,6 +28,12 @@ public partial class OverlayDialogHost
SetDrawerPosition(control); SetDrawerPosition(control);
control.AddHandler(OverlayFeedbackElement.ClosedEvent, OnDrawerControlClosing); control.AddHandler(OverlayFeedbackElement.ClosedEvent, OnDrawerControlClosing);
var animation = CreateAnimation(control.Bounds.Size, control.Position, true); var animation = CreateAnimation(control.Bounds.Size, control.Position, true);
if (IsAnimationDisabled)
{
ResetDrawerPosition(control, this.Bounds.Size);
}
else
{
if (mask is null) if (mask is null)
{ {
await animation.RunAsync(control); await animation.RunAsync(control);
@@ -37,6 +43,7 @@ public partial class OverlayDialogHost
await Task.WhenAll(animation.RunAsync(control), _maskAppearAnimation.RunAsync(mask)); await Task.WhenAll(animation.RunAsync(control), _maskAppearAnimation.RunAsync(mask));
} }
} }
}
internal async void AddModalDrawer(DrawerControlBase control) internal async void AddModalDrawer(DrawerControlBase control)
{ {
@@ -48,10 +55,19 @@ public partial class OverlayDialogHost
control.Measure(this.Bounds.Size); control.Measure(this.Bounds.Size);
control.Arrange(new Rect(control.DesiredSize)); control.Arrange(new Rect(control.DesiredSize));
SetDrawerPosition(control); SetDrawerPosition(control);
_modalCount++;
HasModal = _modalCount > 0;
control.AddHandler(OverlayFeedbackElement.ClosedEvent, OnDrawerControlClosing); control.AddHandler(OverlayFeedbackElement.ClosedEvent, OnDrawerControlClosing);
var animation = CreateAnimation(control.Bounds.Size, control.Position); var animation = CreateAnimation(control.Bounds.Size, control.Position);
if (IsAnimationDisabled)
{
ResetDrawerPosition(control, this.Bounds.Size);
}
else
{
await Task.WhenAll(animation.RunAsync(control), _maskAppearAnimation.RunAsync(mask)); await Task.WhenAll(animation.RunAsync(control), _maskAppearAnimation.RunAsync(mask));
} }
}
private void SetDrawerPosition(DrawerControlBase control) private void SetDrawerPosition(DrawerControlBase control)
{ {
@@ -145,16 +161,24 @@ public partial class OverlayDialogHost
control.RemoveHandler(DialogControlBase.LayerChangedEvent, OnDialogLayerChanged); control.RemoveHandler(DialogControlBase.LayerChangedEvent, OnDialogLayerChanged);
if (layer.Mask is not null) if (layer.Mask is not null)
{ {
_modalCount--;
HasModal = _modalCount > 0;
layer.Mask.RemoveHandler(PointerPressedEvent, ClickMaskToCloseDialog); layer.Mask.RemoveHandler(PointerPressedEvent, ClickMaskToCloseDialog);
if (!IsAnimationDisabled)
{
var disappearAnimation = CreateAnimation(control.Bounds.Size, control.Position, false); var disappearAnimation = CreateAnimation(control.Bounds.Size, control.Position, false);
await Task.WhenAll(disappearAnimation.RunAsync(control), _maskDisappearAnimation.RunAsync(layer.Mask)); await Task.WhenAll(disappearAnimation.RunAsync(control), _maskDisappearAnimation.RunAsync(layer.Mask));
}
Children.Remove(layer.Mask); Children.Remove(layer.Mask);
} }
else else
{
if (!IsAnimationDisabled)
{ {
var disappearAnimation = CreateAnimation(control.Bounds.Size, control.Position, false); var disappearAnimation = CreateAnimation(control.Bounds.Size, control.Position, false);
await disappearAnimation.RunAsync(control); await disappearAnimation.RunAsync(control);
} }
}
Children.Remove(control); Children.Remove(control);
ResetZIndices(); ResetZIndices();
} }

View File

@@ -15,7 +15,7 @@ public partial class OverlayDialogHost: Canvas
private static readonly Animation _maskAppearAnimation; private static readonly Animation _maskAppearAnimation;
private static readonly Animation _maskDisappearAnimation; private static readonly Animation _maskDisappearAnimation;
private readonly List<DialogPair> _layers = new List<DialogPair>(); private readonly List<DialogPair> _layers = new List<DialogPair>(10);
private class DialogPair private class DialogPair
{ {
@@ -44,6 +44,8 @@ public partial class OverlayDialogHost: Canvas
private set => SetAndRaise(HasModalProperty, ref _hasModal, value); private set => SetAndRaise(HasModalProperty, ref _hasModal, value);
} }
public bool IsAnimationDisabled { get; set; }
static OverlayDialogHost() static OverlayDialogHost()
{ {
ClipToBoundsProperty.OverrideDefaultValue<OverlayDialogHost>(true); ClipToBoundsProperty.OverrideDefaultValue<OverlayDialogHost>(true);