Skip to content

Commit

Permalink
feat!: Add possibility to specify VerticalAlignment and HorizontalAli…
Browse files Browse the repository at this point in the history
…gnment for ContentDialogs
  • Loading branch information
sandre58 committed Jun 5, 2024
1 parent 44fc001 commit 652b72c
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 10 deletions.
4 changes: 1 addition & 3 deletions src/MyNet.Wpf/Controls/OverlayDialogControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,6 @@ public bool CloseOnClickAway

#endregion


#region FocusOnShow

public static readonly DependencyProperty FocusOnShowProperty = DependencyProperty.Register(
Expand All @@ -192,7 +191,6 @@ public bool FocusOnShow

#endregion


#region OverlayBackground

public static readonly DependencyProperty OverlayBackgroundProperty = DependencyProperty.Register(
Expand Down Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions src/MyNet.Wpf/Dialogs/IOverlayDialog.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
// 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
{
bool CloseOnClickAway { get; }

bool FocusOnShow { get; }

VerticalAlignment VerticalAlignment { get; }

HorizontalAlignment HorizontalAlignment { get; }
}
}
10 changes: 8 additions & 2 deletions src/MyNet.Wpf/Dialogs/OverlayDialogService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 3 additions & 1 deletion src/MyNet.Wpf/Styles/MyNet.ContentDialog.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
<Setter Property="HeaderForeground" Value="{DynamicResource MyNet.Brushes.Application.Foreground}" />
<Setter Property="HeaderHeight" Value="30" />
<Setter Property="HeaderPadding" Value="{StaticResource MyNet.Margins.Default}" />
<Setter Property="HorizontalAlignment" Value="Stretch" />
<Setter Property="VerticalAlignment" Value="Center" />
<Setter Property="HorizontalAlignment" Value="Center" />
<Setter Property="VerticalContentAlignment" Value="Stretch" />
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
<Setter Property="IsTabStop" Value="False" />
<Setter Property="Padding" Value="{StaticResource MyNet.Margins.Medium}" />
Expand Down
6 changes: 4 additions & 2 deletions src/MyNet.Wpf/Styles/MyNet.OverlayDialogControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
<Setter Property="FontSize" Value="{Binding Path=(TextElement.FontSize), RelativeSource={RelativeSource AncestorType={x:Type FrameworkElement}}}" />
<Setter Property="Foreground" Value="{DynamicResource MyNet.Brushes.Application.Foreground}" />
<Setter Property="OverlayBackground" Value="{DynamicResource MyNet.Brushes.Overlay}" />
<Setter Property="VerticalContentAlignment" Value="Center" />
<Setter Property="HorizontalContentAlignment" Value="Center" />
<Setter Property="Padding" Value="50" />
<Setter Property="Template">
<Setter.Value>
Expand Down Expand Up @@ -145,8 +147,8 @@
<ctrl:Card x:Name="PART_ContentElement"
Margin="{TemplateBinding Padding}"
Padding="0"
HorizontalAlignment="Center"
VerticalAlignment="Center"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
p:ElevationAssist.Elevation="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(p:ElevationAssist.Elevation)}"
Background="{TemplateBinding Background}"
Content="{TemplateBinding Content}"
Expand Down
8 changes: 6 additions & 2 deletions src/MyNet.Wpf/Themes/MyNet.Styles.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -6948,6 +6948,8 @@ Styles\MyNet.VirtualizingWrapPanel.xaml
<Setter Property="FontSize" Value="{Binding Path=(TextElement.FontSize), RelativeSource={RelativeSource AncestorType={x:Type FrameworkElement}}}" />
<Setter Property="Foreground" Value="{DynamicResource MyNet.Brushes.Application.Foreground}" />
<Setter Property="OverlayBackground" Value="{DynamicResource MyNet.Brushes.Overlay}" />
<Setter Property="VerticalContentAlignment" Value="Center" />
<Setter Property="HorizontalContentAlignment" Value="Center" />
<Setter Property="Padding" Value="50" />
<Setter Property="Template">
<Setter.Value>
Expand Down Expand Up @@ -7054,7 +7056,7 @@ Styles\MyNet.VirtualizingWrapPanel.xaml
<MouseBinding Command="{x:Static ctrl:OverlayDialogControl.CloseDialogCommand}" MouseAction="LeftClick" />
</Border.InputBindings>
</Border>
<ctrl:Card x:Name="PART_ContentElement" Margin="{TemplateBinding Padding}" Padding="0" HorizontalAlignment="Center" VerticalAlignment="Center" p:ElevationAssist.Elevation="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(p:ElevationAssist.Elevation)}" Background="{TemplateBinding Background}" Content="{TemplateBinding Content}" ContentTemplate="{TemplateBinding ContentTemplate}" ContentTemplateSelector="{TemplateBinding ContentTemplateSelector}" FocusManager.IsFocusScope="False" Focusable="False" FontFamily="{TemplateBinding FontFamily}" FontSize="{TemplateBinding FontSize}" FontStretch="{TemplateBinding FontStretch}" FontStyle="{TemplateBinding FontStyle}" FontWeight="{TemplateBinding FontWeight}" Foreground="{TemplateBinding Foreground}" IsHitTestVisible="True" IsTabStop="False" Opacity="0" RenderTransformOrigin=".5,.5" TextElement.FontFamily="{TemplateBinding FontFamily}" TextElement.FontSize="{TemplateBinding FontSize}" TextElement.FontStretch="{TemplateBinding FontStretch}" TextElement.FontStyle="{TemplateBinding FontStyle}" TextElement.FontWeight="{TemplateBinding FontWeight}" TextElement.Foreground="{TemplateBinding Foreground}" TextOptions.TextFormattingMode="Ideal" TextOptions.TextRenderingMode="Auto" UniformCornerRadius="{StaticResource MyNet.UniformCornerRadius.Container}">
<ctrl:Card x:Name="PART_ContentElement" Margin="{TemplateBinding Padding}" Padding="0" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" p:ElevationAssist.Elevation="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(p:ElevationAssist.Elevation)}" Background="{TemplateBinding Background}" Content="{TemplateBinding Content}" ContentTemplate="{TemplateBinding ContentTemplate}" ContentTemplateSelector="{TemplateBinding ContentTemplateSelector}" FocusManager.IsFocusScope="False" Focusable="False" FontFamily="{TemplateBinding FontFamily}" FontSize="{TemplateBinding FontSize}" FontStretch="{TemplateBinding FontStretch}" FontStyle="{TemplateBinding FontStyle}" FontWeight="{TemplateBinding FontWeight}" Foreground="{TemplateBinding Foreground}" IsHitTestVisible="True" IsTabStop="False" Opacity="0" RenderTransformOrigin=".5,.5" TextElement.FontFamily="{TemplateBinding FontFamily}" TextElement.FontSize="{TemplateBinding FontSize}" TextElement.FontStretch="{TemplateBinding FontStretch}" TextElement.FontStyle="{TemplateBinding FontStyle}" TextElement.FontWeight="{TemplateBinding FontWeight}" TextElement.Foreground="{TemplateBinding Foreground}" TextOptions.TextFormattingMode="Ideal" TextOptions.TextRenderingMode="Auto" UniformCornerRadius="{StaticResource MyNet.UniformCornerRadius.Container}">
<ctrl:Card.RenderTransform>
<TransformGroup>
<ScaleTransform x:Name="CardScaleTransform" ScaleX="0" ScaleY="0" />
Expand Down Expand Up @@ -13733,7 +13735,9 @@ Styles\MyNet.VirtualizingWrapPanel.xaml
<Setter Property="HeaderForeground" Value="{DynamicResource MyNet.Brushes.Application.Foreground}" />
<Setter Property="HeaderHeight" Value="30" />
<Setter Property="HeaderPadding" Value="{StaticResource MyNet.Margins.Default}" />
<Setter Property="HorizontalAlignment" Value="Stretch" />
<Setter Property="VerticalAlignment" Value="Center" />
<Setter Property="HorizontalAlignment" Value="Center" />
<Setter Property="VerticalContentAlignment" Value="Stretch" />
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
<Setter Property="IsTabStop" Value="False" />
<Setter Property="Padding" Value="{StaticResource MyNet.Margins.Medium}" />
Expand Down

0 comments on commit 652b72c

Please sign in to comment.