更新整理
This commit is contained in:
@@ -7,18 +7,20 @@ using WPFluent.Interop;
|
||||
namespace WPFluent.Appearance;
|
||||
|
||||
/// <summary>
|
||||
/// Allows updating the accents used by controls in the application by swapping dynamic resources.
|
||||
/// 允许通过交换动态资源来更新应用程序中控件使用的Accent。
|
||||
/// </summary>
|
||||
/// <example>
|
||||
/// <code lang="csharp"> /// ApplicationAccentColorManager.Apply( /// Color.FromArgb(0xFF, 0xEE, 0x00, 0xBB), ///
|
||||
/// ApplicationTheme.Dark, /// false /// ); ///</code> <code lang="csharp"> ///
|
||||
/// ApplicationAccentColorManager.Apply( /// ApplicationAccentColorManager.GetColorizationColor(), ///
|
||||
/// ApplicationTheme.Dark, /// false /// ); ///</code>
|
||||
/// <code lang="csharp">
|
||||
/// ApplicationAccentColorManager.Apply(Color.FromArgb(0xFF, 0xEE, 0x00, 0xBB),ApplicationTheme.Dark,false);
|
||||
/// </code>
|
||||
/// <code lang="csharp">
|
||||
/// ApplicationAccentColorManager.Apply(ApplicationAccentColorManager.GetColorizationColor(),ApplicationTheme.Dark,false);
|
||||
///</code>
|
||||
/// </example>
|
||||
public static class ApplicationAccentColorManager
|
||||
{
|
||||
/// <summary>
|
||||
/// The maximum value of the background HSV brightness after which the text on the accent will be turned dark.
|
||||
/// 背景 HSV 亮度的最大值,超过该值后,重音上的文字将变暗。
|
||||
/// </summary>
|
||||
private const double BackgroundBrightnessThresholdValue = 80d;
|
||||
|
||||
@@ -31,15 +33,8 @@ public static class ApplicationAccentColorManager
|
||||
Color secondaryAccent,
|
||||
Color tertiaryAccent)
|
||||
{
|
||||
System.Diagnostics.Debug.WriteLine($"INFO | SystemAccentColor: {systemAccent}", "WPFluent.Accent");
|
||||
System.Diagnostics.Debug
|
||||
.WriteLine($"INFO | SystemAccentColorPrimary: {primaryAccent}", "WPFluent.Accent");
|
||||
System.Diagnostics.Debug
|
||||
.WriteLine($"INFO | SystemAccentColorSecondary: {secondaryAccent}", "WPFluent.Accent");
|
||||
System.Diagnostics.Debug
|
||||
.WriteLine($"INFO | SystemAccentColorTertiary: {tertiaryAccent}", "WPFluent.Accent");
|
||||
|
||||
if(secondaryAccent.GetBrightness() > BackgroundBrightnessThresholdValue)
|
||||
if (secondaryAccent.GetBrightness() > BackgroundBrightnessThresholdValue)
|
||||
{
|
||||
System.Diagnostics.Debug.WriteLine("INFO | Text on accent is DARK", "WPFluent.Accent");
|
||||
UiApplication.Current.Resources["TextOnAccentFillColorPrimary"] = Color.FromArgb(0xFF, 0x00, 0x00, 0x00);
|
||||
@@ -85,22 +80,21 @@ public static class ApplicationAccentColorManager
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Changes the color accents of the application based on the color entered.
|
||||
/// 根据输入的颜色更改应用程序的色彩基调。
|
||||
/// </summary>
|
||||
/// <param name="systemAccent">Primary accent color.</param>
|
||||
/// <param name="applicationTheme">If <see cref="ApplicationTheme.Dark"/>, the colors will be different.</param>
|
||||
/// <param name="systemAccent">原色强调色。</param>
|
||||
/// <param name="applicationTheme">如果是<see cref="ApplicationTheme.Dark"/>,颜色将有所不同。</param>
|
||||
/// <param name="systemGlassColor">
|
||||
/// If the color is taken from the Glass Color System, its brightness will be increased with the help of the
|
||||
/// operations on HSV space.
|
||||
/// 如果颜色取自玻璃色彩系统,则其亮度将借助 HSV 空间的操作而提高。
|
||||
/// </param>
|
||||
public static void Apply(
|
||||
Color systemAccent,
|
||||
ApplicationTheme applicationTheme = ApplicationTheme.Light,
|
||||
bool systemGlassColor = false)
|
||||
{
|
||||
if(systemGlassColor)
|
||||
if (systemGlassColor)
|
||||
{
|
||||
// WindowGlassColor is little darker than accent color
|
||||
// WindowGlassColor 比强调色深一点
|
||||
systemAccent = systemAccent.UpdateBrightness(6f);
|
||||
}
|
||||
|
||||
@@ -108,7 +102,7 @@ public static class ApplicationAccentColorManager
|
||||
Color secondaryAccent;
|
||||
Color tertiaryAccent;
|
||||
|
||||
if(applicationTheme == ApplicationTheme.Dark)
|
||||
if (applicationTheme == ApplicationTheme.Dark)
|
||||
{
|
||||
primaryAccent = systemAccent.Update(15f, -12f);
|
||||
secondaryAccent = systemAccent.Update(30f, -24f);
|
||||
@@ -134,17 +128,6 @@ public static class ApplicationAccentColorManager
|
||||
public static void Apply(Color systemAccent, Color primaryAccent, Color secondaryAccent, Color tertiaryAccent)
|
||||
{ UpdateColorResources(systemAccent, primaryAccent, secondaryAccent, tertiaryAccent); }
|
||||
|
||||
/// <summary>
|
||||
/// Applies system accent color to the application.
|
||||
/// </summary>
|
||||
public static void ApplySystemAccent() { Apply(GetColorizationColor(), ApplicationThemeManager.GetAppTheme()); }
|
||||
|
||||
/// <summary>
|
||||
/// Gets current Desktop Window Manager colorization color. <para>It should be the color defined in the system
|
||||
/// Personalization.</para>
|
||||
/// </summary>
|
||||
public static Color GetColorizationColor() { return UnsafeNativeMethods.GetDwmColor(); }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the SystemAccentColorPrimary.
|
||||
/// </summary>
|
||||
@@ -154,7 +137,7 @@ public static class ApplicationAccentColorManager
|
||||
{
|
||||
object? resource = UiApplication.Current.Resources["SystemAccentColorPrimary"];
|
||||
|
||||
if(resource is Color color)
|
||||
if (resource is Color color)
|
||||
{
|
||||
return color;
|
||||
}
|
||||
@@ -177,7 +160,7 @@ public static class ApplicationAccentColorManager
|
||||
{
|
||||
object? resource = UiApplication.Current.Resources["SystemAccentColorSecondary"];
|
||||
|
||||
if(resource is Color color)
|
||||
if (resource is Color color)
|
||||
{
|
||||
return color;
|
||||
}
|
||||
@@ -200,7 +183,7 @@ public static class ApplicationAccentColorManager
|
||||
{
|
||||
object? resource = UiApplication.Current.Resources["SystemAccentColor"];
|
||||
|
||||
if(resource is Color color)
|
||||
if (resource is Color color)
|
||||
{
|
||||
return color;
|
||||
}
|
||||
@@ -223,7 +206,7 @@ public static class ApplicationAccentColorManager
|
||||
{
|
||||
object? resource = UiApplication.Current.Resources["SystemAccentColorTertiary"];
|
||||
|
||||
if(resource is Color color)
|
||||
if (resource is Color color)
|
||||
{
|
||||
return color;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user