Skip to content

Commit 6bce9f8

Browse files
authored
Merge pull request #4354 from Keboo/fix4350
Adding the ability for the dialog title to contain arbitrary content
2 parents 135e84c + 06385f1 commit 6bce9f8

13 files changed

Lines changed: 133 additions & 51 deletions

File tree

src/MahApps.Metro.Samples/MahApps.Metro.Demo/MainWindow.xaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
<mah:MetroWindow x:Class="MetroDemo.MainWindow"
22
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
33
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:controlzEx="urn:controlzex"
45
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
56
xmlns:exampleViews="clr-namespace:MetroDemo.ExampleViews"
67
xmlns:iconPacks="http://metro.mahapps.com/winfx/xaml/iconpacks"
78
xmlns:local="clr-namespace:MetroDemo"
89
xmlns:mah="http://metro.mahapps.com/winfx/xaml/controls"
910
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
10-
xmlns:controlzEx="urn:controlzex"
1111
Title="MahApps.Metro - Demo Application"
1212
Width="1024"
1313
Height="768"
@@ -245,9 +245,9 @@
245245
IsCheckable="True"
246246
IsChecked="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type mah:MetroWindow}}, Path=PreferDWMBorderColor}" />
247247
<MenuItem Header="DWMSupportsBorderColor"
248-
IsEnabled="False"
249248
IsCheckable="True"
250-
IsChecked="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type mah:MetroWindow}}, Path=DWMSupportsBorderColor}" />
249+
IsChecked="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type mah:MetroWindow}}, Path=DWMSupportsBorderColor}"
250+
IsEnabled="False" />
251251
</MenuItem>
252252
<MenuItem Header="ShowTitleBar"
253253
IsCheckable="True"

src/MahApps.Metro/Automation/Peers/MetroDialogAutomationPeer.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ protected override AutomationControlType GetAutomationControlTypeCore()
2727
protected override string GetNameCore()
2828
{
2929
var nameCore = base.GetNameCore();
30-
if (string.IsNullOrEmpty(nameCore))
30+
if (string.IsNullOrEmpty(nameCore) && ((BaseMetroDialog)this.Owner).Title is string title)
3131
{
32-
nameCore = ((BaseMetroDialog)this.Owner).Title;
32+
nameCore = title;
3333
}
34-
34+
3535
if (string.IsNullOrEmpty(nameCore))
3636
{
3737
nameCore = ((BaseMetroDialog)this.Owner).Name;

src/MahApps.Metro/Controls/Dialogs/BaseMetroDialog.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,16 +83,16 @@ public GridLength DialogContentWidth
8383
/// <summary>Identifies the <see cref="Title"/> dependency property.</summary>
8484
public static readonly DependencyProperty TitleProperty
8585
= DependencyProperty.Register(nameof(Title),
86-
typeof(string),
86+
typeof(object),
8787
typeof(BaseMetroDialog),
88-
new PropertyMetadata(default(string)));
88+
new PropertyMetadata(default(object)));
8989

9090
/// <summary>
9191
/// Gets or sets the title of the dialog.
9292
/// </summary>
93-
public string? Title
93+
public object? Title
9494
{
95-
get => (string?)this.GetValue(TitleProperty);
95+
get => (object?)this.GetValue(TitleProperty);
9696
set => this.SetValue(TitleProperty, value);
9797
}
9898

src/MahApps.Metro/Controls/Dialogs/DialogManager.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public static class DialogManager
2424
/// <param name="message">The message contained within the LoginDialog.</param>
2525
/// <param name="settings">Optional settings that override the global metro dialog settings.</param>
2626
/// <returns>The text that was entered or null (Nothing in Visual Basic) if the user cancelled the operation.</returns>
27-
public static async Task<LoginDialogData?> ShowLoginAsync(this MetroWindow window, string title, string message, LoginDialogSettings? settings = null)
27+
public static async Task<LoginDialogData?> ShowLoginAsync(this MetroWindow window, object title, string message, LoginDialogSettings? settings = null)
2828
{
2929
window.Dispatcher.VerifyAccess();
3030

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

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

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

src/MahApps.Metro/Controls/Dialogs/ProgressDialogController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ public void SetMessage(string message)
147147
/// Sets the dialog's title.
148148
/// </summary>
149149
/// <param name="title">The title to be set.</param>
150-
public void SetTitle(string title)
150+
public void SetTitle(object title)
151151
{
152152
this.WrappedDialog.Invoke(() => this.WrappedDialog.Title = title);
153153
}

src/MahApps.Metro/Styles/Controls.Buttons.xaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
22
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
3+
xmlns:controlzex="urn:controlzex"
34
xmlns:mah="clr-namespace:MahApps.Metro.Controls"
4-
xmlns:mahConverters="clr-namespace:MahApps.Metro.Converters"
5-
xmlns:controlzex="urn:controlzex">
5+
xmlns:mahConverters="clr-namespace:MahApps.Metro.Converters">
66

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

src/MahApps.Metro/Themes/Dialogs/BaseMetroDialog.xaml

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,18 @@
7979
<RowDefinition Height="*" />
8080
</Grid.RowDefinitions>
8181

82-
<TextBlock x:Name="PART_Title"
83-
Grid.Row="0"
84-
AutomationProperties.Name="Dialog title"
85-
FontSize="{TemplateBinding DialogTitleFontSize}"
86-
Foreground="{TemplateBinding Foreground}"
87-
Text="{TemplateBinding Title}"
88-
TextWrapping="Wrap" />
82+
<ContentPresenter x:Name="PART_Title"
83+
Grid.Row="0"
84+
AutomationProperties.Name="Dialog title"
85+
Content="{TemplateBinding Title}"
86+
TextElement.FontSize="{TemplateBinding DialogTitleFontSize}"
87+
TextElement.Foreground="{TemplateBinding Foreground}">
88+
<ContentPresenter.Resources>
89+
<Style BasedOn="{StaticResource {x:Type TextBlock}}" TargetType="TextBlock">
90+
<Setter Property="TextWrapping" Value="Wrap" />
91+
</Style>
92+
</ContentPresenter.Resources>
93+
</ContentPresenter>
8994

9095
<ContentPresenter x:Name="PART_Content"
9196
Grid.Row="1"

src/MahApps.Metro/Themes/MetroWindow.xaml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
1+
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
22
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
33
xmlns:controlzEx="urn:controlzex"
44
xmlns:mah="clr-namespace:MahApps.Metro.Controls"
@@ -54,9 +54,9 @@
5454
HorizontalContentAlignment="Stretch"
5555
VerticalContentAlignment="Stretch"
5656
Panel.ZIndex="1"
57+
controlzEx:WindowChrome.IsHitTestVisibleInChrome="True"
5758
Content="{TemplateBinding Icon}"
5859
ContentTemplate="{TemplateBinding IconTemplate}"
59-
controlzEx:WindowChrome.IsHitTestVisibleInChrome="True"
6060
Focusable="False"
6161
Visibility="{TemplateBinding ShowIconOnTitleBar, Converter={StaticResource BooleanToVisibilityConverter}}" />
6262

@@ -204,10 +204,10 @@
204204
<ResizeGrip x:Name="WindowResizeGrip"
205205
HorizontalAlignment="Right"
206206
VerticalAlignment="Bottom"
207+
controlzEx:WindowChrome.ResizeGripDirection="BottomRight"
207208
IsTabStop="False"
208209
UseLayoutRounding="True"
209-
Visibility="Collapsed"
210-
controlzEx:WindowChrome.ResizeGripDirection="BottomRight" />
210+
Visibility="Collapsed" />
211211
</Grid>
212212

213213
<ControlTemplate.Triggers>
@@ -299,9 +299,9 @@
299299
HorizontalContentAlignment="Stretch"
300300
VerticalContentAlignment="Stretch"
301301
Panel.ZIndex="1"
302+
controlzEx:WindowChrome.IsHitTestVisibleInChrome="True"
302303
Content="{TemplateBinding Icon}"
303304
ContentTemplate="{TemplateBinding IconTemplate}"
304-
controlzEx:WindowChrome.IsHitTestVisibleInChrome="True"
305305
Focusable="False"
306306
Visibility="{TemplateBinding ShowIconOnTitleBar, Converter={StaticResource BooleanToVisibilityConverter}}" />
307307

@@ -456,10 +456,10 @@
456456
<ResizeGrip x:Name="WindowResizeGrip"
457457
HorizontalAlignment="Right"
458458
VerticalAlignment="Bottom"
459+
controlzEx:WindowChrome.ResizeGripDirection="BottomRight"
459460
IsTabStop="False"
460461
UseLayoutRounding="True"
461-
Visibility="Collapsed"
462-
controlzEx:WindowChrome.ResizeGripDirection="BottomRight" />
462+
Visibility="Collapsed" />
463463
</Grid>
464464

465465
<ControlTemplate.Resources>

src/MahApps.Metro/Themes/WindowButtonCommands.xaml

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
22
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
3+
xmlns:controlzex="urn:controlzex"
34
xmlns:mah="clr-namespace:MahApps.Metro.Controls"
4-
xmlns:mahConverters="clr-namespace:MahApps.Metro.Converters"
5-
xmlns:controlzex="urn:controlzex">
5+
xmlns:mahConverters="clr-namespace:MahApps.Metro.Converters">
66

77
<!-- WindowButtonCommands control templates -->
88

99
<ControlTemplate x:Key="MahApps.Templates.WindowButtonCommands" TargetType="{x:Type mah:WindowButtonCommands}">
1010
<StackPanel Orientation="Horizontal">
1111
<Button x:Name="PART_Min"
12-
AutomationProperties.AutomationId="Minimize"
13-
AutomationProperties.Name="Minimize"
1412
controlzex:NonClientControlProperties.ClickStrategy="MouseEvent"
1513
controlzex:NonClientControlProperties.HitTestResult="MINBUTTON"
14+
AutomationProperties.AutomationId="Minimize"
15+
AutomationProperties.Name="Minimize"
1616
Command="{x:Static SystemCommands.MinimizeWindowCommand}"
1717
Focusable="False"
1818
IsEnabled="{Binding IsMinButtonEnabled, RelativeSource={RelativeSource AncestorType={x:Type mah:MetroWindow}}}"
@@ -35,10 +35,10 @@
3535
SnapsToDevicePixels="True" />
3636
</Button>
3737
<Button x:Name="PART_Max"
38-
AutomationProperties.AutomationId="MaximizeRestore"
39-
AutomationProperties.Name="Maximize"
4038
controlzex:NonClientControlProperties.ClickStrategy="MouseEvent"
4139
controlzex:NonClientControlProperties.HitTestResult="MAXBUTTON"
40+
AutomationProperties.AutomationId="MaximizeRestore"
41+
AutomationProperties.Name="Maximize"
4242
Command="{x:Static SystemCommands.MaximizeWindowCommand}"
4343
Focusable="False"
4444
IsEnabled="{Binding IsMaxRestoreButtonEnabled, RelativeSource={RelativeSource AncestorType={x:Type mah:MetroWindow}}}"
@@ -65,10 +65,10 @@
6565
SnapsToDevicePixels="True" />
6666
</Button>
6767
<Button x:Name="PART_Close"
68-
AutomationProperties.AutomationId="Close"
69-
AutomationProperties.Name="Close"
7068
controlzex:NonClientControlProperties.ClickStrategy="MouseEvent"
7169
controlzex:NonClientControlProperties.HitTestResult="CLOSE"
70+
AutomationProperties.AutomationId="Close"
71+
AutomationProperties.Name="Close"
7272
Command="{x:Static SystemCommands.CloseWindowCommand}"
7373
Focusable="False"
7474
IsEnabled="{Binding RelativeSource={RelativeSource AncestorType={x:Type mah:MetroWindow}}, Path=IsCloseButtonEnabled, Mode=OneWay}"
@@ -134,11 +134,11 @@
134134
<StackPanel Orientation="Horizontal">
135135
<Button x:Name="PART_Min"
136136
Width="46"
137+
controlzex:NonClientControlProperties.ClickStrategy="MouseEvent"
138+
controlzex:NonClientControlProperties.HitTestResult="MINBUTTON"
137139
AutomationProperties.AutomationId="Minimize"
138140
AutomationProperties.Name="Minimize"
139141
Command="{x:Static SystemCommands.MinimizeWindowCommand}"
140-
controlzex:NonClientControlProperties.ClickStrategy="MouseEvent"
141-
controlzex:NonClientControlProperties.HitTestResult="MINBUTTON"
142142
Focusable="False"
143143
IsEnabled="{Binding IsMinButtonEnabled, RelativeSource={RelativeSource AncestorType={x:Type mah:MetroWindow}}}"
144144
ToolTip="{Binding Minimize, RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}"
@@ -168,10 +168,10 @@
168168
</Button>
169169
<Button x:Name="PART_Max"
170170
Width="46"
171-
AutomationProperties.AutomationId="MaximizeRestore"
172-
AutomationProperties.Name="Maximize"
173171
controlzex:NonClientControlProperties.ClickStrategy="MouseEvent"
174172
controlzex:NonClientControlProperties.HitTestResult="MAXBUTTON"
173+
AutomationProperties.AutomationId="MaximizeRestore"
174+
AutomationProperties.Name="Maximize"
175175
Command="{x:Static SystemCommands.MaximizeWindowCommand}"
176176
Focusable="False"
177177
IsEnabled="{Binding IsMaxRestoreButtonEnabled, RelativeSource={RelativeSource AncestorType={x:Type mah:MetroWindow}}}"
@@ -204,10 +204,10 @@
204204
</Button>
205205
<Button x:Name="PART_Close"
206206
Width="46"
207-
AutomationProperties.AutomationId="Close"
208-
AutomationProperties.Name="Close"
209207
controlzex:NonClientControlProperties.ClickStrategy="MouseEvent"
210208
controlzex:NonClientControlProperties.HitTestResult="CLOSE"
209+
AutomationProperties.AutomationId="Close"
210+
AutomationProperties.Name="Close"
211211
Command="{x:Static SystemCommands.CloseWindowCommand}"
212212
Focusable="False"
213213
IsEnabled="{Binding RelativeSource={RelativeSource AncestorType={x:Type mah:MetroWindow}}, Path=IsCloseButtonEnabled, Mode=OneWay}"

0 commit comments

Comments
 (0)