From bb838ae7f8f27b16544ff8047239c13a7159e88d Mon Sep 17 00:00:00 2001 From: NaBian <836904362@qq.com> Date: Thu, 22 Jul 2021 22:42:01 +0800 Subject: [PATCH] formatted window code --- .../Controls/Window/BlurWindow.cs | 4 +- .../Controls/Window/GlowWindow.cs | 4 +- .../Controls/Window/Window.cs | 484 ++++++++++-------- 3 files changed, 264 insertions(+), 228 deletions(-) diff --git a/src/Shared/HandyControl_Shared/Controls/Window/BlurWindow.cs b/src/Shared/HandyControl_Shared/Controls/Window/BlurWindow.cs index 74bfe398..005fad7a 100644 --- a/src/Shared/HandyControl_Shared/Controls/Window/BlurWindow.cs +++ b/src/Shared/HandyControl_Shared/Controls/Window/BlurWindow.cs @@ -11,13 +11,13 @@ namespace HandyControl.Controls { protected override void OnSourceInitialized(EventArgs e) { + base.OnSourceInitialized(e); + var versionInfo = SystemHelper.GetSystemVersionInfo(); if (versionInfo >= SystemVersionInfo.Windows10_1903) { this.GetHwndSource()?.AddHook(HwndSourceHook); } - - base.OnSourceInitialized(e); } private IntPtr HwndSourceHook(IntPtr hwnd, int msg, IntPtr wparam, IntPtr lparam, ref bool handled) diff --git a/src/Shared/HandyControl_Shared/Controls/Window/GlowWindow.cs b/src/Shared/HandyControl_Shared/Controls/Window/GlowWindow.cs index 17d81a5c..0247440f 100644 --- a/src/Shared/HandyControl_Shared/Controls/Window/GlowWindow.cs +++ b/src/Shared/HandyControl_Shared/Controls/Window/GlowWindow.cs @@ -161,14 +161,14 @@ namespace HandyControl.Controls protected override void OnSourceInitialized(EventArgs e) { + base.OnSourceInitialized(e); + var hwndSource = this.GetHwndSource(); if (hwndSource != null) { hwndSource.AddHook(HwndSourceHook); CreateGlowWindowHandles(); } - - base.OnSourceInitialized(e); } #endregion diff --git a/src/Shared/HandyControl_Shared/Controls/Window/Window.cs b/src/Shared/HandyControl_Shared/Controls/Window/Window.cs index e3dc1c17..448c08e2 100644 --- a/src/Shared/HandyControl_Shared/Controls/Window/Window.cs +++ b/src/Shared/HandyControl_Shared/Controls/Window/Window.cs @@ -19,66 +19,10 @@ namespace HandyControl.Controls [TemplatePart(Name = ElementNonClientArea, Type = typeof(UIElement))] public class Window : System.Windows.Window { + #region fields + private const string ElementNonClientArea = "PART_NonClientArea"; - - public static readonly DependencyProperty NonClientAreaContentProperty = DependencyProperty.Register( - "NonClientAreaContent", typeof(object), typeof(Window), new PropertyMetadata(default(object))); - - public static readonly DependencyProperty CloseButtonHoverBackgroundProperty = DependencyProperty.Register( - "CloseButtonHoverBackground", typeof(Brush), typeof(Window), - new PropertyMetadata(default(Brush))); - - public static readonly DependencyProperty CloseButtonHoverForegroundProperty = - DependencyProperty.Register( - "CloseButtonHoverForeground", typeof(Brush), typeof(Window), - new PropertyMetadata(default(Brush))); - - public static readonly DependencyProperty CloseButtonBackgroundProperty = DependencyProperty.Register( - "CloseButtonBackground", typeof(Brush), typeof(Window), new PropertyMetadata(Brushes.Transparent)); - - public static readonly DependencyProperty CloseButtonForegroundProperty = DependencyProperty.Register( - "CloseButtonForeground", typeof(Brush), typeof(Window), - new PropertyMetadata(Brushes.White)); - - public static readonly DependencyProperty OtherButtonBackgroundProperty = DependencyProperty.Register( - "OtherButtonBackground", typeof(Brush), typeof(Window), new PropertyMetadata(Brushes.Transparent)); - - public static readonly DependencyProperty OtherButtonForegroundProperty = DependencyProperty.Register( - "OtherButtonForeground", typeof(Brush), typeof(Window), - new PropertyMetadata(Brushes.White)); - - public static readonly DependencyProperty OtherButtonHoverBackgroundProperty = DependencyProperty.Register( - "OtherButtonHoverBackground", typeof(Brush), typeof(Window), - new PropertyMetadata(default(Brush))); - - public static readonly DependencyProperty OtherButtonHoverForegroundProperty = - DependencyProperty.Register( - "OtherButtonHoverForeground", typeof(Brush), typeof(Window), - new PropertyMetadata(default(Brush))); - - public static readonly DependencyProperty NonClientAreaBackgroundProperty = DependencyProperty.Register( - "NonClientAreaBackground", typeof(Brush), typeof(Window), - new PropertyMetadata(default(Brush))); - - public static readonly DependencyProperty NonClientAreaForegroundProperty = DependencyProperty.Register( - "NonClientAreaForeground", typeof(Brush), typeof(Window), - new PropertyMetadata(default(Brush))); - - public static readonly DependencyProperty NonClientAreaHeightProperty = DependencyProperty.Register( - "NonClientAreaHeight", typeof(double), typeof(Window), - new PropertyMetadata(22.0)); - - public static readonly DependencyProperty ShowNonClientAreaProperty = DependencyProperty.Register( - "ShowNonClientArea", typeof(bool), typeof(Window), - new PropertyMetadata(ValueBoxes.TrueBox, OnShowNonClientAreaChanged)); - - public static readonly DependencyProperty ShowTitleProperty = DependencyProperty.Register( - "ShowTitle", typeof(bool), typeof(Window), new PropertyMetadata(ValueBoxes.TrueBox)); - - public static readonly DependencyProperty IsFullScreenProperty = DependencyProperty.Register( - "IsFullScreen", typeof(bool), typeof(Window), - new PropertyMetadata(ValueBoxes.FalseBox, OnIsFullScreenChanged)); - + private bool _isFullScreen; private Thickness _actualBorderThickness; @@ -97,6 +41,10 @@ namespace HandyControl.Controls private UIElement _nonClientArea; + #endregion + + #region ctor + static Window() { StyleProperty.OverrideMetadata(typeof(Window), new FrameworkPropertyMetadata(ResourceHelper.GetResourceInternal