This commit is contained in:
ShrlAlgo
2025-07-11 09:20:23 +08:00
parent c7b104f44f
commit 4d35cadb56
840 changed files with 102347 additions and 11595 deletions

View File

@@ -239,16 +239,13 @@ public class TitleBar : System.Windows.Controls.Control
remove => RemoveHandler(MinimizeClickedEvent, value);
}
private void CloseWindow()
{
currentWindow.Close();
}
private void CloseWindow() { currentWindow.Close(); }
private T GetTemplateChild<T>(string name) where T : DependencyObject
{
var element = GetTemplateChild(name);
if (element is not T tElement)
if(element is not T tElement)
{
throw new InvalidOperationException($"Template part '{name}' is not found or is not of type {typeof(T)}");
}
@@ -260,7 +257,7 @@ public class TitleBar : System.Windows.Controls.Control
{
var message = (User32.WM)msg;
if (message
if(message
is not (
User32.WM.NCHITTEST
or User32.WM.NCMOUSELEAVE
@@ -271,22 +268,22 @@ public class TitleBar : System.Windows.Controls.Control
return IntPtr.Zero;
}
foreach (TitleBarButton button in buttons)
foreach(TitleBarButton button in buttons)
{
if (!button.ReactToHwndHook(message, lParam, out IntPtr returnIntPtr))
if(!button.ReactToHwndHook(message, lParam, out IntPtr returnIntPtr))
{
continue;
}
// 修复了有时未正确清除按钮悬停背景,导致多个按钮看起来好像悬停的问题。
foreach (TitleBarButton anotherButton in buttons)
foreach(TitleBarButton anotherButton in buttons)
{
if (anotherButton == button)
if(anotherButton == button)
{
continue;
}
if (anotherButton.IsHovered && button.IsHovered)
if(anotherButton.IsHovered && button.IsHovered)
{
anotherButton.RemoveHover();
}
@@ -313,7 +310,7 @@ public class TitleBar : System.Windows.Controls.Control
// }
//}
switch (message)
switch(message)
{
case User32.WM.NCHITTEST when CloseWindowByDoubleClickOnIcon && icon.IsMouseOverElement(lParam):
// Ideally, clicking on the icon should open the system menu, but when the system menu is opened manually, double-clicking on the icon does not close the window
@@ -329,19 +326,19 @@ public class TitleBar : System.Windows.Controls.Control
private void MaximizeWindow()
{
if (!CanMaximize)
if(!CanMaximize)
{
return;
}
if (MaximizeActionOverride is not null)
if(MaximizeActionOverride is not null)
{
MaximizeActionOverride(this, currentWindow);
return;
}
if (currentWindow.WindowState == WindowState.Normal)
if(currentWindow.WindowState == WindowState.Normal)
{
SetCurrentValue(IsMaximizedProperty, true);
currentWindow.SetCurrentValue(Window.WindowStateProperty, WindowState.Maximized);
@@ -355,7 +352,7 @@ public class TitleBar : System.Windows.Controls.Control
private void MinimizeWindow()
{
if (MinimizeActionOverride is not null)
if(MinimizeActionOverride is not null)
{
MinimizeActionOverride(this, currentWindow);
@@ -367,18 +364,19 @@ public class TitleBar : System.Windows.Controls.Control
private void OnParentWindowStateChanged(object sender, EventArgs e)
{
if (IsMaximized != (currentWindow.WindowState == WindowState.Maximized))
if(IsMaximized != (currentWindow.WindowState == WindowState.Maximized))
{
SetCurrentValue(IsMaximizedProperty, currentWindow.WindowState == WindowState.Maximized);
}
}
/// <summary>
/// 设置窗口状态
/// </summary>
/// <param name="buttonType"></param>
private void OnTemplateButtonClick(TitleBarButtonType buttonType)
{
switch (buttonType)
switch(buttonType)
{
case TitleBarButtonType.Maximize
or TitleBarButtonType.Restore:
@@ -413,7 +411,7 @@ public class TitleBar : System.Windows.Controls.Control
/// </summary>
private void OnWindowContentRendered(object sender, EventArgs e)
{
if (sender is not Window window)
if(sender is not Window window)
{
return;
}
@@ -433,7 +431,7 @@ public class TitleBar : System.Windows.Controls.Control
{
var point = PointToScreen(e.GetPosition(this));
if (dpiScale is null)
if(dpiScale is null)
{
throw new InvalidOperationException("dpiScale is not initialized.");
}
@@ -445,8 +443,10 @@ public class TitleBar : System.Windows.Controls.Control
protected virtual void OnLoaded(object sender, RoutedEventArgs e)
{
currentWindow =
System.Windows.Window.GetWindow(this) ?? throw new InvalidOperationException("Window is null");
// 添加设计时检查
if (DesignerProperties.GetIsInDesignMode(this))
return;
currentWindow = System.Windows.Window.GetWindow(this) ?? throw new InvalidOperationException("Window is null");
currentWindow.StateChanged += OnParentWindowStateChanged;
currentWindow.ContentRendered += OnWindowContentRendered;
}
@@ -466,7 +466,7 @@ public class TitleBar : System.Windows.Controls.Control
_parentWindow = VisualTreeHelper.GetParent(this);
while (_parentWindow is not null and not Window)
while(_parentWindow is not null and not Window)
{
_parentWindow = VisualTreeHelper.GetParent(_parentWindow);
}

View File

@@ -28,41 +28,29 @@
VerticalAlignment="Center"
Focusable="False"
RenderOptions.BitmapScalingMode="HighQuality">
<Canvas
x:Name="Canvas"
Width="72"
Height="72"
Focusable="False">
<Path x:Name="CanvasPath" Fill="{TemplateBinding RenderButtonsForeground}" />
</Canvas>
<Path x:Name="IconPath" Fill="{TemplateBinding RenderButtonsForeground}" />
</Viewbox>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="ButtonType" Value="{x:Static controls:TitleBarButtonType.Help}">
<Setter Property="CommandParameter" Value="{x:Static controls:TitleBarButtonType.Help}" />
<Setter TargetName="CanvasPath" Property="Data" Value="M20.56,11.57c0-1.19-.24-2.31-.71-3.36-.47-1.05-1.11-1.96-1.92-2.74-.8-.78-1.74-1.4-2.81-1.85-1.07-.45-2.2-.68-3.37-.68s-2.37,.23-3.44,.69c-1.07,.46-2,1.09-2.8,1.88s-1.42,1.73-1.88,2.8c-.46,1.07-.69,2.22-.69,3.44,0,.4-.15,.74-.44,1.03s-.64,.44-1.03,.44c-.49,0-.86-.17-1.1-.52-.25-.34-.37-.74-.37-1.18,0-1.59,.32-3.09,.95-4.49,.63-1.4,1.49-2.62,2.57-3.66,1.08-1.04,2.33-1.86,3.74-2.47,1.42-.6,2.91-.91,4.49-.91s3.07,.3,4.49,.91c1.42,.6,2.66,1.43,3.74,2.47,1.08,1.04,1.93,2.26,2.57,3.66,.63,1.4,.95,2.9,.95,4.49,0,1.24-.13,2.32-.39,3.25-.26,.93-.63,1.77-1.12,2.54-.49,.77-1.08,1.49-1.78,2.18-.7,.69-1.48,1.42-2.35,2.2-.44,.4-.88,.78-1.31,1.16-.43,.38-.84,.78-1.24,1.21-.5,.55-.89,1.08-1.17,1.59-.28,.51-.48,1.03-.62,1.56-.14,.53-.22,1.09-.25,1.69-.03,.6-.05,1.25-.05,1.95,0,.4-.15,.74-.44,1.03-.29,.29-.64,.44-1.03,.44-.34,0-.6-.06-.79-.18-.19-.12-.34-.29-.44-.49-.1-.21-.17-.44-.2-.7-.03-.26-.05-.52-.05-.78v-.78c0-1.21,.15-2.28,.44-3.2,.29-.93,.68-1.76,1.16-2.5,.48-.74,1.03-1.41,1.65-2.02,.62-.6,1.25-1.19,1.89-1.74,.64-.56,1.27-1.11,1.88-1.66,.61-.55,1.16-1.15,1.64-1.8,.48-.65,.87-1.37,1.17-2.16,.3-.79,.45-1.69,.45-2.72Zm-11.02,27.36c0-.61,.21-1.13,.64-1.56,.43-.43,.95-.64,1.56-.64s1.13,.21,1.56,.64c.43,.43,.64,.95,.64,1.56s-.21,1.13-.64,1.56c-.43,.43-.95,.64-1.56,.64s-1.13-.21-1.56-.64c-.43-.43-.64-.95-.64-1.56Z" />
<Setter TargetName="ViewBox" Property="Height" Value="13" />
<Setter TargetName="Canvas" Property="Height" Value="41" />
<Setter TargetName="ViewBox" Property="Width" Value="13" />
<Setter TargetName="Canvas" Property="Width" Value="24" />
<Setter TargetName="IconPath" Property="Data" Value="F1 M1024,1024z M0,0z M512,42.667C251.733,42.667 42.667,251.733 42.667,512 42.667,772.267 251.733,981.333 512,981.333 772.267,981.333 981.333,772.267 981.333,512 981.333,251.733 772.267,42.667 512,42.667z M512,938.667L512,85.333C746.667,85.333 938.667,277.333 938.667,512 938.667,746.667 746.667,938.667 512,938.667z" />
</Trigger>
<Trigger Property="ButtonType" Value="{x:Static controls:TitleBarButtonType.Minimize}">
<Setter Property="CommandParameter" Value="{x:Static controls:TitleBarButtonType.Minimize}" />
<Setter TargetName="CanvasPath" Property="Data" Value="M3.59,7.21A3.56,3.56,0,0,1,2.2,6.93a3.66,3.66,0,0,1-1.15-.78A3.88,3.88,0,0,1,.28,5,3.42,3.42,0,0,1,0,3.62,3.45,3.45,0,0,1,.28,2.23a4.12,4.12,0,0,1,.77-1.16A3.52,3.52,0,0,1,2.2.28,3.39,3.39,0,0,1,3.59,0H68.41A3.39,3.39,0,0,1,69.8.28,3.52,3.52,0,0,1,71,1.07a4.12,4.12,0,0,1,.77,1.16A3.45,3.45,0,0,1,72,3.62,3.42,3.42,0,0,1,71.72,5,3.88,3.88,0,0,1,71,6.15a3.66,3.66,0,0,1-1.15.78,3.56,3.56,0,0,1-1.39.28Z" />
<Setter TargetName="Canvas" Property="Height" Value="8" />
<Setter TargetName="Canvas" Property="Width" Value="72" />
<Setter TargetName="IconPath" Property="Data" Value="F1 M1024,1024z M0,0z M45.60213333,478.13973333L978.39786667,478.13973333C1001.33546667,478.13973333 1012.25813334,489.60853333 1012.80426667,512.54613333 1012.80426667,535.48373333 1001.33546667,546.95253333 978.39786667,546.95253333L45.60213333,546.95253333C22.66453333,546.95253333 11.19573333,535.48373333 11.19573333,512.54613333 11.19573333,489.0624 22.66453333,478.13973333 45.60213333,478.13973333z" />
</Trigger>
<Trigger Property="ButtonType" Value="{x:Static controls:TitleBarButtonType.Restore}">
<Setter Property="CommandParameter" Value="{x:Static controls:TitleBarButtonType.Restore}" />
<Setter TargetName="CanvasPath" Property="Data" Value="M10.62,72a9.92,9.92,0,0,1-4-.86A11.15,11.15,0,0,1,.86,65.43,9.92,9.92,0,0,1,0,61.38V25A9.86,9.86,0,0,1,.86,21,11.32,11.32,0,0,1,3.18,17.6a11,11,0,0,1,3.38-2.32,9.68,9.68,0,0,1,4.06-.87H47a9.84,9.84,0,0,1,4.08.87A11,11,0,0,1,56.72,21,9.84,9.84,0,0,1,57.59,25V61.38a9.68,9.68,0,0,1-.87,4.06,11,11,0,0,1-2.32,3.38A11.32,11.32,0,0,1,51,71.14,9.86,9.86,0,0,1,47,72Zm36.17-7.21a3.39,3.39,0,0,0,1.39-.28,3.79,3.79,0,0,0,1.16-.77,3.47,3.47,0,0,0,1.07-2.53v-36a3.55,3.55,0,0,0-.28-1.41,3.51,3.51,0,0,0-.77-1.16,3.67,3.67,0,0,0-1.16-.77,3.55,3.55,0,0,0-1.41-.28h-36a3.45,3.45,0,0,0-1.39.28,3.59,3.59,0,0,0-1.14.79,3.79,3.79,0,0,0-.77,1.16,3.39,3.39,0,0,0-.28,1.39v36a3.45,3.45,0,0,0,.28,1.39A3.62,3.62,0,0,0,9.4,64.51a3.45,3.45,0,0,0,1.39.28Zm18-43.45a13.14,13.14,0,0,0-1.16-5.5,14.41,14.41,0,0,0-3.14-4.5,15,15,0,0,0-4.61-3,14.14,14.14,0,0,0-5.5-1.1H15A10.73,10.73,0,0,1,21.88.51,10.93,10.93,0,0,1,25.21,0H50.38a20.82,20.82,0,0,1,8.4,1.71A21.72,21.72,0,0,1,70.29,13.18,20.91,20.91,0,0,1,72,21.59v25.2a10.93,10.93,0,0,1-.51,3.33A10.71,10.71,0,0,1,70,53.05a10.84,10.84,0,0,1-2.28,2.36,10.66,10.66,0,0,1-3,1.58Z" />
<Setter TargetName="IconPath" Property="Data" Value="F1 M1024,1024z M0,0z M739.95130434,284.04869566L739.95130434,942.37206261 81.62793739,942.37206261 81.62793739,284.04869566 739.95130434,284.04869566 M740.55917449,208.06492754L80.4121971,208.06492754C39.07702725,208.06492754,5.03629913,241.49778551,5.03629913,283.44082551L5.03629913,943.5878029C5.03629913,984.92297275,38.4691571,1018.96370087,80.4121971,1018.96370087L740.55917449,1018.96370087C781.89434434,1018.96370087,815.93507246,985.5308429,815.93507246,943.5878029L815.93507246,283.44082551C815.93507246,241.49778551,782.50221449,208.06492754,740.55917449,208.06492754z M1024,1024z M0,0z M944.19567304,5.64416928L282.83295536,5.64416928C241.49778551,5.64416928,208.67279768,39.07702725,208.06492754,79.80432696L208.06492754,157.00383536 284.04869566,157.00383536 284.04869566,81.62793739 942.37206261,81.62793739 942.37206261,739.95130434 866.38829449,739.95130434 866.38829449,815.93507246 943.5878029,815.93507246C984.92297275,815.93507246,1017.74796058,782.50221449,1018.35583072,741.16704464L1018.35583072,79.80432696C1018.35583072,39.07702725,984.92297275,5.64416928,944.19567304,5.64416928z" />
</Trigger>
<Trigger Property="ButtonType" Value="{x:Static controls:TitleBarButtonType.Maximize}">
<Setter Property="CommandParameter" Value="{x:Static controls:TitleBarButtonType.Maximize}" />
<Setter TargetName="CanvasPath" Property="Data" Value="M10.62,72a9.92,9.92,0,0,1-4-.86A11.15,11.15,0,0,1,.86,65.43,9.92,9.92,0,0,1,0,61.38V10.62a9.92,9.92,0,0,1,.86-4A11.15,11.15,0,0,1,6.57.86a9.92,9.92,0,0,1,4-.86H61.38a9.92,9.92,0,0,1,4.05.86,11.15,11.15,0,0,1,5.71,5.71,9.92,9.92,0,0,1,.86,4V61.38a9.92,9.92,0,0,1-.86,4.05,11.15,11.15,0,0,1-5.71,5.71,9.92,9.92,0,0,1-4.05.86Zm50.59-7.21a3.45,3.45,0,0,0,1.39-.28,3.62,3.62,0,0,0,1.91-1.91,3.45,3.45,0,0,0,.28-1.39V10.79a3.45,3.45,0,0,0-.28-1.39A3.62,3.62,0,0,0,62.6,7.49a3.45,3.45,0,0,0-1.39-.28H10.79a3.45,3.45,0,0,0-1.39.28A3.62,3.62,0,0,0,7.49,9.4a3.45,3.45,0,0,0-.28,1.39V61.21a3.45,3.45,0,0,0,.28,1.39A3.62,3.62,0,0,0,9.4,64.51a3.45,3.45,0,0,0,1.39.28Z" />
<Setter TargetName="IconPath" Property="Data" Value="F1 M1024,1024z M0,0z M926.45937303,97.54062697L926.45937303,925.83799467 97.54062697,925.83799467 97.54062697,97.54062697 926.45937303,97.54062697 M931.4304,19.86833067L92.5696,19.86833067C52.8013843,19.86833067,20.48970903,52.18000592,20.48970903,91.94822163L20.48970903,931.4304C20.48970903,971.1986157,52.80138428,1003.51029097,92.5696,1003.51029097L932.05177837,1003.51029097C971.81999407,1003.51029097,1004.13166934,971.19861572,1004.13166933,931.4304L1004.13166933,92.5696C1004.13166933,52.18000592 971.81999408,19.86833067 931.4304,19.86833067 932.05177837,19.86833067 931.4304,19.86833067 931.4304,19.86833067z" />
</Trigger>
<Trigger Property="ButtonType" Value="{x:Static controls:TitleBarButtonType.Close}">
<Setter Property="CommandParameter" Value="{x:Static controls:TitleBarButtonType.Close}" />
<Setter TargetName="CanvasPath" Property="Data" Value="M36,41.1,6.15,71a3.44,3.44,0,0,1-2.53,1A3.55,3.55,0,0,1,0,68.38a3.44,3.44,0,0,1,1.05-2.53L30.9,36,1.05,6.15A3.49,3.49,0,0,1,0,3.59,3.51,3.51,0,0,1,.28,2.18,3.42,3.42,0,0,1,1.05,1,3.82,3.82,0,0,1,2.21.28,3.58,3.58,0,0,1,3.62,0,3.44,3.44,0,0,1,6.15,1.05L36,30.9,65.85,1.05a3.49,3.49,0,0,1,2.56-1A3.39,3.39,0,0,1,69.8.28,3.8,3.8,0,0,1,71,1.05a3.8,3.8,0,0,1,.77,1.15A3.39,3.39,0,0,1,72,3.59a3.49,3.49,0,0,1-1,2.56L41.1,36,71,65.85a3.44,3.44,0,0,1,1,2.53,3.58,3.58,0,0,1-.28,1.41A3.82,3.82,0,0,1,71,71a3.42,3.42,0,0,1-1.14.77,3.66,3.66,0,0,1-4-.77Z" />
<Setter TargetName="IconPath" Property="Data" Value="F1 M1024,1024z M0,0z M578.36284173,512L1000.67183457,89.69100716C1018.7707914,71.59205033 1018.7707914,41.42712226 1000.67183457,23.32816543 982.57287774,5.22920860000003 952.40794967,5.22920860000003 934.30899284,23.32816543L512,445.63715827 89.69100716,23.32816543C71.59205033,5.22920860000001 41.42712226,5.22920860000001 23.32816543,23.32816543 5.22920860000003,41.42712226 5.22920860000003,71.59205033 23.32816543,89.69100716L445.63715827,512 23.32816543,934.30899284C5.22920860000001,952.40794967 5.22920860000001,982.57287774 23.32816543,1000.67183457 41.42712226,1018.7707914 71.59205033,1018.7707914 89.69100716,1000.67183457L512,578.36284173 934.30899284,1000.67183457C952.40794967,1018.7707914 982.57287774,1018.7707914 1000.67183457,1000.67183457 1018.7707914,982.57287774 1018.7707914,952.40794967 1000.67183457,934.30899284L578.36284173,512z" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
@@ -72,16 +60,13 @@
</Style>
<Style TargetType="{x:Type controls:TitleBar}">
<Setter Property="Background" Value="{DynamicResource WindowBackground}" />
<Setter Property="Background" Value="{DynamicResource ApplicationBackgroundColorBrush}" />
<Setter Property="ButtonsBackground" Value="#1A000000" />
<Setter Property="ButtonsForeground" Value="{DynamicResource ButtonForeground}" />
<Setter Property="ButtonsForeground" Value="{DynamicResource TextFillColorPrimaryBrush}" />
<Setter Property="Focusable" Value="False" />
<Setter Property="FontSize" Value="12" />
<Setter Property="FontWeight" Value="Normal" />
<Setter Property="Foreground" Value="{DynamicResource WindowForeground}" />
<Setter Property="Foreground" Value="{DynamicResource ButtonForeground}" />
<!--<Setter Property="Height" Value="30" />-->
<!--<Setter Property="Height" Value="48" />-->
<Setter Property="Foreground" Value="{DynamicResource TextFillColorPrimaryBrush}" />
<Setter Property="HorizontalAlignment" Value="Stretch" />
<Setter Property="OverridesDefaultStyle" Value="True" />
<Setter Property="Padding" Value="16,4" />
@@ -93,7 +78,7 @@
x:Name="PART_MainGrid"
HorizontalAlignment="{TemplateBinding HorizontalAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
Background="{DynamicResource WindowBackground}">
Background="{DynamicResource ApplicationBackgroundColorBrush}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
@@ -125,12 +110,13 @@
Grid.Column="1"
Margin="12,0"
Content="{Binding Title,RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=Window}}"
TextElement.Foreground="{DynamicResource WindowForeground}" />-->
TextElement.Foreground="{DynamicResource TextFillColorPrimaryBrush}" />-->
<ContentPresenter
x:Name="PART_TitleBlock"
Grid.Column="1"
Margin="12,0"
Content="{TemplateBinding Title}" TextElement.Foreground="{DynamicResource WindowForeground}"/>
Content="{TemplateBinding Title}"
TextElement.Foreground="{DynamicResource TextFillColorPrimaryBrush}" />
<!--<TextBlock
Grid.Column="1"
Height="16"
@@ -183,7 +169,7 @@
x:Name="PART_CloseButton"
Grid.Column="3"
ButtonType="Close"
MouseOverBackground="{DynamicResource PaletteRedBrush}"
MouseOverBackground="#C42B1C"
MouseOverButtonsForeground="White" />
</Grid>
</Grid>
@@ -205,7 +191,6 @@
<Condition Property="ShowMaximize" Value="True" />
<Condition Property="IsMaximized" Value="True" />
</MultiTrigger.Conditions>
<Setter TargetName="PART_MaximizeButton" Property="ButtonType" Value="Restore" />
</MultiTrigger>
<Trigger Property="ShowHelp" Value="False">
@@ -224,10 +209,5 @@
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="VerticalAlignment" Value="Center" />
<Setter Property="VerticalContentAlignment" Value="Stretch" />
<Setter Property="VerticalContentAlignment" Value="Stretch" />
</Style>
</ResourceDictionary>