2b0797f50f
Linked colors to options menu Options extension Aussehen aufgebohrt: - erlaubt text von status zu ändern, - bessere beschriftung von Farben desing änderung und bedienung - heute status felder anklickbar, - Farbpalette verdunkelt und kontrast reduziert - Kalender Tage anklickbar gemacht - Optionen überarbeitet
48 lines
1.1 KiB
C#
48 lines
1.1 KiB
C#
using System.Globalization;
|
|
using Microsoft.Maui.Controls;
|
|
using Microsoft.Maui.Graphics;
|
|
|
|
namespace cfs_tracker.Converters;
|
|
|
|
public class HexToColorConverter : IValueConverter
|
|
{
|
|
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
|
{
|
|
if (value is string hex && !string.IsNullOrWhiteSpace(hex))
|
|
{
|
|
try
|
|
{
|
|
return Color.FromArgb(hex);
|
|
}
|
|
catch
|
|
{
|
|
}
|
|
}
|
|
|
|
return Color.FromArgb("#203041");
|
|
}
|
|
|
|
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
|
{
|
|
if (value is Color color)
|
|
return color.ToArgbHex();
|
|
|
|
return "#203041";
|
|
}
|
|
}
|
|
|
|
public static class ColorExtensions
|
|
{
|
|
public static string ToArgbHex(this Color color)
|
|
{
|
|
byte a = (byte)(color.Alpha * 255);
|
|
byte r = (byte)(color.Red * 255);
|
|
byte g = (byte)(color.Green * 255);
|
|
byte b = (byte)(color.Blue * 255);
|
|
|
|
if (a < 255)
|
|
return $"#{a:X2}{r:X2}{g:X2}{b:X2}";
|
|
|
|
return $"#{r:X2}{g:X2}{b:X2}";
|
|
}
|
|
} |