Skip to content

Commit 26792f8

Browse files
committed
Fix issue (#129
Fix issue (#129
1 parent 054386b commit 26792f8

21 files changed

+590
-48
lines changed

src/WPFDevelopers.Net40/Themes/Generic.xaml

Lines changed: 141 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,22 +39,142 @@
3939
<RowDefinition Height="Auto" />
4040
<RowDefinition Height="*" />
4141
</Grid.RowDefinitions>
42-
<control:SmallPanel Grid.Row="0" Background="{TemplateBinding TitleBackground}">
43-
<Grid x:Name="PART_GridChrome" Height="{TemplateBinding TitleHeight}">
42+
<control:SmallPanel
43+
x:Name="PART_Normal"
44+
Grid.Row="0"
45+
Background="{TemplateBinding TitleBackground}">
46+
<Grid Height="{TemplateBinding TitleHeight}">
47+
<Grid.ColumnDefinitions>
48+
<ColumnDefinition Width="*" />
49+
<ColumnDefinition Width="Auto" />
50+
</Grid.ColumnDefinitions>
51+
<StackPanel Orientation="Horizontal">
52+
<Button
53+
x:Name="PART_TitleBarIcon"
54+
Margin="5,0,0,0"
55+
VerticalAlignment="Center"
56+
shell:WindowChrome.IsHitTestVisibleInChrome="True"
57+
Background="Transparent"
58+
BorderThickness="0"
59+
Visibility="{Binding Icon, RelativeSource={RelativeSource Mode=TemplatedParent}, Converter={StaticResource ObjectNullToVisibilityConverter}}">
60+
<Image
61+
Width="{x:Static SystemParameters.SmallIconWidth}"
62+
Height="{x:Static SystemParameters.SmallIconHeight}"
63+
IsHitTestVisible="False"
64+
RenderOptions.BitmapScalingMode="HighQuality"
65+
Source="{TemplateBinding Icon}" />
66+
</Button>
67+
68+
<ContentControl
69+
Margin="5,0,0,0"
70+
VerticalAlignment="Center"
71+
Content="{TemplateBinding Title}"
72+
FontSize="{DynamicResource {x:Static SystemFonts.CaptionFontSizeKey}}"
73+
Foreground="{DynamicResource WD.WindowForegroundColorBrush}"
74+
IsTabStop="False" />
75+
</StackPanel>
76+
<StackPanel
77+
Grid.Column="1"
78+
HorizontalAlignment="Right"
79+
VerticalAlignment="Top"
80+
shell:WindowChrome.IsHitTestVisibleInChrome="True"
81+
Orientation="Horizontal">
82+
<StackPanel x:Name="PART_TitleBarMinAndMax" Orientation="Horizontal">
83+
<Button
84+
Name="PART_TitleBarMinimizeButton"
85+
Padding="0"
86+
Command="{Binding Source={x:Static shell:SystemCommands.MinimizeWindowCommand}}"
87+
IsTabStop="False"
88+
Style="{DynamicResource WD.WindowButtonStyle}"
89+
ToolTip="{Binding [Minimize], Source={x:Static resx:LanguageManager.Instance}}">
90+
<Grid HorizontalAlignment="Center" VerticalAlignment="Center">
91+
<Rectangle
92+
Width="10"
93+
Height="1"
94+
Margin="0,7,0,0"
95+
VerticalAlignment="Bottom"
96+
Fill="{DynamicResource WD.WindowForegroundColorBrush}" />
97+
</Grid>
98+
</Button>
99+
<Button
100+
Name="PART_TitleBarMaximizeButton"
101+
Padding="0"
102+
Command="{Binding Source={x:Static shell:SystemCommands.MaximizeWindowCommand}}"
103+
IsTabStop="False"
104+
Style="{DynamicResource WD.WindowButtonStyle}"
105+
ToolTip="{Binding [Maximize], Source={x:Static resx:LanguageManager.Instance}}">
106+
<Grid HorizontalAlignment="Center" VerticalAlignment="Center">
107+
<Path
108+
Width="10"
109+
Height="10"
110+
HorizontalAlignment="Center"
111+
VerticalAlignment="Center"
112+
Data="{DynamicResource WD.WindowMaximizeGeometry}"
113+
Fill="{DynamicResource WD.WindowForegroundColorBrush}"
114+
Stretch="Uniform"
115+
UseLayoutRounding="False" />
116+
</Grid>
117+
</Button>
118+
<Button
119+
Name="PART_TitleBarRestoreButton"
120+
Padding="0"
121+
Command="{Binding Source={x:Static shell:SystemCommands.RestoreWindowCommand}}"
122+
IsTabStop="False"
123+
Style="{DynamicResource WD.WindowButtonStyle}"
124+
ToolTip="{Binding [Restore], Source={x:Static resx:LanguageManager.Instance}}"
125+
Visibility="Collapsed">
126+
<Grid HorizontalAlignment="Center" VerticalAlignment="Center">
127+
<Path
128+
Width="10"
129+
Height="10"
130+
HorizontalAlignment="Center"
131+
VerticalAlignment="Center"
132+
Data="{DynamicResource WD.WindowRestoreGeometry}"
133+
Fill="{DynamicResource WD.WindowForegroundColorBrush}"
134+
Stretch="Uniform"
135+
UseLayoutRounding="False" />
136+
</Grid>
137+
</Button>
138+
</StackPanel>
139+
140+
<Button
141+
Name="PART_TitleBarCloseButton"
142+
Command="{Binding Source={x:Static shell:SystemCommands.CloseWindowCommand}}"
143+
IsTabStop="False"
144+
Style="{DynamicResource WD.WindowButtonStyle}"
145+
ToolTip="{Binding [Close], Source={x:Static resx:LanguageManager.Instance}}">
146+
<Path
147+
Width="10"
148+
Height="10"
149+
HorizontalAlignment="Center"
150+
VerticalAlignment="Center"
151+
Data="{DynamicResource WD.WindowCloseGeometry}"
152+
Fill="{DynamicResource WD.WindowForegroundColorBrush}"
153+
Stretch="Uniform" />
154+
</Button>
155+
</StackPanel>
156+
</Grid>
157+
</control:SmallPanel>
158+
<control:SmallPanel
159+
x:Name="PART_HighTitleBar"
160+
Grid.Row="0"
161+
Background="{TemplateBinding TitleBackground}"
162+
Visibility="Collapsed">
163+
<Grid
164+
x:Name="PART_GridChrome"
165+
Height="{TemplateBinding TitleHeight}"
166+
Margin="10,0,0,0">
44167
<Grid.ColumnDefinitions>
45168
<ColumnDefinition Width="Auto" />
46169
<ColumnDefinition Width="*" />
47170
<ColumnDefinition Width="Auto" MinWidth="30" />
48171
</Grid.ColumnDefinitions>
49172
<Image
50-
Width="30"
51-
Height="30"
52-
Margin="14,0,0,0"
53-
HorizontalAlignment="Left"
173+
Width="23"
174+
Height="23"
54175
VerticalAlignment="Center"
55176
RenderOptions.BitmapScalingMode="HighQuality"
56177
Source="{TemplateBinding Icon}"
57-
Stretch="Fill"
58178
Visibility="{TemplateBinding Icon,
59179
Converter={StaticResource ObjectNullToVisibilityConverter}}" />
60180
<TextBlock
@@ -65,11 +185,12 @@
65185
FontSize="{DynamicResource WD.TitleFontSize}"
66186
Foreground="{DynamicResource WD.WindowForegroundColorBrush}"
67187
Text="{TemplateBinding Title}" />
68-
<WrapPanel
188+
<StackPanel
69189
Grid.Column="2"
70190
Margin="0,6"
71-
shell:WindowChrome.IsHitTestVisibleInChrome="True">
72-
<WrapPanel x:Name="PART_MinAndMax">
191+
shell:WindowChrome.IsHitTestVisibleInChrome="True"
192+
Orientation="Horizontal">
193+
<StackPanel x:Name="PART_MinAndMax" Orientation="Horizontal">
73194
<Button
74195
Name="PART_MinimizeButton"
75196
Padding="0"
@@ -126,7 +247,7 @@
126247
UseLayoutRounding="False" />
127248
</Grid>
128249
</Button>
129-
</WrapPanel>
250+
</StackPanel>
130251

131252
<Button
132253
Name="PART_CloseButton"
@@ -143,7 +264,7 @@
143264
Fill="{DynamicResource WD.WindowForegroundColorBrush}"
144265
Stretch="Uniform" />
145266
</Button>
146-
</WrapPanel>
267+
</StackPanel>
147268
</Grid>
148269
<ContentPresenter
149270
x:Name="PART_TitleToolBar"
@@ -165,18 +286,26 @@
165286
</Grid>
166287
</Border>
167288
<ControlTemplate.Triggers>
289+
<Trigger Property="TitleBarMode" Value="HighTitleBar">
290+
<Setter TargetName="PART_HighTitleBar" Property="Visibility" Value="Visible" />
291+
<Setter TargetName="PART_Normal" Property="Visibility" Value="Collapsed" />
292+
</Trigger>
168293
<Trigger Property="WindowState" Value="Maximized">
169294
<Setter TargetName="PART_RestoreButton" Property="Visibility" Value="Visible" />
170295
<Setter TargetName="PART_MaximizeButton" Property="Visibility" Value="Collapsed" />
296+
<Setter TargetName="PART_TitleBarRestoreButton" Property="Visibility" Value="Visible" />
297+
<Setter TargetName="PART_TitleBarMaximizeButton" Property="Visibility" Value="Collapsed" />
171298
<Setter TargetName="PART_Border" Property="Margin" Value="7" />
172299
</Trigger>
173300
<Trigger Property="WindowStyle" Value="ToolWindow">
174301
<Setter TargetName="PART_MinAndMax" Property="Visibility" Value="Collapsed" />
302+
<Setter TargetName="PART_TitleBarMinAndMax" Property="Visibility" Value="Collapsed" />
175303
</Trigger>
176304
<Trigger Property="NoChrome" Value="True">
177305
<Setter TargetName="PART_GridChrome" Property="Visibility" Value="Collapsed" />
178306
<Setter TargetName="PART_TitleToolBar" Property="Visibility" Value="Visible" />
179307
</Trigger>
308+
180309
<MultiTrigger>
181310
<MultiTrigger.Conditions>
182311
<Condition Property="ResizeMode" Value="CanResizeWithGrip" />

src/WPFDevelopers.Net40/Window.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,21 @@
22
using System;
33
using System.Runtime.InteropServices;
44
using System.Windows;
5+
using System.Windows.Controls;
56
using System.Windows.Input;
67
using System.Windows.Interop;
78
using System.Windows.Media;
9+
using WPFDevelopers.Controls;
810
using WPFDevelopers.Helpers;
911

1012
namespace WPFDevelopers.Net40
1113
{
14+
[TemplatePart(Name = TitleBarIcon, Type = typeof(Button))]
1215
public class Window : System.Windows.Window
1316
{
17+
private const string TitleBarIcon = "PART_TitleBarIcon";
1418
private WindowStyle _windowStyle;
19+
private Button _titleBarIcon;
1520

1621
public static readonly DependencyProperty TitleHeightProperty =
1722
DependencyProperty.Register("TitleHeight", typeof(double), typeof(Window), new PropertyMetadata(50d));
@@ -25,6 +30,9 @@ public class Window : System.Windows.Window
2530
public static readonly DependencyProperty TitleBackgroundProperty =
2631
DependencyProperty.Register("TitleBackground", typeof(Brush), typeof(Window), new PropertyMetadata(null));
2732

33+
public static readonly DependencyProperty TitleBarModeProperty =
34+
DependencyProperty.Register("TitleBarMode", typeof(TitleBarMode), typeof(Window), new PropertyMetadata(TitleBarMode.Normal));
35+
2836
static Window()
2937
{
3038
DefaultStyleKeyProperty.OverrideMetadata(typeof(Window), new FrameworkPropertyMetadata(typeof(Window)));
@@ -46,7 +54,20 @@ public override void OnApplyTemplate()
4654
{
4755
base.OnApplyTemplate();
4856
_windowStyle = WindowStyle;
57+
_titleBarIcon = GetTemplateChild(TitleBarIcon) as Button;
58+
if (_titleBarIcon != null)
59+
{
60+
_titleBarIcon.MouseDoubleClick -= Icon_MouseDoubleClick;
61+
_titleBarIcon.MouseDoubleClick += Icon_MouseDoubleClick;
62+
}
63+
}
64+
65+
private void Icon_MouseDoubleClick(object sender, MouseButtonEventArgs e)
66+
{
67+
if (e.ChangedButton == MouseButton.Left)
68+
Close();
4969
}
70+
5071
public double TitleHeight
5172
{
5273
get => (double)GetValue(TitleHeightProperty);
@@ -71,10 +92,18 @@ public Brush TitleBackground
7192
set => SetValue(TitleBackgroundProperty, value);
7293
}
7394

95+
public TitleBarMode TitleBarMode
96+
{
97+
get => (TitleBarMode)GetValue(TitleBarModeProperty);
98+
set => SetValue(TitleBarModeProperty, value);
99+
}
100+
74101
private void Window_Loaded(object sender, RoutedEventArgs e)
75102
{
76103
hWnd = new WindowInteropHelper(this).Handle;
77104
HwndSource.FromHwnd(hWnd).AddHook(WindowProc);
105+
if(TitleBarMode == TitleBarMode.Normal)
106+
TitleHeight = SystemParameters2.Current.WindowNonClientFrameThickness.Top;
78107
}
79108

80109
protected override void OnContentRendered(EventArgs e)

0 commit comments

Comments
 (0)