Skip to content

Commit d0ca2a4

Browse files
author
Carl Chang
committed
add borderlesswindow's border overlay;
fix window closing not handled correctly;
1 parent 7ec75f1 commit d0ca2a4

File tree

3 files changed

+38
-28
lines changed

3 files changed

+38
-28
lines changed

InputWindow.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
44
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
55
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" ResizeMode="NoResize" SizeToContent="Height"
6-
xmlns:local="clr-namespace:ZipImageViewer" Background="#CCDDDDDD" Foreground="#FF333333"
6+
xmlns:local="clr-namespace:ZipImageViewer" Background="#CCDDDDDD" Foreground="#FF333333" ShowInTaskbar="False"
77
mc:Ignorable="d" Width="400">
88
<StackPanel>
99
<StackPanel.Resources>

MainWindow.xaml.cs

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -87,27 +87,35 @@ private void MainWin_Unloaded(object sender, RoutedEventArgs e) {
8787
Application.Current.Shutdown();
8888
}
8989

90-
private void ThumbnailSizeChanged(object sender, PropertyChangedEventArgs e) {
91-
if (PropertyChanged == null) return;
92-
if (e.PropertyName == nameof(Setting.ThumbnailSize.Item1))
93-
PropertyChanged.Invoke(this, new PropertyChangedEventArgs(nameof(ThumbRealWidth)));
94-
if (e.PropertyName == nameof(Setting.ThumbnailSize.Item2))
95-
PropertyChanged.Invoke(this, new PropertyChangedEventArgs(nameof(ThumbRealHeight)));
96-
}
97-
90+
private bool reallyClose = false;
9891
private async void MainWin_Closing(object sender, CancelEventArgs e) {
92+
if (reallyClose) return;
93+
94+
//start cleaning up
95+
e.Cancel = true;
9996
Setting.ThumbnailSize.PropertyChanged -= ThumbnailSizeChanged;
10097

10198
tknSrc_LoadThumb?.Cancel();
102-
while (tknSrc_LoadThumb != null) {
103-
await Task.Delay(100);
104-
}
99+
while (tknSrc_LoadThumb != null) { await Task.Delay(100); }
100+
105101
Dispatcher.Invoke(() => ObjectList.Clear());
106102

107103
Setting.LastPath = CurrentPath;
108104
if (WindowState != WindowState.Maximized) {
109105
Setting.LastWindowSize = new Size(Width, Height);
110106
}
107+
108+
//now really close
109+
reallyClose = true;
110+
Dispatcher.BeginInvoke(new Action(() => Close()));
111+
}
112+
113+
private void ThumbnailSizeChanged(object sender, PropertyChangedEventArgs e) {
114+
if (PropertyChanged == null) return;
115+
if (e.PropertyName == nameof(Setting.ThumbnailSize.Item1))
116+
PropertyChanged.Invoke(this, new PropertyChangedEventArgs(nameof(ThumbRealWidth)));
117+
if (e.PropertyName == nameof(Setting.ThumbnailSize.Item2))
118+
PropertyChanged.Invoke(this, new PropertyChangedEventArgs(nameof(ThumbRealHeight)));
111119
}
112120

113121
private void MainWin_DpiChanged(object sender, DpiChangedEventArgs e) {

UserControls/BorderlessWindow.xaml

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
<Setter.Value>
99
<ControlTemplate TargetType="local:BorderlessWindow">
1010
<Grid Background="{TemplateBinding Background}">
11-
<Grid x:Name="titleBar" Opacity="0" Background="#22FFFFFF" VerticalAlignment="Top" Height="30" Panel.ZIndex="1">
12-
<Grid.Triggers>
11+
<Border x:Name="overlay" Opacity="0" BorderBrush="#33FFFFFF" BorderThickness="5 0 5 5" Panel.ZIndex="1">
12+
<Border.Triggers>
1313
<EventTrigger RoutedEvent="MouseEnter">
1414
<BeginStoryboard>
1515
<Storyboard Storyboard.TargetProperty="Opacity">
@@ -24,26 +24,28 @@
2424
</Storyboard>
2525
</BeginStoryboard>
2626
</EventTrigger>
27-
</Grid.Triggers>
28-
<Grid.Effect>
29-
<DropShadowEffect ShadowDepth="1" Direction="270" BlurRadius="3"/>
30-
</Grid.Effect>
27+
</Border.Triggers>
3128

32-
<!--window title-->
33-
<TextBlock x:Name="titleText" FontSize="12" VerticalAlignment="Center" HorizontalAlignment="Left" Margin="8 0 0 0"
29+
<DockPanel x:Name="titleBar" LastChildFill="False" Background="#33FFFFFF" VerticalAlignment="Top" Height="30">
30+
<DockPanel.Effect>
31+
<DropShadowEffect ShadowDepth="1" Direction="270" BlurRadius="3"/>
32+
</DockPanel.Effect>
33+
34+
<!--window title-->
35+
<TextBlock x:Name="titleText" FontSize="12" VerticalAlignment="Center" DockPanel.Dock="Left" Margin="8 0 0 0"
3436
Text="{TemplateBinding Title}" Foreground="{TemplateBinding Foreground}" Visibility="{TemplateBinding TitleVisibility}"/>
3537

36-
<!--the close button-->
37-
<StackPanel x:Name="systemButtons"
38-
Orientation="Horizontal" VerticalAlignment="Center" HorizontalAlignment="Right">
39-
<Button x:Name="minimizeButton" Style="{StaticResource WindowButtonStyle}" Content="0"
38+
<!--the close button-->
39+
<StackPanel x:Name="systemButtons" Orientation="Horizontal" VerticalAlignment="Center" DockPanel.Dock="Right">
40+
<Button x:Name="minimizeButton" Style="{StaticResource WindowButtonStyle}" Content="0"
4041
Visibility="{TemplateBinding ButtonMinVisibility}" Margin="0 0 8 0"/>
41-
<Button x:Name="restoreButton" Style="{StaticResource WindowButtonStyle}" Content="1"
42+
<Button x:Name="restoreButton" Style="{StaticResource WindowButtonStyle}" Content="1"
4243
Visibility="{TemplateBinding ButtonMaxVisibility}" Margin="0 0 8 0"/>
43-
<Button x:Name="closeButton" Style="{StaticResource WindowButtonStyle}" Content="r"
44+
<Button x:Name="closeButton" Style="{StaticResource WindowButtonStyle}" Content="r"
4445
Visibility="{TemplateBinding ButtonCloseVisibility}" Margin="0 0 8 0"/>
45-
</StackPanel>
46-
</Grid>
46+
</StackPanel>
47+
</DockPanel>
48+
</Border>
4749

4850
<!--the real content-->
4951
<ContentPresenter Panel.ZIndex="0" x:Name="windowContent" Margin="{TemplateBinding Padding}"

0 commit comments

Comments
 (0)