mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-12-24 20:57:19 -08:00
style<Window>: makes the window border color is the same on both Windows 10 and 11
This commit is contained in:
parent
80aa468b08
commit
d9afb798db
1 changed files with 49 additions and 3 deletions
|
@ -1,7 +1,8 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Documents;
|
using System.Runtime.InteropServices;
|
||||||
using System.Collections.Generic;
|
using System.Windows.Interop;
|
||||||
|
using System.Windows.Media;
|
||||||
|
|
||||||
namespace SourceGit.Views.Controls {
|
namespace SourceGit.Views.Controls {
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -9,6 +10,31 @@ namespace SourceGit.Views.Controls {
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class Window : System.Windows.Window {
|
public class Window : System.Windows.Window {
|
||||||
|
|
||||||
|
[StructLayout(LayoutKind.Sequential)]
|
||||||
|
private struct OSVERSIONINFOEX {
|
||||||
|
public int Size;
|
||||||
|
public int Major;
|
||||||
|
public int Minor;
|
||||||
|
public int Build;
|
||||||
|
public int Platform;
|
||||||
|
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)]
|
||||||
|
public string CSDVersion;
|
||||||
|
public ushort ServicePackMajor;
|
||||||
|
public ushort ServicePackMinor;
|
||||||
|
public short SuiteMask;
|
||||||
|
public byte ProductType;
|
||||||
|
public byte Reserved;
|
||||||
|
}
|
||||||
|
|
||||||
|
[DllImport("ntdll.dll", CharSet = CharSet.Unicode, SetLastError = true)]
|
||||||
|
private static extern int RtlGetVersion(ref OSVERSIONINFOEX version);
|
||||||
|
|
||||||
|
[DllImport("dwmapi.dll", CharSet = CharSet.Unicode, SetLastError = true)]
|
||||||
|
private static extern long DwmSetWindowAttribute(IntPtr hwnd,
|
||||||
|
uint attribute,
|
||||||
|
ref uint pvAttribute,
|
||||||
|
uint cbAttribute);
|
||||||
|
|
||||||
public static readonly DependencyProperty IsMaximizedProperty = DependencyProperty.Register(
|
public static readonly DependencyProperty IsMaximizedProperty = DependencyProperty.Register(
|
||||||
"IsMaximized",
|
"IsMaximized",
|
||||||
typeof(bool),
|
typeof(bool),
|
||||||
|
@ -22,7 +48,27 @@ namespace SourceGit.Views.Controls {
|
||||||
|
|
||||||
public Window() {
|
public Window() {
|
||||||
Style = FindResource("Style.Window") as Style;
|
Style = FindResource("Style.Window") as Style;
|
||||||
Loaded += (_, __) => OnStateChanged(null);
|
Loaded += OnWindowLoaded;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnWindowLoaded(object sender, RoutedEventArgs e) {
|
||||||
|
OnStateChanged(null);
|
||||||
|
|
||||||
|
// Windows 11 需要特殊处理一下边框,使得其与Window 10下表现一致
|
||||||
|
OSVERSIONINFOEX version = new OSVERSIONINFOEX() { Size = Marshal.SizeOf(typeof(OSVERSIONINFOEX)) };
|
||||||
|
if (RtlGetVersion(ref version) == 0 && version.Major >= 10 && version.Build >= 22000) {
|
||||||
|
Models.Theme.Changed += UpdateBorderColor;
|
||||||
|
Unloaded += (_, __) => Models.Theme.Changed -= UpdateBorderColor;
|
||||||
|
|
||||||
|
UpdateBorderColor();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void UpdateBorderColor() {
|
||||||
|
IntPtr hWnd = new WindowInteropHelper(GetWindow(this)).EnsureHandle();
|
||||||
|
Color color = (BorderBrush as SolidColorBrush).Color;
|
||||||
|
uint preference = ((uint)color.B << 16) | ((uint)color.G << 8) | (uint)color.R;
|
||||||
|
DwmSetWindowAttribute(hWnd, 34, ref preference, sizeof(uint));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnStateChanged(EventArgs e) {
|
protected override void OnStateChanged(EventArgs e) {
|
||||||
|
|
Loading…
Reference in a new issue