整理控件库

This commit is contained in:
GG Z
2025-05-05 17:04:06 +08:00
parent 74532b77be
commit 3eaad7566e
283 changed files with 2156 additions and 17846 deletions

View File

@@ -1,15 +0,0 @@
namespace WPFluent.Controls;
/// <summary>
/// Control changing its properties or appearance depending on the theme.
/// </summary>
public interface IThemeControl
{
/// <summary>
/// Gets the theme that is currently set.
/// </summary>
public Appearance.ApplicationTheme ApplicationTheme { get; }
}

View File

@@ -1,22 +1,13 @@

using System.Diagnostics;
using System.Windows.Data;
using System.Windows.Input;
using WPFluent.Designer;
using System.Windows.Input;
using WPFluent.Extensions;
using WPFluent.Input;
using WPFluent.Interop;
// ReSharper disable once CheckNamespace
namespace WPFluent.Controls;
/// <summary>
/// Custom navigation buttons for the window.
/// HCWhite navigation buttons for the window.
/// </summary>
[TemplatePart(Name = ElementMainGrid, Type = typeof(System.Windows.Controls.Grid))]
[TemplatePart(Name = ElementIcon, Type = typeof(System.Windows.Controls.Image))]
@@ -25,7 +16,7 @@ namespace WPFluent.Controls;
[TemplatePart(Name = ElementMaximizeButton, Type = typeof(TitleBarButton))]
[TemplatePart(Name = ElementRestoreButton, Type = typeof(TitleBarButton))]
[TemplatePart(Name = ElementCloseButton, Type = typeof(TitleBarButton))]
public class TitleBar : System.Windows.Controls.Control, IThemeControl
public class TitleBar : System.Windows.Controls.Control
{
private const string ElementCloseButton = "PART_CloseButton";
private const string ElementHelpButton = "PART_HelpButton";
@@ -37,15 +28,6 @@ public class TitleBar : System.Windows.Controls.Control, IThemeControl
private static DpiScale? dpiScale;
/// <summary>
/// Identifies the <see cref="ApplicationTheme"/> dependency property.
/// </summary>
public static readonly DependencyProperty ApplicationThemeProperty = DependencyProperty.Register(
nameof(ApplicationTheme),
typeof(Appearance.ApplicationTheme),
typeof(TitleBar),
new PropertyMetadata(Appearance.ApplicationTheme.Unknown));
/// <summary>
/// Identifies the <see cref="ButtonsBackground"/> dependency property.
/// </summary>
@@ -92,24 +74,6 @@ public class TitleBar : System.Windows.Controls.Control, IThemeControl
typeof(TitleBar),
new PropertyMetadata(false));
/// <summary>
/// Identifies the <see cref="ForceShutdown"/> dependency property.
/// </summary>
public static readonly DependencyProperty ForceShutdownProperty = DependencyProperty.Register(
nameof(ForceShutdown),
typeof(bool),
typeof(TitleBar),
new PropertyMetadata(false));
/// <summary>
/// Property for <see cref="Header"/>.
/// </summary>
public static readonly DependencyProperty HeaderProperty = DependencyProperty.Register(
nameof(Header),
typeof(object),
typeof(TitleBar),
new PropertyMetadata(null));
/// <summary>
/// Identifies the <see cref="HelpClicked"/> routed event.
/// </summary>
@@ -218,14 +182,12 @@ public class TitleBar : System.Windows.Controls.Control, IThemeControl
typeof(TitleBar),
new PropertyMetadata(null));
private readonly TitleBarButton[] _buttons = new TitleBarButton[4];
private System.Windows.Window _currentWindow = null!;
private readonly TitleBarButton[] buttons = new TitleBarButton[4];
private System.Windows.Window currentWindow;
/*private System.Windows.Controls.Grid _mainGrid = null!;*/
private System.Windows.Controls.ContentPresenter _icon = null!;
private System.Windows.Controls.ContentPresenter icon;
private DependencyObject _parentWindow;
private readonly TextBlock _titleBlock;
/// <summary>
/// Initializes a new instance of the <see cref="TitleBar"/> class and sets the default <see
@@ -237,16 +199,6 @@ public class TitleBar : System.Windows.Controls.Control, IThemeControl
dpiScale ??= VisualTreeHelper.GetDpi(this);
_titleBlock = new TextBlock();
_titleBlock.VerticalAlignment = VerticalAlignment.Center;
_titleBlock.SetBinding(
System.Windows.Controls.TextBlock.TextProperty,
new Binding(nameof(Title)) { Source = this });
_titleBlock.SetBinding(
System.Windows.Controls.TextBlock.FontSizeProperty,
new Binding(nameof(FontSize)) { Source = this });
Header = _titleBlock;
Loaded += OnLoaded;
Unloaded += OnUnloaded;
}
@@ -289,17 +241,7 @@ public class TitleBar : System.Windows.Controls.Control, IThemeControl
private void CloseWindow()
{
Debug.WriteLine(
$"INFO | {typeof(TitleBar)}.CloseWindow:ForceShutdown - {ForceShutdown}",
"WPFluent.TitleBar");
if (ForceShutdown)
{
UiApplication.Current.Shutdown();
return;
}
_currentWindow.Close();
currentWindow.Close();
}
private T GetTemplateChild<T>(string name) where T : DependencyObject
@@ -329,15 +271,15 @@ public class TitleBar : System.Windows.Controls.Control, IThemeControl
return IntPtr.Zero;
}
foreach (TitleBarButton button in _buttons)
foreach (TitleBarButton button in buttons)
{
if (!button.ReactToHwndHook(message, lParam, out IntPtr returnIntPtr))
{
continue;
}
// Fix for when sometimes, button hover backgrounds aren't cleared correctly, causing multiple buttons to appear as if hovered.
foreach (TitleBarButton anotherButton in _buttons)
// 修复了有时未正确清除按钮悬停背景,导致多个按钮看起来好像悬停的问题。
foreach (TitleBarButton anotherButton in buttons)
{
if (anotherButton == button)
{
@@ -356,26 +298,24 @@ public class TitleBar : System.Windows.Controls.Control, IThemeControl
var isMouseOverHeaderContent = false;
if (message == User32.WM.NCHITTEST && (TrailingContent is UIElement || Header is UIElement))
{
var headerLeftUIElement = Header as UIElement;
var headerRightUiElement = TrailingContent as UIElement;
//if (message == User32.WM.NCHITTEST && (TrailingContent is UIElement))
//{
// var headerRightUiElement = TrailingContent as UIElement;
if (headerLeftUIElement is not null && headerLeftUIElement != _titleBlock)
{
isMouseOverHeaderContent =
headerLeftUIElement.IsMouseOverElement(lParam) ||
(headerRightUiElement?.IsMouseOverElement(lParam) ?? false);
}
else
{
isMouseOverHeaderContent = headerRightUiElement?.IsMouseOverElement(lParam) ?? false;
}
}
// if (headerLeftUIElement is not null)
// {
// isMouseOverHeaderContent =
// (headerRightUiElement?.IsMouseOverElement(lParam) ?? false);
// }
// else
// {
// isMouseOverHeaderContent = headerRightUiElement?.IsMouseOverElement(lParam) ?? false;
// }
//}
switch (message)
{
case User32.WM.NCHITTEST when CloseWindowByDoubleClickOnIcon && _icon.IsMouseOverElement(lParam):
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
handled = true;
return (IntPtr)User32.WM_NCHITTEST.HTSYSMENU;
@@ -396,20 +336,20 @@ public class TitleBar : System.Windows.Controls.Control, IThemeControl
if (MaximizeActionOverride is not null)
{
MaximizeActionOverride(this, _currentWindow);
MaximizeActionOverride(this, currentWindow);
return;
}
if (_currentWindow.WindowState == WindowState.Normal)
if (currentWindow.WindowState == WindowState.Normal)
{
SetCurrentValue(IsMaximizedProperty, true);
_currentWindow.SetCurrentValue(Window.WindowStateProperty, WindowState.Maximized);
currentWindow.SetCurrentValue(Window.WindowStateProperty, WindowState.Maximized);
}
else
{
SetCurrentValue(IsMaximizedProperty, false);
_currentWindow.SetCurrentValue(Window.WindowStateProperty, WindowState.Normal);
currentWindow.SetCurrentValue(Window.WindowStateProperty, WindowState.Normal);
}
}
@@ -417,22 +357,25 @@ public class TitleBar : System.Windows.Controls.Control, IThemeControl
{
if (MinimizeActionOverride is not null)
{
MinimizeActionOverride(this, _currentWindow);
MinimizeActionOverride(this, currentWindow);
return;
}
_currentWindow.SetCurrentValue(Window.WindowStateProperty, WindowState.Minimized);
currentWindow.SetCurrentValue(Window.WindowStateProperty, WindowState.Minimized);
}
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);
SetCurrentValue(IsMaximizedProperty, currentWindow.WindowState == WindowState.Maximized);
}
}
/// <summary>
/// 设置窗口状态
/// </summary>
/// <param name="buttonType"></param>
private void OnTemplateButtonClick(TitleBarButtonType buttonType)
{
switch (buttonType)
@@ -463,8 +406,6 @@ public class TitleBar : System.Windows.Controls.Control, IThemeControl
{
Loaded -= OnLoaded;
Unloaded -= OnUnloaded;
Appearance.ApplicationThemeManager.Changed -= OnThemeChanged;
}
/// <summary>
@@ -486,7 +427,7 @@ public class TitleBar : System.Windows.Controls.Control, IThemeControl
}
/// <summary>
/// Show 'SystemMenu' on mouse right button up.
/// 在鼠标右键时显示 'SystemMenu'
/// </summary>
private void TitleBar_MouseRightButtonUp(object sender, MouseButtonEventArgs e)
{
@@ -502,43 +443,22 @@ public class TitleBar : System.Windows.Controls.Control, IThemeControl
new Point(point.X / dpiScale.Value.DpiScaleX, point.Y / dpiScale.Value.DpiScaleY));
}
/// <inheritdoc/>
protected override void OnInitialized(EventArgs e)
{
base.OnInitialized(e);
SetCurrentValue(ApplicationThemeProperty, Appearance.ApplicationThemeManager.GetAppTheme());
Appearance.ApplicationThemeManager.Changed += OnThemeChanged;
}
protected virtual void OnLoaded(object sender, RoutedEventArgs e)
{
if (DesignerHelper.IsInDesignMode)
{
return;
}
_currentWindow =
currentWindow =
System.Windows.Window.GetWindow(this) ?? throw new InvalidOperationException("Window is null");
_currentWindow.StateChanged += OnParentWindowStateChanged;
_currentWindow.ContentRendered += OnWindowContentRendered;
currentWindow.StateChanged += OnParentWindowStateChanged;
currentWindow.ContentRendered += OnWindowContentRendered;
}
/// <summary>
/// This virtual method is triggered when the app's theme changes.
/// 获取单击标题栏按钮时触发的命令。
/// </summary>
protected virtual void OnThemeChanged(Appearance.ApplicationTheme currentApplicationTheme, Color systemAccent)
{
Debug.WriteLine(
$"INFO | {typeof(TitleBar)} received theme - {currentApplicationTheme}",
"WPFluent.TitleBar");
internal IRelayCommand TemplateButtonCommand => (IRelayCommand)GetValue(TemplateButtonCommandProperty);
SetCurrentValue(ApplicationThemeProperty, currentApplicationTheme);
}
/// <summary>
/// Invoked whenever application code or an internal process, such as a rebuilding layout pass, calls the
/// ApplyTemplate method.
/// 每当应用程序代码或内部进程如重建布局传递调用OnApplyTemplate方法。
/// </summary>
public override void OnApplyTemplate()
{
@@ -554,28 +474,28 @@ public class TitleBar : System.Windows.Controls.Control, IThemeControl
MouseRightButtonUp += TitleBar_MouseRightButtonUp;
/*_mainGrid = GetTemplateChild<System.Windows.Controls.Grid>(ElementMainGrid);*/
_icon = GetTemplateChild<System.Windows.Controls.ContentPresenter>(ElementIcon);
icon = GetTemplateChild<System.Windows.Controls.ContentPresenter>(ElementIcon);
var helpButton = GetTemplateChild<TitleBarButton>(ElementHelpButton);
var minimizeButton = GetTemplateChild<TitleBarButton>(ElementMinimizeButton);
var maximizeButton = GetTemplateChild<TitleBarButton>(ElementMaximizeButton);
var closeButton = GetTemplateChild<TitleBarButton>(ElementCloseButton);
_buttons[0] = maximizeButton;
_buttons[1] = minimizeButton;
_buttons[2] = closeButton;
_buttons[3] = helpButton;
buttons[0] = maximizeButton;
buttons[1] = minimizeButton;
buttons[2] = closeButton;
buttons[3] = helpButton;
}
/// <inheritdoc/>
public Appearance.ApplicationTheme ApplicationTheme
{
get => (Appearance.ApplicationTheme)GetValue(ApplicationThemeProperty);
set => SetValue(ApplicationThemeProperty, value);
}
///// <inheritdoc/>
//public Appearance.ThemeType ApplicationTheme
//{
// get => (Appearance.ThemeType)GetValue(ApplicationThemeProperty);
// set => SetValue(ApplicationThemeProperty, value);
//}
/// <summary>
/// Gets or sets the background of the navigation buttons when hovered.
/// 获取或设置导航按钮悬停时的背景。
/// </summary>
[Bindable(true)]
[Category("Appearance")]
@@ -611,27 +531,13 @@ public class TitleBar : System.Windows.Controls.Control, IThemeControl
set => SetValue(CloseWindowByDoubleClickOnIconProperty, value);
}
/// <summary>
/// Gets or sets a value indicating whether the controls affect main application window.
/// </summary>
public bool ForceShutdown
{
get => (bool)GetValue(ForceShutdownProperty);
set => SetValue(ForceShutdownProperty, value);
}
/// <summary>
/// Gets or sets the content displayed in the left side of the <see cref="TitleBar"/>.
/// </summary>
public object Header { get => GetValue(HeaderProperty); set => SetValue(HeaderProperty, value); }
/// <summary>
/// Gets or sets the titlebar icon.
/// </summary>
public IconElement Icon { get => (IconElement)GetValue(IconProperty); set => SetValue(IconProperty, value); }
/// <summary>
/// Gets a value indicating whether the current window is maximized.
/// 获取一个值,该值指示当前窗口是否最大化。
/// </summary>
public bool IsMaximized
{
@@ -640,27 +546,27 @@ public class TitleBar : System.Windows.Controls.Control, IThemeControl
}
/// <summary>
/// Gets or sets the <see cref="Action"/> that should be executed when the Maximize button is clicked."/>
/// 获取或设置单击“最大化”按钮时应执行的 <see cref=Action/>
/// </summary>
public Action<TitleBar, System.Windows.Window> MaximizeActionOverride { get; set; }
/// <summary>
/// Gets or sets what <see cref="Action"/> should be executed when the Minimize button is clicked.
/// 获取或设置在单击 Minimize 按钮时应执行的 <see cref=Action/> 内容。
/// </summary>
public Action<TitleBar, System.Windows.Window> MinimizeActionOverride { get; set; }
/// <summary>
/// Gets or sets a value indicating whether to show the close button.
/// 获取或设置一个值,该值指示是否显示关闭按钮。
/// </summary>
public bool ShowClose { get => (bool)GetValue(ShowCloseProperty); set => SetValue(ShowCloseProperty, value); }
/// <summary>
/// Gets or sets a value indicating whether to show the help button
/// 获取或设置一个值,该值指示是否显示 help 按钮
/// </summary>
public bool ShowHelp { get => (bool)GetValue(ShowHelpProperty); set => SetValue(ShowHelpProperty, value); }
/// <summary>
/// Gets or sets a value indicating whether to show the maximize button.
/// 获取或设置一个值,该值指示是否显示 maximize (最大化) 按钮。
/// </summary>
public bool ShowMaximize
{
@@ -669,7 +575,7 @@ public class TitleBar : System.Windows.Controls.Control, IThemeControl
}
/// <summary>
/// Gets or sets a value indicating whether to show the minimize button.
/// 获取或设置一个值,该值指示是否显示 minimize (最小化) 按钮。
/// </summary>
public bool ShowMinimize
{
@@ -678,21 +584,16 @@ public class TitleBar : System.Windows.Controls.Control, IThemeControl
}
/// <summary>
/// Gets the command triggered when clicking the titlebar button.
/// </summary>
internal IRelayCommand TemplateButtonCommand => (IRelayCommand)GetValue(TemplateButtonCommandProperty);
/// <summary>
/// Gets or sets title displayed on the left.
/// 获取或设置显示在左侧的标题。
/// </summary>
public string Title { get => (string)GetValue(TitleProperty); set => SetValue(TitleProperty, value); }
/// <summary>
/// Gets or sets the content displayed in right side of the <see cref="TitleBar"/>.
/// 获取或设置在右侧显示的内容 <see cref="TitleBar"/>.
/// </summary>
public object TrailingContent
{
get => GetValue(TrailingContentProperty);
set => SetValue(TrailingContentProperty, value);
}
}
}

View File

@@ -1,29 +1,21 @@
<!--
This Source Code Form is subject to the terms of the MIT License.
If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT.
Copyright (C) Leszek Pomianowski and WPF UI Contributors.
All Rights Reserved.
-->
<ResourceDictionary
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="clr-namespace:WPFluent.Controls">
<Style TargetType="{x:Type controls:TitleBarButton}">
<Setter Property="Width" Value="44" />
<Setter Property="Height" Value="30" />
<Setter Property="MouseOverBackground" Value="{Binding Path=ButtonsBackground, RelativeSource={RelativeSource AncestorType={x:Type controls:TitleBar}}}" />
<Setter Property="ButtonsForeground" Value="{Binding Path=ButtonsForeground, RelativeSource={RelativeSource AncestorType={x:Type controls:TitleBar}}}" />
<Setter Property="MouseOverButtonsForeground" Value="{Binding Path=MouseOverButtonsForeground, RelativeSource={RelativeSource Self}}" />
<Setter Property="Background" Value="Transparent" />
<Setter Property="FocusVisualStyle" Value="{DynamicResource DefaultControlFocusVisualStyle}" />
<Setter Property="SnapsToDevicePixels" Value="True" />
<Setter Property="OverridesDefaultStyle" Value="True" />
<Setter Property="Command" Value="{Binding Path=TemplateButtonCommand, RelativeSource={RelativeSource AncestorType={x:Type controls:TitleBar}}}" />
<Setter Property="KeyboardNavigation.IsTabStop" Value="True" />
<Setter Property="Focusable" Value="False" />
<Setter Property="ButtonsForeground" Value="{Binding Path=ButtonsForeground, RelativeSource={RelativeSource AncestorType={x:Type controls:TitleBar}}}" />
<Setter Property="Canvas.ZIndex" Value="1" />
<Setter Property="Command" Value="{Binding Path=TemplateButtonCommand, RelativeSource={RelativeSource AncestorType={x:Type controls:TitleBar}}}" />
<Setter Property="Focusable" Value="False" />
<Setter Property="FocusVisualStyle" Value="{DynamicResource DefaultControlFocusVisualStyle}" />
<Setter Property="Height" Value="30" />
<Setter Property="KeyboardNavigation.IsTabStop" Value="True" />
<Setter Property="MouseOverBackground" Value="{Binding Path=ButtonsBackground, RelativeSource={RelativeSource AncestorType={x:Type controls:TitleBar}}}" />
<Setter Property="MouseOverButtonsForeground" Value="{Binding Path=MouseOverButtonsForeground, RelativeSource={RelativeSource Self}}" />
<Setter Property="OverridesDefaultStyle" Value="True" />
<Setter Property="SnapsToDevicePixels" Value="True" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type controls:TitleBarButton}">
@@ -48,17 +40,17 @@
<ControlTemplate.Triggers>
<Trigger Property="ButtonType" Value="{x:Static controls:TitleBarButtonType.Help}">
<Setter Property="CommandParameter" Value="{x:Static controls:TitleBarButtonType.Help}" />
<Setter TargetName="ViewBox" Property="Width" Value="13" />
<Setter TargetName="ViewBox" Property="Height" Value="13" />
<Setter TargetName="Canvas" Property="Width" Value="24" />
<Setter TargetName="Canvas" Property="Height" Value="41" />
<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" />
</Trigger>
<Trigger Property="ButtonType" Value="{x:Static controls:TitleBarButtonType.Minimize}">
<Setter Property="CommandParameter" Value="{x:Static controls:TitleBarButtonType.Minimize}" />
<Setter TargetName="Canvas" Property="Width" Value="72" />
<Setter TargetName="Canvas" Property="Height" Value="8" />
<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" />
</Trigger>
<Trigger Property="ButtonType" Value="{x:Static controls:TitleBarButtonType.Restore}">
<Setter Property="CommandParameter" Value="{x:Static controls:TitleBarButtonType.Restore}" />
@@ -76,27 +68,24 @@
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="Width" Value="44" />
</Style>
<Style TargetType="{x:Type controls:TitleBar}">
<Setter Property="Background" Value="Transparent" />
<Setter Property="Foreground" Value="{DynamicResource ButtonForeground}" />
<Setter Property="Background" Value="{DynamicResource WindowBackground}" />
<Setter Property="ButtonsBackground" Value="#1A000000" />
<Setter Property="ButtonsForeground" Value="{DynamicResource ButtonForeground}" />
<Setter Property="ButtonsBackground">
<Setter.Value>
<SolidColorBrush Color="#1A000000" />
</Setter.Value>
</Setter>
<Setter Property="VerticalAlignment" Value="Top" />
<Setter Property="HorizontalAlignment" Value="Stretch" />
<Setter Property="Padding" Value="16,4,16,4" />
<Setter Property="FontSize" Value="12" />
<Setter Property="Height" Value="48" />
<Setter Property="FontWeight" Value="Normal" />
<Setter Property="Focusable" Value="False" />
<Setter Property="VerticalContentAlignment" Value="Stretch" />
<Setter Property="SnapsToDevicePixels" Value="True" />
<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="HorizontalAlignment" Value="Stretch" />
<Setter Property="OverridesDefaultStyle" Value="True" />
<Setter Property="Padding" Value="16,4" />
<Setter Property="SnapsToDevicePixels" Value="True" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type controls:TitleBar}">
@@ -104,12 +93,11 @@
x:Name="PART_MainGrid"
HorizontalAlignment="{TemplateBinding HorizontalAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
Background="{TemplateBinding Background}">
Background="{DynamicResource WindowBackground}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid
x:Name="TitleGrid"
Grid.Column="0"
@@ -121,34 +109,46 @@
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<!-- Custom application icon -->
<!-- 自定义应用程序图标 -->
<ContentPresenter
x:Name="PART_Icon"
Grid.Column="0"
Height="16"
Margin="0,0,12,0"
VerticalAlignment="Center"
Margin="12,0"
Content="{TemplateBinding Icon}"
Focusable="False"
RenderOptions.BitmapScalingMode="HighQuality" />
<!-- Title text or other header content -->
<ContentPresenter
<!-- 标题文字或其它内容 -->
<!--<ContentPresenter
x:Name="PART_TitleBlock"
Grid.Column="1"
HorizontalAlignment="Left"
Content="{TemplateBinding Header}" />
Margin="12,0"
Content="{Binding Title,RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=Window}}"
TextElement.Foreground="{DynamicResource WindowForeground}" />-->
<ContentPresenter
x:Name="PART_TitleBlock"
Grid.Column="1"
Margin="12,0"
Content="{TemplateBinding Title}" TextElement.Foreground="{DynamicResource WindowForeground}"/>
<!--<TextBlock
Grid.Column="1"
Height="16"
VerticalAlignment="Center"
Text="{TemplateBinding Header}"/>-->
</Grid>
<Grid Grid.Column="1">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<!-- Additional header content -->
<!-- 右侧的附加内容 -->
<ContentPresenter
Grid.Column="0"
HorizontalAlignment="Right"
VerticalAlignment="Center"
Content="{TemplateBinding TrailingContent}" />
<!-- Navigation buttons - Close, Restore, Maximize, Minimize -->
@@ -161,7 +161,6 @@
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<controls:TitleBarButton
@@ -177,12 +176,12 @@
<controls:TitleBarButton
x:Name="PART_MaximizeButton"
Grid.Column="2"
ButtonType="Maximize"
IsHitTestVisible="False"/>
ButtonType="Maximize"
IsHitTestVisible="False" />
<controls:TitleBarButton
x:Name="PART_CloseButton"
Grid.Column="4"
Grid.Column="3"
ButtonType="Close"
MouseOverBackground="{DynamicResource PaletteRedBrush}"
MouseOverButtonsForeground="White" />
@@ -197,16 +196,9 @@
</MultiTrigger.Conditions>
<Setter TargetName="TitleGrid" Property="Visibility" Value="Collapsed" />
</MultiTrigger>
<Trigger Property="ApplicationTheme" Value="Dark">
<Setter Property="ButtonsBackground">
<Setter.Value>
<SolidColorBrush Color="#17FFFFFF" />
</Setter.Value>
</Setter>
</Trigger>
<Trigger Property="Icon" Value="{x:Null}">
<Setter TargetName="PART_Icon" Property="Visibility" Value="Collapsed" />
<Setter TargetName="PART_Icon" Property="Margin" Value="0" />
<Setter TargetName="PART_Icon" Property="Visibility" Value="Collapsed" />
</Trigger>
<MultiTrigger>
<MultiTrigger.Conditions>
@@ -232,6 +224,10 @@
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="VerticalAlignment" Value="Center" />
<Setter Property="VerticalContentAlignment" Value="Stretch" />
<Setter Property="VerticalContentAlignment" Value="Stretch" />
</Style>
</ResourceDictionary>
</ResourceDictionary>

View File

@@ -10,7 +10,7 @@ namespace WPFluent.Controls;
public enum TitleBarButtonType
{
/// <summary>
/// Unknown button.
/// HCWhite button.
/// </summary>
Unknown,