Skip to content

Commit d580f7f

Browse files
committed
ux: window border style
Signed-off-by: leo <longshuang@msn.cn>
1 parent 67e4043 commit d580f7f

File tree

4 files changed

+48
-16
lines changed

4 files changed

+48
-16
lines changed

src/Native/Windows.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public void SetupWindow(Window window)
6767
{
6868
window.ExtendClientAreaChromeHints = ExtendClientAreaChromeHints.NoChrome;
6969
window.ExtendClientAreaToDecorationsHint = true;
70-
window.Classes.Add("fix_maximized_padding");
70+
window.BorderThickness = new Thickness(1);
7171

7272
Win32Properties.AddWndProcHookCallback(window, (IntPtr hWnd, uint msg, IntPtr _, IntPtr lParam, ref bool handled) =>
7373
{

src/Resources/Styles.axaml

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,25 +24,38 @@
2424
</Style>
2525

2626
<Style Selector="Window">
27-
<Setter Property="Background" Value="{DynamicResource Brush.Window}"/>
28-
<Setter Property="BorderThickness" Value="1"/>
29-
<Setter Property="BorderBrush" Value="{DynamicResource Brush.Border0}"/>
30-
<Setter Property="SystemDecorations" Value="Full"/>
31-
<Setter Property="Padding" Value="0"/>
32-
3327
<Style.Resources>
3428
<SolidColorBrush x:Key="SystemControlErrorTextForegroundBrush" Color="Red"/>
3529
<Color x:Key="SystemErrorTextColor">Red</Color>
3630
</Style.Resources>
37-
</Style>
38-
39-
<Style Selector="Window[WindowState=Maximized]">
31+
32+
<Setter Property="Background" Value="{DynamicResource Brush.Window}"/>
4033
<Setter Property="BorderThickness" Value="0"/>
34+
<Setter Property="BorderBrush" Value="{DynamicResource Brush.WindowBorder}"/>
35+
<Setter Property="SystemDecorations" Value="Full"/>
4136
<Setter Property="Padding" Value="0"/>
42-
</Style>
4337

44-
<Style Selector="Window[WindowState=Maximized].fix_maximized_padding">
45-
<Setter Property="Padding" Value="8,6,8,8"/>
38+
<Setter Property="Template">
39+
<ControlTemplate>
40+
<Border BorderThickness="{TemplateBinding BorderThickness}"
41+
BorderBrush="{TemplateBinding BorderBrush}"
42+
Background="{TemplateBinding Background}"
43+
CornerRadius="{TemplateBinding CornerRadius}"
44+
ClipToBounds="True">
45+
<Border Margin="{TemplateBinding Padding}">
46+
<VisualLayerManager>
47+
<Border>
48+
<ContentPresenter Name="PART_ContentPresenter"
49+
ContentTemplate="{TemplateBinding ContentTemplate}"
50+
Content="{TemplateBinding Content}"
51+
HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
52+
VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"/>
53+
</Border>
54+
</VisualLayerManager>
55+
</Border>
56+
</Border>
57+
</ControlTemplate>
58+
</Setter>
4659
</Style>
4760

4861
<Style Selector="Window.custom_window_frame">

src/Resources/Themes.axaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<ResourceDictionary.ThemeDictionaries>
44
<ResourceDictionary x:Key="Light">
55
<Color x:Key="Color.Window">#FFF0F5F9</Color>
6-
<Color x:Key="Color.WindowBorder">#00000000</Color>
6+
<Color x:Key="Color.WindowBorder">#FF999999</Color>
77
<Color x:Key="Color.TitleBar">#FFCFDEEA</Color>
88
<Color x:Key="Color.ToolBar">#FFF0F5F9</Color>
99
<Color x:Key="Color.Popup">#FFF8F8F8</Color>
@@ -30,7 +30,7 @@
3030

3131
<ResourceDictionary x:Key="Dark">
3232
<Color x:Key="Color.Window">#FF252525</Color>
33-
<Color x:Key="Color.WindowBorder">#FF444444</Color>
33+
<Color x:Key="Color.WindowBorder">#FF606060</Color>
3434
<Color x:Key="Color.TitleBar">#FF1F1F1F</Color>
3535
<Color x:Key="Color.ToolBar">#FF2F2F2F</Color>
3636
<Color x:Key="Color.Popup">#FF2B2B2B</Color>

src/Views/ChromelessWindow.cs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
using System;
2-
2+
using Avalonia;
33
using Avalonia.Controls;
44
using Avalonia.Controls.Primitives;
55
using Avalonia.Input;
@@ -74,6 +74,25 @@ protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
7474
}
7575
}
7676

77+
protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change)
78+
{
79+
base.OnPropertyChanged(change);
80+
81+
if (change.Property == WindowStateProperty && OperatingSystem.IsWindows())
82+
{
83+
if (WindowState == WindowState.Maximized)
84+
{
85+
BorderThickness = new Thickness(0);
86+
Padding = new Thickness(8, 6, 8, 8);
87+
}
88+
else
89+
{
90+
BorderThickness = new Thickness(1);
91+
Padding = new Thickness(0);
92+
}
93+
}
94+
}
95+
7796
protected override void OnKeyDown(KeyEventArgs e)
7897
{
7998
base.OnKeyDown(e);

0 commit comments

Comments
 (0)