Skip to content

Commit b8c6715

Browse files
authored
Change default MahApps dialog button style (#570)
* Change button style * Button order changed Co-authored-by: BornToBeRoot <[email protected]>
1 parent 282baa8 commit b8c6715

22 files changed

+80
-114
lines changed

Source/NETworkManager.Settings/AppearanceManager.cs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
using ControlzEx.Theming;
22
using MahApps.Metro.Controls.Dialogs;
3+
using System;
34
using System.Collections.Generic;
45
using System.Linq;
6+
using System.Windows;
57
using System.Windows.Media;
68

79
namespace NETworkManager.Settings
@@ -10,12 +12,7 @@ namespace NETworkManager.Settings
1012
/// Class provides static variables and methods to change the theme and accent of the application.
1113
/// </summary>
1214
public static class AppearanceManager
13-
{
14-
/// <summary>
15-
/// Containes the default settings for a new <see cref="BaseMetroDialog"/>
16-
/// </summary>
17-
public static MetroDialogSettings MetroDialog = new MetroDialogSettings();
18-
15+
{
1916
/// <summary>
2017
/// List who contains all MahApps.Metro themes.
2118
/// </summary>
@@ -26,6 +23,11 @@ public static class AppearanceManager
2623
/// </summary>
2724
public static List<AccentColorInfo> Accents { get; set; }
2825

26+
/// <summary>
27+
/// Containes the default settings for a new <see cref="BaseMetroDialog"/>
28+
/// </summary>
29+
public static MetroDialogSettings MetroDialog = new MetroDialogSettings();
30+
2931
/// <summary>
3032
/// Load the MahApps.Metro themes and accents when needed.
3133
/// </summary>
@@ -42,6 +44,11 @@ static AppearanceManager()
4244
.OrderBy(x => x.Key)
4345
.Select(x => new AccentColorInfo { Name = x.Key, Color = x.First().ShowcaseBrush })
4446
.ToList();
47+
48+
MetroDialog.CustomResourceDictionary = new ResourceDictionary
49+
{
50+
Source = new Uri("NETworkManager;component/Resources/Styles/MetroDialogStyles.xaml", UriKind.RelativeOrAbsolute)
51+
};
4552
}
4653

4754
/// <summary>
Lines changed: 13 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,17 @@
11
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
2-
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
3-
xmlns:dialog="clr-namespace:MahApps.Metro.Controls.Dialogs;assembly=MahApps.Metro">
4-
<Style x:Key="ProfileMetroDialog" TargetType="{x:Type dialog:BaseMetroDialog}" BasedOn="{StaticResource {x:Type dialog:BaseMetroDialog}}">
5-
<Setter Property="Template">
6-
<Setter.Value>
7-
<ControlTemplate TargetType="{x:Type dialog:BaseMetroDialog}">
8-
<ControlTemplate.Resources>
9-
<Storyboard x:Key="DialogShownStoryboard">
10-
<DoubleAnimation AccelerationRatio=".9" BeginTime="0:0:0" Storyboard.TargetProperty="Opacity" To="1" Duration="0:0:0.2" />
11-
</Storyboard>
12-
</ControlTemplate.Resources>
13-
<Grid Background="{TemplateBinding Background}">
14-
<Grid.RowDefinitions>
15-
<RowDefinition Height="Auto" />
16-
<RowDefinition Height="*" MaxHeight="560" /> <!-- Adjust MaxHeight if Window.xaml MinHeight has changed -> 80% -->
17-
<RowDefinition Height="Auto" />
18-
</Grid.RowDefinitions>
19-
<ContentPresenter Grid.Row="0" AutomationProperties.Name="Dialog top" Content="{TemplateBinding DialogTop}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
20-
<Grid Grid.Row="1" >
21-
<Grid.ColumnDefinitions>
22-
<ColumnDefinition Width="10*" />
23-
<ColumnDefinition Width="80*" MaxWidth="840" />
24-
<!-- Adjust MaxHeight if Window.xaml MinWidth has changed -> 80% -->
25-
<ColumnDefinition Width="10*" />
26-
</Grid.ColumnDefinitions>
27-
<!-- Content area -->
28-
<Grid Grid.Column="1" Margin="{TemplateBinding Padding}">
29-
<Grid.RowDefinitions>
30-
<RowDefinition Height="Auto" />
31-
<RowDefinition Height="*" />
32-
</Grid.RowDefinitions>
33-
<TextBlock x:Name="PART_Title" Grid.Row="0" AutomationProperties.Name="Dialog title" FontSize="{TemplateBinding DialogTitleFontSize}" Foreground="{TemplateBinding Foreground}" Text="{TemplateBinding Title}" TextWrapping="Wrap" />
34-
<ContentPresenter Grid.Row="1" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" AutomationProperties.Name="Dialog content" Content="{TemplateBinding Content}" ContentStringFormat="{TemplateBinding ContentStringFormat}" ContentTemplate="{TemplateBinding ContentTemplate}" ContentTemplateSelector="{TemplateBinding ContentTemplateSelector}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
35-
</Grid>
36-
</Grid>
37-
<ContentPresenter Grid.Row="2" AutomationProperties.Name="Dialog bottom" Content="{TemplateBinding DialogBottom}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
38-
</Grid>
39-
<ControlTemplate.Triggers>
40-
<Trigger Property="Title" Value="{x:Null}">
41-
<Setter TargetName="PART_Title" Property="Visibility" Value="Collapsed" />
42-
</Trigger>
43-
<EventTrigger RoutedEvent="Loaded">
44-
<EventTrigger.Actions>
45-
<BeginStoryboard Storyboard="{StaticResource DialogShownStoryboard}" />
46-
</EventTrigger.Actions>
47-
</EventTrigger>
48-
</ControlTemplate.Triggers>
49-
</ControlTemplate>
50-
</Setter.Value>
51-
</Setter>
2+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
3+
<ResourceDictionary.MergedDictionaries>
4+
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.Buttons.xaml" />
5+
</ResourceDictionary.MergedDictionaries>
6+
7+
<!-- Override the buttons in MahApps.Metro Dialogs -->
8+
<Style x:Key="MahApps.Styles.Button.Dialogs" BasedOn="{StaticResource DefaultButton}" TargetType="{x:Type Button}">
9+
<Setter Property="VerticalAlignment" Value="Center" />
10+
<Setter Property="FontSize" Value="14" />
5211
</Style>
5312

54-
<Style TargetType="{x:Type dialog:CustomDialog}" BasedOn="{StaticResource ProfileMetroDialog}" />
55-
56-
<!-- Override the buttons in MahApps.Metro Dialogs -->
57-
<Style BasedOn="{StaticResource DefaultButton}" TargetType="{x:Type Button}" />
58-
<Style x:Key="AccentedDialogSquareButton" BasedOn="{StaticResource HighlightedButton}" TargetType="{x:Type Button}" />
59-
<Style x:Key="AccentedDialogHighlightedSquareButton" BasedOn="{StaticResource HighlightedButton}" TargetType="{x:Type Button}" />
13+
<Style x:Key="MahApps.Styles.Button.Dialogs.Accent" BasedOn="{StaticResource HighlightedButton}" TargetType="{x:Type Button}">
14+
<Setter Property="VerticalAlignment" Value="Center" />
15+
<Setter Property="FontSize" Value="14" />
16+
</Style>
6017
</ResourceDictionary>

Source/NETworkManager/Views/ARPTableAddEntryDialog.xaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,8 @@
5252
</TextBox.Text>
5353
</TextBox>
5454
</Grid>
55-
<StackPanel Grid.Row="2" Orientation="Horizontal" HorizontalAlignment="Right">
56-
<Button Content="{x:Static localization:Strings.Cancel}" Command="{Binding CancelCommand}" IsCancel="True" Style="{StaticResource DefaultButton}" />
57-
<Button Content="{x:Static localization:Strings.Add}" Command="{Binding AddCommand}" IsDefault="True" Margin="10,0,0,0">
55+
<StackPanel Grid.Row="2" Orientation="Horizontal" HorizontalAlignment="Right">
56+
<Button Content="{x:Static localization:Strings.Add}" Command="{Binding AddCommand}" IsDefault="True" Margin="0,0,10,0">
5857
<Button.Style>
5958
<Style TargetType="{x:Type Button}" BasedOn="{StaticResource HighlightedButton}">
6059
<Setter Property="IsEnabled" Value="False" />
@@ -72,6 +71,7 @@
7271
</Style>
7372
</Button.Style>
7473
</Button>
74+
<Button Content="{x:Static localization:Strings.Cancel}" Command="{Binding CancelCommand}" IsCancel="True" Style="{StaticResource DefaultButton}" />
7575
</StackPanel>
7676
</Grid>
7777
</UserControl>

Source/NETworkManager/Views/ConfirmDeleteDialog.xaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@
1616
<TextBlock Text="{Binding Message}" Style="{StaticResource WrapTextBlock}" />
1717
</StackPanel>
1818
<StackPanel Grid.Row="2" Orientation="Horizontal" HorizontalAlignment="Right">
19+
<Button Content="{x:Static localization:Strings.Delete}" Command="{Binding DeleteCommand}" IsDefault="True" Style="{StaticResource HighlightedButton}" Margin="0,0,10,0" />
1920
<Button Content="{x:Static localization:Strings.Cancel}" Command="{Binding CancelCommand}" IsCancel="True" Style="{StaticResource DefaultButton}" />
20-
<Button Content="{x:Static localization:Strings.Delete}" Command="{Binding DeleteCommand}" IsDefault="True" Style="{StaticResource HighlightedButton}" Margin="10,0,0,0" />
21+
2122
</StackPanel>
2223
</Grid>
2324
</UserControl>

Source/NETworkManager/Views/CredentialsChangePasswordDialog.xaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,8 @@
6969
</Style>
7070
</TextBlock.Style>
7171
</TextBlock>
72-
<StackPanel Grid.Row="3" Orientation="Horizontal" HorizontalAlignment="Right">
73-
<Button Content="{x:Static localization:Strings.Cancel}" Command="{Binding CancelCommand}" IsCancel="True" Style="{StaticResource DefaultButton}" />
74-
<Button Content="{x:Static localization:Strings.OK}" Command="{Binding OKCommand}" IsDefault="True" Margin="10,0,0,0">
72+
<StackPanel Grid.Row="3" Orientation="Horizontal" HorizontalAlignment="Right">
73+
<Button Content="{x:Static localization:Strings.OK}" Command="{Binding OKCommand}" IsDefault="True" Margin="0,0,10,0">
7574
<Button.Style>
7675
<Style TargetType="{x:Type Button}" BasedOn="{StaticResource HighlightedButton}">
7776
<Setter Property="IsEnabled" Value="False" />
@@ -89,6 +88,7 @@
8988
</Style>
9089
</Button.Style>
9190
</Button>
91+
<Button Content="{x:Static localization:Strings.Cancel}" Command="{Binding CancelCommand}" IsCancel="True" Style="{StaticResource DefaultButton}" />
9292
</StackPanel>
9393
</Grid>
9494
</UserControl>

Source/NETworkManager/Views/CredentialsPasswordDialog.xaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,8 @@
3434
</interactivity:Interaction.Behaviors>
3535
</PasswordBox>
3636
</Grid>
37-
<StackPanel Grid.Row="2" Orientation="Horizontal" HorizontalAlignment="Right">
38-
<Button Content="{x:Static localization:Strings.Cancel}" Command="{Binding CancelCommand}" IsCancel="True" Style="{StaticResource DefaultButton}" />
39-
<Button Content="{x:Static localization:Strings.OK}" Command="{Binding OKCommand}" IsDefault="True" Margin="10,0,0,0">
37+
<StackPanel Grid.Row="2" Orientation="Horizontal" HorizontalAlignment="Right">
38+
<Button Content="{x:Static localization:Strings.OK}" Command="{Binding OKCommand}" IsDefault="True" Margin="0,0,10,0">
4039
<Button.Style>
4140
<Style TargetType="{x:Type Button}" BasedOn="{StaticResource HighlightedButton}">
4241
<Setter Property="IsEnabled" Value="False" />
@@ -48,6 +47,7 @@
4847
</Style>
4948
</Button.Style>
5049
</Button>
50+
<Button Content="{x:Static localization:Strings.Cancel}" Command="{Binding CancelCommand}" IsCancel="True" Style="{StaticResource DefaultButton}" />
5151
</StackPanel>
5252
</Grid>
5353
</UserControl>

Source/NETworkManager/Views/CredentialsSetPasswordDialog.xaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,8 @@
6161
</Style>
6262
</TextBlock.Style>
6363
</TextBlock>
64-
<StackPanel Grid.Row="3" Orientation="Horizontal" HorizontalAlignment="Right">
65-
<Button Content="{x:Static localization:Strings.Cancel}" Command="{Binding CancelCommand}" IsCancel="True" Style="{StaticResource DefaultButton}" />
66-
<Button Content="{x:Static localization:Strings.OK}" Command="{Binding OKCommand}" IsDefault="True" Margin="10,0,0,0">
64+
<StackPanel Grid.Row="3" Orientation="Horizontal" HorizontalAlignment="Right">
65+
<Button Content="{x:Static localization:Strings.OK}" Command="{Binding OKCommand}" IsDefault="True" Margin="0,0,10,0">
6766
<Button.Style>
6867
<Style TargetType="{x:Type Button}" BasedOn="{StaticResource HighlightedButton}">
6968
<Setter Property="IsEnabled" Value="False" />
@@ -81,6 +80,7 @@
8180
</Style>
8281
</Button.Style>
8382
</Button>
83+
<Button Content="{x:Static localization:Strings.Cancel}" Command="{Binding CancelCommand}" IsCancel="True" Style="{StaticResource DefaultButton}" />
8484
</StackPanel>
8585
</Grid>
8686
</UserControl>

Source/NETworkManager/Views/CustomCommandDialog.xaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,8 @@
8787
</Rectangle.Resources>
8888
</Rectangle>
8989
</Grid>
90-
<StackPanel Grid.Row="2" Orientation="Horizontal" HorizontalAlignment="Right">
91-
<Button Content="{x:Static localization:Strings.Cancel}" Command="{Binding CancelCommand}" IsCancel="True" Style="{StaticResource DefaultButton}" />
92-
<Button Content="{x:Static localization:Strings.Save}" Command="{Binding SaveCommand}" IsDefault="True" Margin="10,0,0,0">
90+
<StackPanel Grid.Row="2" Orientation="Horizontal" HorizontalAlignment="Right">
91+
<Button Content="{x:Static localization:Strings.Save}" Command="{Binding SaveCommand}" IsDefault="True" Margin="0,0,10,0">
9392
<Button.Style>
9493
<Style TargetType="{x:Type Button}" BasedOn="{StaticResource HighlightedButton}">
9594
<Setter Property="IsEnabled" Value="False" />
@@ -109,6 +108,7 @@
109108
</Style>
110109
</Button.Style>
111110
</Button>
111+
<Button Content="{x:Static localization:Strings.Cancel}" Command="{Binding CancelCommand}" IsCancel="True" Style="{StaticResource DefaultButton}" />
112112
</StackPanel>
113113
</Grid>
114114
</UserControl>

Source/NETworkManager/Views/DNSServerDialog.xaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,8 @@
8686
</TextBox.Text>
8787
</TextBox>
8888
</Grid>
89-
<StackPanel Grid.Row="2" Orientation="Horizontal" HorizontalAlignment="Right">
90-
<Button Content="{x:Static localization:Strings.Cancel}" Command="{Binding CancelCommand}" IsCancel="True" Style="{StaticResource DefaultButton}" />
91-
<Button Content="{x:Static localization:Strings.Save}" Command="{Binding SaveCommand}" IsDefault="True" Margin="10,0,0,0">
89+
<StackPanel Grid.Row="2" Orientation="Horizontal" HorizontalAlignment="Right">
90+
<Button Content="{x:Static localization:Strings.Save}" Command="{Binding SaveCommand}" IsDefault="True" Margin="0,0,10,0">
9291
<Button.Style>
9392
<Style TargetType="{x:Type Button}" BasedOn="{StaticResource HighlightedButton}">
9493
<Setter Property="IsEnabled" Value="False" />
@@ -108,6 +107,7 @@
108107
</Style>
109108
</Button.Style>
110109
</Button>
110+
<Button Content="{x:Static localization:Strings.Cancel}" Command="{Binding CancelCommand}" IsCancel="True" Style="{StaticResource DefaultButton}" />
111111
</StackPanel>
112112
</Grid>
113113
</UserControl>

Source/NETworkManager/Views/ExportDialog.xaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,8 @@
6666
</TextBox.Text>
6767
</TextBox>
6868
</Grid>
69-
<StackPanel Grid.Row="2" Orientation="Horizontal" HorizontalAlignment="Right">
70-
<Button Content="{x:Static localization:Strings.Cancel}" Command="{Binding CancelCommand}" IsCancel="True" Style="{StaticResource DefaultButton}" />
71-
<Button Content="{x:Static localization:Strings.Export}" Command="{Binding ExportCommand}" IsDefault="True" Margin="10,0,0,0">
69+
<StackPanel Grid.Row="2" Orientation="Horizontal" HorizontalAlignment="Right">
70+
<Button Content="{x:Static localization:Strings.Export}" Command="{Binding ExportCommand}" IsDefault="True" Margin="0,0,10,0">
7271
<Button.Style>
7372
<Style TargetType="{x:Type Button}" BasedOn="{StaticResource HighlightedButton}">
7473
<Style.Triggers>
@@ -79,6 +78,7 @@
7978
</Style>
8079
</Button.Style>
8180
</Button>
81+
<Button Content="{x:Static localization:Strings.Cancel}" Command="{Binding CancelCommand}" IsCancel="True" Style="{StaticResource DefaultButton}" />
8282
</StackPanel>
8383
</Grid>
8484
</UserControl>

Source/NETworkManager/Views/GroupDialog.xaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,8 @@
3838
</ComboBox.Text>
3939
</ComboBox>
4040
</Grid>
41-
<StackPanel Grid.Row="2" Orientation="Horizontal" HorizontalAlignment="Right">
42-
<Button Content="{x:Static localization:Strings.Cancel}" Command="{Binding CancelCommand}" IsCancel="True" Style="{StaticResource DefaultButton}" />
43-
<Button Content="{x:Static localization:Strings.OK}" Command="{Binding OKCommand}" IsDefault="True" Margin="10,0,0,0">
41+
<StackPanel Grid.Row="2" Orientation="Horizontal" HorizontalAlignment="Right">
42+
<Button Content="{x:Static localization:Strings.OK}" Command="{Binding OKCommand}" IsDefault="True" Margin="0,0,10,0">
4443
<Button.Style>
4544
<Style TargetType="{x:Type Button}" BasedOn="{StaticResource HighlightedButton}">
4645
<Setter Property="IsEnabled" Value="False" />
@@ -52,6 +51,7 @@
5251
</Style>
5352
</Button.Style>
5453
</Button>
54+
<Button Content="{x:Static localization:Strings.Cancel}" Command="{Binding CancelCommand}" IsCancel="True" Style="{StaticResource DefaultButton}" />
5555
</StackPanel>
5656
</Grid>
5757
</UserControl>

Source/NETworkManager/Views/NetworkInterfaceAddIPAddressDialog.xaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,8 @@
5252
</TextBox.Text>
5353
</TextBox>
5454
</Grid>
55-
<StackPanel Grid.Row="2" Orientation="Horizontal" HorizontalAlignment="Right">
56-
<Button Content="{x:Static localization:Strings.Cancel}" Command="{Binding CancelCommand}" IsCancel="True" Style="{StaticResource DefaultButton}" />
57-
<Button Content="{x:Static localization:Strings.Add}" Command="{Binding AddCommand}" IsDefault="True" Margin="10,0,0,0">
55+
<StackPanel Grid.Row="2" Orientation="Horizontal" HorizontalAlignment="Right">
56+
<Button Content="{x:Static localization:Strings.Add}" Command="{Binding AddCommand}" IsDefault="True" Margin="0,0,10,0">
5857
<Button.Style>
5958
<Style TargetType="{x:Type Button}" BasedOn="{StaticResource HighlightedButton}">
6059
<Setter Property="IsEnabled" Value="False" />
@@ -72,6 +71,7 @@
7271
</Style>
7372
</Button.Style>
7473
</Button>
74+
<Button Content="{x:Static localization:Strings.Cancel}" Command="{Binding CancelCommand}" IsCancel="True" Style="{StaticResource DefaultButton}" />
7575
</StackPanel>
7676
</Grid>
7777
</UserControl>

0 commit comments

Comments
 (0)