Derive nav/content shades from background and make config dialog frameless

This commit is contained in:
Meik
2026-03-05 12:05:51 +01:00
parent 48ae3a5a8f
commit d4777636fc
3 changed files with 129 additions and 7 deletions

View File

@@ -221,6 +221,37 @@ namespace C4IT_CustomerPanel.libs
{
return (SolidColorBrush)System.Windows.Application.Current.Resources["backgroundColor"];
}
private static Color BlendColor(Color source, Color target, double amount)
{
amount = Math.Max(0.0, Math.Min(1.0, amount));
return Color.FromArgb(
source.A,
(byte)Math.Round((source.R * (1.0 - amount)) + (target.R * amount)),
(byte)Math.Round((source.G * (1.0 - amount)) + (target.G * amount)),
(byte)Math.Round((source.B * (1.0 - amount)) + (target.B * amount)));
}
private static double GetRelativeLuminance(Color color)
{
return ((0.2126 * color.R) + (0.7152 * color.G) + (0.0722 * color.B)) / 255.0;
}
private static void ApplyBackgroundDerivedResources(Color baseColor)
{
bool isLightBackground = GetRelativeLuminance(baseColor) >= 0.55;
Color panelColor = BlendColor(baseColor, Colors.White, isLightBackground ? 0.06 : 0.08);
Color navColor = BlendColor(baseColor, Colors.Black, isLightBackground ? 0.06 : 0.08);
Color panelBorder = BlendColor(baseColor, isLightBackground ? Colors.Black : Colors.White, isLightBackground ? 0.16 : 0.22);
Color navBorder = BlendColor(baseColor, isLightBackground ? Colors.Black : Colors.White, isLightBackground ? 0.20 : 0.28);
Application.Current.Resources["backgroundColor"] = new SolidColorBrush(baseColor);
Application.Current.Resources["panelBackgroundColor"] = new SolidColorBrush(panelColor);
Application.Current.Resources["navigationRailColor"] = new SolidColorBrush(navColor);
Application.Current.Resources["panelBorderColor"] = new SolidColorBrush(panelBorder);
Application.Current.Resources["navigationRailBorderColor"] = new SolidColorBrush(navBorder);
}
public SolidColorBrush GetHeaderColor()
{
return (SolidColorBrush)System.Windows.Application.Current.Resources["headerColor"];
@@ -958,10 +989,15 @@ namespace C4IT_CustomerPanel.libs
{
try
{
System.Windows.Application.Current.Resources["activeButtonColor"] = new SolidColorBrush((Color)ConverterHelper.ColorConvertFromString(cpConfig._uiColors["activeButtonColor"]));
System.Windows.Application.Current.Resources["inactiveButtonColor"] = new SolidColorBrush((Color)ConverterHelper.ColorConvertFromString(cpConfig._uiColors["inactiveButtonColor"]));
System.Windows.Application.Current.Resources["backgroundColor"] = new SolidColorBrush((Color)ConverterHelper.ColorConvertFromString(cpConfig._uiColors["backgroundColor"]));
System.Windows.Application.Current.Resources["headerColor"] = new SolidColorBrush((Color)ConverterHelper.ColorConvertFromString(cpConfig._uiColors["headerColor"]));
Color activeColor = (Color)ConverterHelper.ColorConvertFromString(cpConfig._uiColors["activeButtonColor"]);
Color inactiveColor = (Color)ConverterHelper.ColorConvertFromString(cpConfig._uiColors["inactiveButtonColor"]);
Color backgroundColor = (Color)ConverterHelper.ColorConvertFromString(cpConfig._uiColors["backgroundColor"]);
Color headerColor = (Color)ConverterHelper.ColorConvertFromString(cpConfig._uiColors["headerColor"]);
System.Windows.Application.Current.Resources["activeButtonColor"] = new SolidColorBrush(activeColor);
System.Windows.Application.Current.Resources["inactiveButtonColor"] = new SolidColorBrush(inactiveColor);
System.Windows.Application.Current.Resources["headerColor"] = new SolidColorBrush(headerColor);
ApplyBackgroundDerivedResources(backgroundColor);
}
catch
{
@@ -969,6 +1005,16 @@ namespace C4IT_CustomerPanel.libs
cpConfig._uiColors["backgroundColor"] = Properties.Resources.backgroundColor;
cpConfig._uiColors["headerColor"] = Properties.Resources.headerColor;
cpConfig._uiColors["activeButtonColor"] = Properties.Resources.activeButtonColor;
Color fallbackActive = (Color)ConverterHelper.ColorConvertFromString(cpConfig._uiColors["activeButtonColor"]);
Color fallbackInactive = (Color)ConverterHelper.ColorConvertFromString(cpConfig._uiColors["inactiveButtonColor"]);
Color fallbackBackground = (Color)ConverterHelper.ColorConvertFromString(cpConfig._uiColors["backgroundColor"]);
Color fallbackHeader = (Color)ConverterHelper.ColorConvertFromString(cpConfig._uiColors["headerColor"]);
System.Windows.Application.Current.Resources["activeButtonColor"] = new SolidColorBrush(fallbackActive);
System.Windows.Application.Current.Resources["inactiveButtonColor"] = new SolidColorBrush(fallbackInactive);
System.Windows.Application.Current.Resources["headerColor"] = new SolidColorBrush(fallbackHeader);
ApplyBackgroundDerivedResources(fallbackBackground);
}
try