整理控件库
This commit is contained in:
@@ -1,16 +1,7 @@
|
||||
|
||||
|
||||
|
||||
|
||||
using System.Windows.Shell;
|
||||
using System.Windows.Shell;
|
||||
|
||||
using WPFluent.Appearance;
|
||||
|
||||
using WPFluent.Hardware;
|
||||
|
||||
using Size = System.Windows.Size;
|
||||
|
||||
// ReSharper disable once CheckNamespace
|
||||
namespace WPFluent.Controls;
|
||||
|
||||
/// <summary>
|
||||
@@ -23,78 +14,62 @@ namespace WPFluent.Controls;
|
||||
/// <code lang="xml"> <Style x:Key="MyWindowCustomStyle" BasedOn="{StaticResource {x:Type Window}}"
|
||||
/// TargetType="{x:Type controls:FluentWindow}"> <Setter Property="Template" > <Setter.Value>
|
||||
/// <ControlTemplate TargetType="{x:Type Window}"> <AdornerDecorator> <controls:ClientAreaBorder
|
||||
/// Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}"
|
||||
/// Background="{TemplateBinding Background}" ControlBorderBrush="{TemplateBinding ControlBorderBrush}"
|
||||
/// BorderThickness="{TemplateBinding BorderThickness}"> <ContentPresenter x:Name="ContentPresenter" />
|
||||
/// </controls:ClientAreaBorder> </AdornerDecorator> </ControlTemplate> </Setter.Value>
|
||||
/// </Setter> </Style></code>
|
||||
/// </example>
|
||||
public class ClientAreaBorder : System.Windows.Controls.Border, IThemeControl
|
||||
public class ClientAreaBorder : System.Windows.Controls.Border/*, IThemeControl*/
|
||||
{
|
||||
/*private const int SM_CXFRAME = 32;
|
||||
private const int SM_CYFRAME = 33;
|
||||
private const int SM_CXPADDEDBORDER = 92;*/
|
||||
private static Thickness? _paddedBorderThickness;
|
||||
private static Thickness? _resizeFrameBorderThickness;
|
||||
private static Thickness? _windowChromeNonClientFrameThickness;
|
||||
private bool _borderBrushApplied = false;
|
||||
//private bool borderBrushApplied = false;
|
||||
private System.Windows.Window? _oldWindow;
|
||||
|
||||
public ClientAreaBorder()
|
||||
{
|
||||
ApplicationTheme = Appearance.ApplicationThemeManager.GetAppTheme();
|
||||
Appearance.ApplicationThemeManager.Changed += OnThemeChanged;
|
||||
}
|
||||
//public ClientAreaBorder()
|
||||
//{
|
||||
// ApplicationTheme = Appearance.ThemeManager.GetAppTheme();
|
||||
// Appearance.ThemeManager.Changed += OnThemeChanged;
|
||||
//}
|
||||
|
||||
private void ApplyDefaultWindowBorder()
|
||||
{
|
||||
if (Win32.Utilities.IsOSWindows11OrNewer || _oldWindow == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
//private void ApplyDefaultWindowBorder()
|
||||
//{
|
||||
// if (_oldWindow == null)
|
||||
// {
|
||||
// return;
|
||||
// }
|
||||
|
||||
_borderBrushApplied = true;
|
||||
// borderBrushApplied = true;
|
||||
|
||||
// SystemParameters.WindowGlassBrush
|
||||
Color borderColor =
|
||||
ApplicationTheme == ApplicationTheme.Light
|
||||
? Color.FromArgb(0xFF, 0x7A, 0x7A, 0x7A)
|
||||
: Color.FromArgb(0xFF, 0x3A, 0x3A, 0x3A);
|
||||
_oldWindow.SetCurrentValue(
|
||||
System.Windows.Controls.Control.BorderBrushProperty,
|
||||
new SolidColorBrush(borderColor));
|
||||
_oldWindow.SetCurrentValue(System.Windows.Controls.Control.BorderThicknessProperty, new Thickness(1));
|
||||
}
|
||||
// // SystemParameters.WindowGlassBrush
|
||||
// Color borderColor =
|
||||
// ApplicationTheme == ThemeType.Light
|
||||
// ? Color.FromArgb(0xFF, 0x7A, 0x7A, 0x7A)
|
||||
// : Color.FromArgb(0xFF, 0x3A, 0x3A, 0x3A);
|
||||
// _oldWindow.SetCurrentValue(
|
||||
// System.Windows.Controls.Control.BorderBrushProperty,
|
||||
// new SolidColorBrush(borderColor));
|
||||
// _oldWindow.SetCurrentValue(System.Windows.Controls.Control.BorderThicknessProperty, new Thickness(1));
|
||||
//}
|
||||
|
||||
private (double FactorX, double FactorY) GetDpi()
|
||||
{
|
||||
if (PresentationSource.FromVisual(this) is { } source)
|
||||
{
|
||||
return (
|
||||
source.CompositionTarget.TransformToDevice.M11, // Possible null reference
|
||||
source.CompositionTarget.TransformToDevice.M22
|
||||
);
|
||||
}
|
||||
//private void OnThemeChanged(ThemeType currentApplicationTheme, Color systemAccent)
|
||||
//{
|
||||
// ApplicationTheme = currentApplicationTheme;
|
||||
|
||||
DisplayDpi systemDPi = DpiHelper.GetSystemDpi();
|
||||
// if (!borderBrushApplied || _oldWindow == null)
|
||||
// {
|
||||
// return;
|
||||
// }
|
||||
|
||||
return (systemDPi.DpiScaleX, systemDPi.DpiScaleY);
|
||||
}
|
||||
|
||||
private void OnThemeChanged(ApplicationTheme currentApplicationTheme, Color systemAccent)
|
||||
{
|
||||
ApplicationTheme = currentApplicationTheme;
|
||||
|
||||
if (!_borderBrushApplied || _oldWindow == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ApplyDefaultWindowBorder();
|
||||
}
|
||||
// ApplyDefaultWindowBorder();
|
||||
//}
|
||||
|
||||
private void OnWindowClosing(object? sender, CancelEventArgs e)
|
||||
{
|
||||
Appearance.ApplicationThemeManager.Changed -= OnThemeChanged;
|
||||
//Appearance.ThemeManager.Changed -= OnThemeChanged;
|
||||
if (_oldWindow != null)
|
||||
{
|
||||
_oldWindow.Closing -= OnWindowClosing;
|
||||
@@ -135,10 +110,10 @@ public class ClientAreaBorder : System.Windows.Controls.Border, IThemeControl
|
||||
|
||||
_oldWindow = newWindow;
|
||||
|
||||
ApplyDefaultWindowBorder();
|
||||
//ApplyDefaultWindowBorder();
|
||||
}
|
||||
|
||||
public ApplicationTheme ApplicationTheme { get; set; } = ApplicationTheme.Unknown;
|
||||
//public ThemeType ApplicationTheme { get; set; } = ThemeType.Unknow;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the system <see cref="User32.SM.CXFRAME"/> and <see cref="User32.SM.CYFRAME"/> values in WPF units.
|
||||
|
||||
@@ -27,7 +27,7 @@ namespace WPFluent.Controls;
|
||||
/// contentDialogService.SetContentPresenter(RootContentDialogPresenter);
|
||||
///
|
||||
/// await _contentDialogService.ShowSimpleDialogAsync(
|
||||
/// new SimpleContentDialogCreateOptions()
|
||||
/// new SimpleContentDialogOptions()
|
||||
/// {
|
||||
/// Title = "The cake?",
|
||||
/// Content = "IS A LIE!",
|
||||
|
||||
Reference in New Issue
Block a user