You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using the Microsoft.Toolkit.Uwp.UI.Controls ColorPicker in a UWP application, or using the ColorPicker in the WinUI 3 Gallery, the result of the hexadecimal input value is wrong when moving the alpha slider. The change to alpha updates the first two characters in the hexadecimal string, when instead it should update the last two characters.
For example, if you paste #6155FF80 in the hex input and move the alpha slider in any direction, the result is #806155FF, where the Alpha is transposed with the Blue.
// This ordinary hexadecimal to Argb Color conversion will not work with ColorPicker.
public static Windows.UI.Color HexToColorWithAlpha(string hex)
{
if (hex.StartsWith("#"))
hex = hex.Substring(1); // Remove '#' if present
byte a = 255; // Default alpha value (255 for fully opaque)
byte r = byte.Parse(hex.Substring(0, 2), System.Globalization.NumberStyles.HexNumber);
byte g = byte.Parse(hex.Substring(2, 2), System.Globalization.NumberStyles.HexNumber);
byte b = byte.Parse(hex.Substring(4, 2), System.Globalization.NumberStyles.HexNumber);
if (hex.Length == 8) // If alpha value is included
a = byte.Parse(hex.Substring(6, 2), System.Globalization.NumberStyles.HexNumber);
return Windows.UI.Color.FromArgb(a, r, g, b);
}
// ColorPicker workaround hexadecimal to Argb Color conversion
public static Windows.UI.Color HexToColorWithAlpha(string hex)
{
if (hex.StartsWith("#"))
hex = hex.Substring(1); // Remove '#' if present
byte a = byte.Parse(hex.Substring(0, 2), System.Globalization.NumberStyles.HexNumber);
byte r = byte.Parse(hex.Substring(2, 2), System.Globalization.NumberStyles.HexNumber);
byte g = byte.Parse(hex.Substring(4, 2), System.Globalization.NumberStyles.HexNumber);
byte b = byte.Parse(hex.Substring(6, 2), System.Globalization.NumberStyles.HexNumber);
return Windows.UI.Color.FromArgb(a, r, g, b);
}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Given a hexadecimal color with alpha, "#6155FF80", the last two characters "80" represent the alpha channel.
When using the Microsoft.Toolkit.Uwp.UI.Controls ColorPicker in a UWP application, or using the ColorPicker in the WinUI 3 Gallery, the result of the hexadecimal input value is wrong when moving the alpha slider. The change to alpha updates the first two characters in the hexadecimal string, when instead it should update the last two characters.
For example, if you paste #6155FF80 in the hex input and move the alpha slider in any direction, the result is #806155FF, where the Alpha is transposed with the Blue.
According to W3C, the alpha characters should appear at the end of the hexadecimal value.
https://www.w3.org/wiki/CSS/Properties/color/RGBA
Beta Was this translation helpful? Give feedback.
All reactions