Skip to content

Commit

Permalink
Merge pull request #4354 from Keboo/fix4350
Browse files Browse the repository at this point in the history
Adding the ability for the dialog title to contain arbitrary content
  • Loading branch information
punker76 authored Oct 8, 2022
2 parents 135e84c + 06385f1 commit 6bce9f8
Show file tree
Hide file tree
Showing 13 changed files with 133 additions and 51 deletions.
6 changes: 3 additions & 3 deletions src/MahApps.Metro.Samples/MahApps.Metro.Demo/MainWindow.xaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<mah:MetroWindow x:Class="MetroDemo.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controlzEx="urn:controlzex"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:exampleViews="clr-namespace:MetroDemo.ExampleViews"
xmlns:iconPacks="http://metro.mahapps.com/winfx/xaml/iconpacks"
xmlns:local="clr-namespace:MetroDemo"
xmlns:mah="http://metro.mahapps.com/winfx/xaml/controls"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:controlzEx="urn:controlzex"
Title="MahApps.Metro - Demo Application"
Width="1024"
Height="768"
Expand Down Expand Up @@ -245,9 +245,9 @@
IsCheckable="True"
IsChecked="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type mah:MetroWindow}}, Path=PreferDWMBorderColor}" />
<MenuItem Header="DWMSupportsBorderColor"
IsEnabled="False"
IsCheckable="True"
IsChecked="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type mah:MetroWindow}}, Path=DWMSupportsBorderColor}" />
IsChecked="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type mah:MetroWindow}}, Path=DWMSupportsBorderColor}"
IsEnabled="False" />
</MenuItem>
<MenuItem Header="ShowTitleBar"
IsCheckable="True"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ protected override AutomationControlType GetAutomationControlTypeCore()
protected override string GetNameCore()
{
var nameCore = base.GetNameCore();
if (string.IsNullOrEmpty(nameCore))
if (string.IsNullOrEmpty(nameCore) && ((BaseMetroDialog)this.Owner).Title is string title)
{
nameCore = ((BaseMetroDialog)this.Owner).Title;
nameCore = title;
}

if (string.IsNullOrEmpty(nameCore))
{
nameCore = ((BaseMetroDialog)this.Owner).Name;
Expand Down
8 changes: 4 additions & 4 deletions src/MahApps.Metro/Controls/Dialogs/BaseMetroDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,16 @@ public GridLength DialogContentWidth
/// <summary>Identifies the <see cref="Title"/> dependency property.</summary>
public static readonly DependencyProperty TitleProperty
= DependencyProperty.Register(nameof(Title),
typeof(string),
typeof(object),
typeof(BaseMetroDialog),
new PropertyMetadata(default(string)));
new PropertyMetadata(default(object)));

/// <summary>
/// Gets or sets the title of the dialog.
/// </summary>
public string? Title
public object? Title
{
get => (string?)this.GetValue(TitleProperty);
get => (object?)this.GetValue(TitleProperty);
set => this.SetValue(TitleProperty, value);
}

Expand Down
8 changes: 4 additions & 4 deletions src/MahApps.Metro/Controls/Dialogs/DialogManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public static class DialogManager
/// <param name="message">The message contained within the LoginDialog.</param>
/// <param name="settings">Optional settings that override the global metro dialog settings.</param>
/// <returns>The text that was entered or null (Nothing in Visual Basic) if the user cancelled the operation.</returns>
public static async Task<LoginDialogData?> ShowLoginAsync(this MetroWindow window, string title, string message, LoginDialogSettings? settings = null)
public static async Task<LoginDialogData?> ShowLoginAsync(this MetroWindow window, object title, string message, LoginDialogSettings? settings = null)
{
window.Dispatcher.VerifyAccess();

Expand Down Expand Up @@ -73,7 +73,7 @@ public static class DialogManager
/// <param name="message">The message contained within the MessageDialog.</param>
/// <param name="settings">Optional settings that override the global metro dialog settings.</param>
/// <returns>The text that was entered or null (Nothing in Visual Basic) if the user cancelled the operation.</returns>
public static async Task<string?> ShowInputAsync(this MetroWindow window, string title, string message, MetroDialogSettings? settings = null)
public static async Task<string?> ShowInputAsync(this MetroWindow window, object title, string message, MetroDialogSettings? settings = null)
{
window.Dispatcher.VerifyAccess();

Expand Down Expand Up @@ -124,7 +124,7 @@ public static class DialogManager
/// <param name="style">The type of buttons to use.</param>
/// <param name="settings">Optional settings that override the global metro dialog settings.</param>
/// <returns>A task promising the result of which button was pressed.</returns>
public static async Task<MessageDialogResult> ShowMessageAsync(this MetroWindow window, string title, string message, MessageDialogStyle style = MessageDialogStyle.Affirmative, MetroDialogSettings? settings = null)
public static async Task<MessageDialogResult> ShowMessageAsync(this MetroWindow window, object title, string message, MessageDialogStyle style = MessageDialogStyle.Affirmative, MetroDialogSettings? settings = null)
{
window.Dispatcher.VerifyAccess();

Expand Down Expand Up @@ -175,7 +175,7 @@ public static async Task<MessageDialogResult> ShowMessageAsync(this MetroWindow
/// <param name="isCancelable">Determines if the cancel button is visible.</param>
/// <param name="settings">Optional Settings that override the global metro dialog settings.</param>
/// <returns>A task promising the instance of ProgressDialogController for this operation.</returns>
public static async Task<ProgressDialogController> ShowProgressAsync(this MetroWindow window, string title, string message, bool isCancelable = false, MetroDialogSettings? settings = null)
public static async Task<ProgressDialogController> ShowProgressAsync(this MetroWindow window, object title, string message, bool isCancelable = false, MetroDialogSettings? settings = null)
{
window.Dispatcher.VerifyAccess();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public void SetMessage(string message)
/// Sets the dialog's title.
/// </summary>
/// <param name="title">The title to be set.</param>
public void SetTitle(string title)
public void SetTitle(object title)
{
this.WrappedDialog.Invoke(() => this.WrappedDialog.Title = title);
}
Expand Down
4 changes: 2 additions & 2 deletions src/MahApps.Metro/Styles/Controls.Buttons.xaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controlzex="urn:controlzex"
xmlns:mah="clr-namespace:MahApps.Metro.Controls"
xmlns:mahConverters="clr-namespace:MahApps.Metro.Converters"
xmlns:controlzex="urn:controlzex">
xmlns:mahConverters="clr-namespace:MahApps.Metro.Converters">

<mahConverters:ThicknessToDoubleConverter x:Key="BorderThicknessToStrokeThicknessConverter" TakeThicknessSide="Left" />

Expand Down
19 changes: 12 additions & 7 deletions src/MahApps.Metro/Themes/Dialogs/BaseMetroDialog.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,18 @@
<RowDefinition Height="*" />
</Grid.RowDefinitions>

<TextBlock x:Name="PART_Title"
Grid.Row="0"
AutomationProperties.Name="Dialog title"
FontSize="{TemplateBinding DialogTitleFontSize}"
Foreground="{TemplateBinding Foreground}"
Text="{TemplateBinding Title}"
TextWrapping="Wrap" />
<ContentPresenter x:Name="PART_Title"
Grid.Row="0"
AutomationProperties.Name="Dialog title"
Content="{TemplateBinding Title}"
TextElement.FontSize="{TemplateBinding DialogTitleFontSize}"
TextElement.Foreground="{TemplateBinding Foreground}">
<ContentPresenter.Resources>
<Style BasedOn="{StaticResource {x:Type TextBlock}}" TargetType="TextBlock">
<Setter Property="TextWrapping" Value="Wrap" />
</Style>
</ContentPresenter.Resources>
</ContentPresenter>

<ContentPresenter x:Name="PART_Content"
Grid.Row="1"
Expand Down
14 changes: 7 additions & 7 deletions src/MahApps.Metro/Themes/MetroWindow.xaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controlzEx="urn:controlzex"
xmlns:mah="clr-namespace:MahApps.Metro.Controls"
Expand Down Expand Up @@ -54,9 +54,9 @@
HorizontalContentAlignment="Stretch"
VerticalContentAlignment="Stretch"
Panel.ZIndex="1"
controlzEx:WindowChrome.IsHitTestVisibleInChrome="True"
Content="{TemplateBinding Icon}"
ContentTemplate="{TemplateBinding IconTemplate}"
controlzEx:WindowChrome.IsHitTestVisibleInChrome="True"
Focusable="False"
Visibility="{TemplateBinding ShowIconOnTitleBar, Converter={StaticResource BooleanToVisibilityConverter}}" />

Expand Down Expand Up @@ -204,10 +204,10 @@
<ResizeGrip x:Name="WindowResizeGrip"
HorizontalAlignment="Right"
VerticalAlignment="Bottom"
controlzEx:WindowChrome.ResizeGripDirection="BottomRight"
IsTabStop="False"
UseLayoutRounding="True"
Visibility="Collapsed"
controlzEx:WindowChrome.ResizeGripDirection="BottomRight" />
Visibility="Collapsed" />
</Grid>

<ControlTemplate.Triggers>
Expand Down Expand Up @@ -299,9 +299,9 @@
HorizontalContentAlignment="Stretch"
VerticalContentAlignment="Stretch"
Panel.ZIndex="1"
controlzEx:WindowChrome.IsHitTestVisibleInChrome="True"
Content="{TemplateBinding Icon}"
ContentTemplate="{TemplateBinding IconTemplate}"
controlzEx:WindowChrome.IsHitTestVisibleInChrome="True"
Focusable="False"
Visibility="{TemplateBinding ShowIconOnTitleBar, Converter={StaticResource BooleanToVisibilityConverter}}" />

Expand Down Expand Up @@ -456,10 +456,10 @@
<ResizeGrip x:Name="WindowResizeGrip"
HorizontalAlignment="Right"
VerticalAlignment="Bottom"
controlzEx:WindowChrome.ResizeGripDirection="BottomRight"
IsTabStop="False"
UseLayoutRounding="True"
Visibility="Collapsed"
controlzEx:WindowChrome.ResizeGripDirection="BottomRight" />
Visibility="Collapsed" />
</Grid>

<ControlTemplate.Resources>
Expand Down
28 changes: 14 additions & 14 deletions src/MahApps.Metro/Themes/WindowButtonCommands.xaml
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controlzex="urn:controlzex"
xmlns:mah="clr-namespace:MahApps.Metro.Controls"
xmlns:mahConverters="clr-namespace:MahApps.Metro.Converters"
xmlns:controlzex="urn:controlzex">
xmlns:mahConverters="clr-namespace:MahApps.Metro.Converters">

<!-- WindowButtonCommands control templates -->

<ControlTemplate x:Key="MahApps.Templates.WindowButtonCommands" TargetType="{x:Type mah:WindowButtonCommands}">
<StackPanel Orientation="Horizontal">
<Button x:Name="PART_Min"
AutomationProperties.AutomationId="Minimize"
AutomationProperties.Name="Minimize"
controlzex:NonClientControlProperties.ClickStrategy="MouseEvent"
controlzex:NonClientControlProperties.HitTestResult="MINBUTTON"
AutomationProperties.AutomationId="Minimize"
AutomationProperties.Name="Minimize"
Command="{x:Static SystemCommands.MinimizeWindowCommand}"
Focusable="False"
IsEnabled="{Binding IsMinButtonEnabled, RelativeSource={RelativeSource AncestorType={x:Type mah:MetroWindow}}}"
Expand All @@ -35,10 +35,10 @@
SnapsToDevicePixels="True" />
</Button>
<Button x:Name="PART_Max"
AutomationProperties.AutomationId="MaximizeRestore"
AutomationProperties.Name="Maximize"
controlzex:NonClientControlProperties.ClickStrategy="MouseEvent"
controlzex:NonClientControlProperties.HitTestResult="MAXBUTTON"
AutomationProperties.AutomationId="MaximizeRestore"
AutomationProperties.Name="Maximize"
Command="{x:Static SystemCommands.MaximizeWindowCommand}"
Focusable="False"
IsEnabled="{Binding IsMaxRestoreButtonEnabled, RelativeSource={RelativeSource AncestorType={x:Type mah:MetroWindow}}}"
Expand All @@ -65,10 +65,10 @@
SnapsToDevicePixels="True" />
</Button>
<Button x:Name="PART_Close"
AutomationProperties.AutomationId="Close"
AutomationProperties.Name="Close"
controlzex:NonClientControlProperties.ClickStrategy="MouseEvent"
controlzex:NonClientControlProperties.HitTestResult="CLOSE"
AutomationProperties.AutomationId="Close"
AutomationProperties.Name="Close"
Command="{x:Static SystemCommands.CloseWindowCommand}"
Focusable="False"
IsEnabled="{Binding RelativeSource={RelativeSource AncestorType={x:Type mah:MetroWindow}}, Path=IsCloseButtonEnabled, Mode=OneWay}"
Expand Down Expand Up @@ -134,11 +134,11 @@
<StackPanel Orientation="Horizontal">
<Button x:Name="PART_Min"
Width="46"
controlzex:NonClientControlProperties.ClickStrategy="MouseEvent"
controlzex:NonClientControlProperties.HitTestResult="MINBUTTON"
AutomationProperties.AutomationId="Minimize"
AutomationProperties.Name="Minimize"
Command="{x:Static SystemCommands.MinimizeWindowCommand}"
controlzex:NonClientControlProperties.ClickStrategy="MouseEvent"
controlzex:NonClientControlProperties.HitTestResult="MINBUTTON"
Focusable="False"
IsEnabled="{Binding IsMinButtonEnabled, RelativeSource={RelativeSource AncestorType={x:Type mah:MetroWindow}}}"
ToolTip="{Binding Minimize, RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}"
Expand Down Expand Up @@ -168,10 +168,10 @@
</Button>
<Button x:Name="PART_Max"
Width="46"
AutomationProperties.AutomationId="MaximizeRestore"
AutomationProperties.Name="Maximize"
controlzex:NonClientControlProperties.ClickStrategy="MouseEvent"
controlzex:NonClientControlProperties.HitTestResult="MAXBUTTON"
AutomationProperties.AutomationId="MaximizeRestore"
AutomationProperties.Name="Maximize"
Command="{x:Static SystemCommands.MaximizeWindowCommand}"
Focusable="False"
IsEnabled="{Binding IsMaxRestoreButtonEnabled, RelativeSource={RelativeSource AncestorType={x:Type mah:MetroWindow}}}"
Expand Down Expand Up @@ -204,10 +204,10 @@
</Button>
<Button x:Name="PART_Close"
Width="46"
AutomationProperties.AutomationId="Close"
AutomationProperties.Name="Close"
controlzex:NonClientControlProperties.ClickStrategy="MouseEvent"
controlzex:NonClientControlProperties.HitTestResult="CLOSE"
AutomationProperties.AutomationId="Close"
AutomationProperties.Name="Close"
Command="{x:Static SystemCommands.CloseWindowCommand}"
Focusable="False"
IsEnabled="{Binding RelativeSource={RelativeSource AncestorType={x:Type mah:MetroWindow}}, Path=IsCloseButtonEnabled, Mode=OneWay}"
Expand Down
Loading

0 comments on commit 6bce9f8

Please sign in to comment.