From 652b72c4f86ee9faa103f068801e3bbcffcaaf2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20ANDRE?= Date: Wed, 5 Jun 2024 09:18:52 +0200 Subject: [PATCH] feat!: Add possibility to specify VerticalAlignment and HorizontalAlignment for ContentDialogs --- src/MyNet.Wpf/Controls/OverlayDialogControl.cs | 4 +--- src/MyNet.Wpf/Dialogs/IOverlayDialog.cs | 6 ++++++ src/MyNet.Wpf/Dialogs/OverlayDialogService.cs | 10 ++++++++-- src/MyNet.Wpf/Styles/MyNet.ContentDialog.xaml | 4 +++- src/MyNet.Wpf/Styles/MyNet.OverlayDialogControl.xaml | 6 ++++-- src/MyNet.Wpf/Themes/MyNet.Styles.xaml | 8 ++++++-- 6 files changed, 28 insertions(+), 10 deletions(-) diff --git a/src/MyNet.Wpf/Controls/OverlayDialogControl.cs b/src/MyNet.Wpf/Controls/OverlayDialogControl.cs index 853ed66..cd0027c 100644 --- a/src/MyNet.Wpf/Controls/OverlayDialogControl.cs +++ b/src/MyNet.Wpf/Controls/OverlayDialogControl.cs @@ -175,7 +175,6 @@ public bool CloseOnClickAway #endregion - #region FocusOnShow public static readonly DependencyProperty FocusOnShowProperty = DependencyProperty.Register( @@ -192,7 +191,6 @@ public bool FocusOnShow #endregion - #region OverlayBackground public static readonly DependencyProperty OverlayBackgroundProperty = DependencyProperty.Register( @@ -300,7 +298,7 @@ internal async Task InternalCloseAsync(bool? dialogResult = false) if (!canClose) dialogClosingEventArgs.Cancel(); - Dispatcher.Invoke(() => + await Dispatcher.InvokeAsync(() => { //multiple ways of calling back that the dialog is closing: // * routed event diff --git a/src/MyNet.Wpf/Dialogs/IOverlayDialog.cs b/src/MyNet.Wpf/Dialogs/IOverlayDialog.cs index faa1dbc..2fc09fa 100644 --- a/src/MyNet.Wpf/Dialogs/IOverlayDialog.cs +++ b/src/MyNet.Wpf/Dialogs/IOverlayDialog.cs @@ -1,6 +1,8 @@ // Copyright (c) Stéphane ANDRE. All Right Reserved. // See the LICENSE file in the project root for more information. +using System.Windows; + namespace MyNet.Wpf.Dialogs { public interface IOverlayDialog @@ -8,5 +10,9 @@ public interface IOverlayDialog bool CloseOnClickAway { get; } bool FocusOnShow { get; } + + VerticalAlignment VerticalAlignment { get; } + + HorizontalAlignment HorizontalAlignment { get; } } } diff --git a/src/MyNet.Wpf/Dialogs/OverlayDialogService.cs b/src/MyNet.Wpf/Dialogs/OverlayDialogService.cs index ae5b040..30c7a2b 100644 --- a/src/MyNet.Wpf/Dialogs/OverlayDialogService.cs +++ b/src/MyNet.Wpf/Dialogs/OverlayDialogService.cs @@ -71,8 +71,14 @@ private OverlayDialogControl GetOverlayDialogControl(object view, IDialogViewMod control.AssociatedControl = _associatedControl; var overlayDialogObject = viewModel is IOverlayDialog overlayDialogViewModel ? overlayDialogViewModel : view is IOverlayDialog overlayDialogView ? overlayDialogView : null; - control.CloseOnClickAway = overlayDialogObject?.CloseOnClickAway ?? false; - control.FocusOnShow = overlayDialogObject?.FocusOnShow ?? true; + + if (overlayDialogObject is not null) + { + control.CloseOnClickAway = overlayDialogObject.CloseOnClickAway; + control.FocusOnShow = overlayDialogObject.FocusOnShow; + control.VerticalContentAlignment = overlayDialogObject.VerticalAlignment; + control.HorizontalContentAlignment = overlayDialogObject.HorizontalAlignment; + } // Load view Model on openning control control.Opened += OnControlOpened; diff --git a/src/MyNet.Wpf/Styles/MyNet.ContentDialog.xaml b/src/MyNet.Wpf/Styles/MyNet.ContentDialog.xaml index 9da0d31..49ee363 100644 --- a/src/MyNet.Wpf/Styles/MyNet.ContentDialog.xaml +++ b/src/MyNet.Wpf/Styles/MyNet.ContentDialog.xaml @@ -18,7 +18,9 @@ - + + + diff --git a/src/MyNet.Wpf/Styles/MyNet.OverlayDialogControl.xaml b/src/MyNet.Wpf/Styles/MyNet.OverlayDialogControl.xaml index 8d9c084..03eaf39 100644 --- a/src/MyNet.Wpf/Styles/MyNet.OverlayDialogControl.xaml +++ b/src/MyNet.Wpf/Styles/MyNet.OverlayDialogControl.xaml @@ -16,6 +16,8 @@ + + @@ -145,8 +147,8 @@ + + @@ -7054,7 +7056,7 @@ Styles\MyNet.VirtualizingWrapPanel.xaml - + @@ -13733,7 +13735,9 @@ Styles\MyNet.VirtualizingWrapPanel.xaml - + + +