UIColor Struct
An enhanced representation of the Avalonia.Media.Color structure with many additional features.
public struct UIColor : IEquatable<UIColor>
- Implements:
- IEquatable<UIColor>
Properties
Alpha
The alpha component of the color, which is a percentage value in the range 0.0
..1.0
.
public double Alpha { readonly get; set; }
Property Value
- double:
The alpha component of the color.
Remarks
0.0
is fully transparent and 1.0
is fully opaque.
HslHue
The HSL hue component of the color, which is a color wheel degree value in the range 0
..360
.
public double HslHue { readonly get; set; }
Property Value
- double:
The HSL hue component of the color.
Remarks
0
/360
degrees is red.
60
degrees is yellow.
120
degrees is green.
180
degrees is cyan.
240
degrees is blue.
300
degrees is magenta.
HslLightness
The HSL lightness component of the color, which is a percentage value in the range 0.0
..1.0
.
public double HslLightness { readonly get; set; }
Property Value
- double:
The HSL lightness component of the color.
Remarks
0.0
is full black and 1.0
is full white.
HslSaturation
The HSL saturation component of the color, which is a percentage value in the range 0.0
..1.0
.
public double HslSaturation { readonly get; set; }
Property Value
- double:
The HSL saturation component of the color.
Remarks
0.0
is only grayscale (no color hue applied) and 1.0
is full color hue applied.
HsvHue
The HSV hue component of the color, which is a color wheel degree value in the range 0
..360
.
public double HsvHue { readonly get; set; }
Property Value
- double:
The HSV hue component of the color.
Remarks
0
/360
degrees is red.
60
degrees is yellow.
120
degrees is green.
180
degrees is cyan.
240
degrees is blue.
300
degrees is magenta.
HsvSaturation
The HSV saturation component of the color, which is a percentage value in the range 0.0
..1.0
.
public double HsvSaturation { readonly get; set; }
Property Value
- double:
The HSV saturation component of the color.
Remarks
0.0
is only grayscale (no color hue applied) and 1.0
is full color hue applied.
HsvValue
The HSV value (brightness) component of the color, which is a percentage value in the range 0.0
..1.0
.
public double HsvValue { readonly get; set; }
Property Value
- double:
The HSV value (brightness) component of the color.
Remarks
0.0
is full black (no light applied) and 1.0
is maximum brightness that allows the full color to show.
IsDark
Whether the color is a dark color.
public readonly bool IsDark { get; }
Property Value
- bool:
true
if the color is a dark color; otherwise,false
.
See Also
IsLight
Whether the color is a light color.
public readonly bool IsLight { get; }
Property Value
- bool:
true
if the color is a light color; otherwise,false
.
See Also
OklabAChromaticity
The OKLAB A chromaticity component of the color, which is a value in the range -0.4
..0.4
.
public double OklabAChromaticity { readonly get; set; }
Property Value
- double:
The OKLAB A chromaticity component of the color.
OklabBChromaticity
The OKLAB B chromaticity component of the color, which is a value in the range -0.4
..0.4
.
public double OklabBChromaticity { readonly get; set; }
Property Value
- double:
The OKLAB B chromaticity component of the color.
OklabLightness
The OKLAB lightness component of the color, which is a percentage value in the range 0.0
..1.0
.
public double OklabLightness { readonly get; set; }
Property Value
- double:
The OKLAB lightness component of the color.
Remarks
0.0
is full black and 1.0
is full white.
OklchChroma
The OKLCH chroma (saturation) component of the color, which is a value in the range 0.0
..0.4
.
public double OklchChroma { readonly get; set; }
Property Value
- double:
The OKLCH chroma (saturation) component of the color.
OklchHue
The OKLCH hue component of the color, which is a color wheel degree value in the range 0
..360
.
public double OklchHue { readonly get; set; }
Property Value
- double:
The OKLCH hue component of the color.
Remarks
Hue angles are slightly different than in other color models.
20
degrees is red.
90
degrees is yellow.
140
degrees is green.
220
degrees is blue.
320
degrees is purple.
OklchLightness
The OKLCH lightness component of the color, which is a percentage value in the range 0.0
..1.0
.
public double OklchLightness { readonly get; set; }
Property Value
- double:
The OKLCH lightness component of the color.
Remarks
0.0
is full black and 1.0
is full white.
RgbAlpha
The RGB alpha component of the color, which is a byte value in the range 0
..255
.
public byte RgbAlpha { readonly get; set; }
Property Value
- byte:
The RGB alpha component of the color.
Remarks
0
is fully transparent and 255
is fully opaque.
RgbBlue
The RGB blue component of the color, which is a byte value in the range 0
..255
.
public byte RgbBlue { readonly get; set; }
Property Value
- byte:
The RGB blue component of the color.
Remarks
0
is no blue component and 255
is maximum blue component.
RgbGreen
The RGB green component of the color, which is a byte value in the range 0
..255
.
public byte RgbGreen { readonly get; set; }
Property Value
- byte:
The RGB green component of the color.
Remarks
0
is no green component and 255
is maximum green component.
RgbRed
The RGB red component of the color, which is a byte value in the range 0
..255
.
public byte RgbRed { readonly get; set; }
Property Value
- byte:
The RGB red component of the color.
Remarks
0
is no red component and 255
is maximum red component.
Methods
Equals(UIColor)
Indicates whether the current object is equal to another object of the same type.
public readonly bool Equals(UIColor other)
Parameter | Type | Description |
---|---|---|
other | UIColor | An object to compare with this object. |
Returns
- bool:
true
if the current object is equal to theother
parameter; otherwise,false
.
Equals(object?)
Indicates whether this instance and a specified object are equal.
public override readonly bool Equals(object? obj)
Parameter | Type | Description |
---|---|---|
obj | object | The object to compare with the current instance. |
Returns
- bool:
true
ifobj
and this instance are the same type and represent the same value; otherwise,false
.
FromHsl(HslColor)
Creates a UIColor instance from the specified Avalonia.Media.HslColor that represents a color in the HSL (hue, saturation, and lightness) color model.
public static UIColor FromHsl(HslColor color)
Parameter | Type | Description |
---|---|---|
color | HslColor | The Avalonia.Media.HslColor to use as a template. |
Returns
FromHsl(double, double, double, double)
Creates a UIColor instance from the specified HSL (hue, saturation, and lightness) and optional alpha components.
public static UIColor FromHsl(double hue, double saturation, double lightness, double alpha = 1)
Parameter | Type | Description |
---|---|---|
hue | double | The hue component, which is a color wheel degree value in the range |
saturation | double | The saturation component, which is a percentage value in the range |
lightness | double | The lightness component, which is a percentage value in the range |
alpha | double | The optional alpha component, which is a percentage value in the range |
Returns
FromHsv(HsvColor)
Creates a UIColor instance from the specified Avalonia.Media.HsvColor that represents a color in the HSV (hue, saturation, and value) color model.
public static UIColor FromHsv(HsvColor color)
Parameter | Type | Description |
---|---|---|
color | HsvColor | The Avalonia.Media.HsvColor to use as a template. |
Returns
FromHsv(double, double, double, double)
Creates a UIColor instance from the specified HSV (hue, saturation, and value) and optional alpha components.
public static UIColor FromHsv(double hue, double saturation, double value, double alpha = 1)
Parameter | Type | Description |
---|---|---|
hue | double | The hue component, which is a color wheel degree value in the range |
saturation | double | The saturation component, which is a percentage value in the range |
value | double | The value (brightness) component, which is a percentage value in the range |
alpha | double | The optional alpha component, which is a percentage value in the range |
Returns
FromMix(UIColor, UIColor, double, ColorInterpolationMode)
Creates a UIColor instance that is a mix of two colors.
public static UIColor FromMix(UIColor color1, UIColor color2, double ratio = 0.5, ColorInterpolationMode interpolationMode = ColorInterpolationMode.LinearRgb)
Parameter | Type | Description |
---|---|---|
color1 | UIColor | The first Avalonia.Media.Color to examine. |
color2 | UIColor | The second Avalonia.Media.Color to examine. |
ratio | double | (Optional) A ratio value in the range |
interpolationMode | ColorInterpolationMode | (Optional) The interpolation mode to use, which defaults to |
Returns
FromOklab(double, double, double, double)
Creates a UIColor instance from the specified OKLAB (lightness, A, and B) and optional alpha components.
public static UIColor FromOklab(double lightness, double a, double b, double alpha = 1)
Parameter | Type | Description |
---|---|---|
lightness | double | The OKLAB lightness component, which is a percentage value in the range |
a | double | The OKLAB A chromaticity component, which is a value in the range |
b | double | The OKLAB B chromaticity component, which is a value in the range |
alpha | double | The optional alpha component, which is a percentage value in the range |
Returns
FromOklch(double, double, double, double)
Creates a UIColor instance from the specified OKLCH (lightness, chroma, and hue) and optional alpha components.
public static UIColor FromOklch(double lightness, double chroma, double hue, double alpha = 1)
Parameter | Type | Description |
---|---|---|
lightness | double | The OKLCH lightness component, which is a percentage value in the range |
chroma | double | The OKLCH chroma (saturation) component, which is a value in the range |
hue | double | The OKLCH hue component, which is a color wheel degree value in the range |
alpha | double | The optional alpha component, which is a percentage value in the range |
Returns
FromRgb(Color)
Creates a UIColor instance from the specified Avalonia.Media.Color that represents a color in the RGB (red, green, and blue) color model.
public static UIColor FromRgb(Color color)
Parameter | Type | Description |
---|---|---|
color | Color | The Avalonia.Media.Color to use as a template. |
Returns
FromRgb(byte, byte, byte, byte)
Creates a UIColor instance from the specified RGB (red, green, and blue) and optional alpha components.
public static UIColor FromRgb(byte red, byte green, byte blue, byte alpha = 255)
Parameter | Type | Description |
---|---|---|
red | byte | The red component, which is a byte value in the range |
green | byte | The green component, which is a byte value in the range |
blue | byte | The blue component, which is a byte value in the range |
alpha | byte | The optional alpha component, which is a byte value in the range |
Returns
GetHashCode()
Returns the hash code for this instance.
public override readonly int GetHashCode()
Returns
- int:
A 32-bit signed integer that is the hash code for this instance.
GetHueFromString(string)
Returns a hue component, which is a degree value in the range 0
..360
, based on the specified text.
public static double GetHueFromString(string text)
Parameter | Type | Description |
---|---|---|
text | string | The text string to examine. |
Returns
- double:
The hue component value.
Parse(string)
Parses the specified color string into a UIColor, throwing an exception on failure.
public static UIColor Parse(string colorString)
Parameter | Type | Description |
---|---|---|
colorString | string | The color string to examine. |
Returns
- UIColor:
The parsed color.
ToChromaticAdaptation(UIColor, bool)
Uses chromatic adaptation to create a new color that renders clearly on the specified background color.
public readonly UIColor ToChromaticAdaptation(UIColor backColor, bool isHighContrast = false)
Parameter | Type | Description |
---|---|---|
backColor | UIColor | The background color. |
isHighContrast | bool | The optional flag for whether in a high-contrast theme. The default value is |
Returns
Remarks
Chromatic adaptation is commonly used to adapt a color that was intended for use with light backgrounds to render clearly on dark backgrounds.
ToGrayscale()
Creates a grayscale transformation of the specified color.
public readonly UIColor ToGrayscale()
Returns
ToHexString(bool?)
Converts this color value to an RGB hexadecimal string (e.g., #ff00ff
, #80ff00ff
).
public readonly string ToHexString(bool? includeAlpha = null)
Parameter | Type | Description |
---|---|---|
includeAlpha | bool? | Whether to include the alpha component specification. A |
Returns
- string:
The RGB hexadecimal string representation of the color.
ToHsl()
Converts this color value to an Avalonia.Media.HslColor instance that represents a color in the HSL (hue, saturation, and lightness) color model.
public readonly HslColor ToHsl()
Returns
- HslColor:
The Avalonia.Media.HslColor that was created.
ToHsv()
Converts this color value to an Avalonia.Media.HsvColor instance that represents a color in the HSV (hue, saturation, and value) color model.
public readonly HsvColor ToHsv()
Returns
- HsvColor:
The Avalonia.Media.HsvColor that was created.
ToRgb()
Converts this color value to a Avalonia.Media.Color instance that represents a color in the RGB (red, green, and blue) color model.
public readonly Color ToRgb()
Returns
- Color:
The Avalonia.Media.Color that was created.
ToString()
Returns the string representation of this object.
public override readonly string ToString()
Returns
- string:
The string representation of this object.
TryParse(string, out UIColor)
Attempts to parse the specified color string into a UIColor.
public static bool TryParse(string colorString, out UIColor color)
Parameter | Type | Description |
---|---|---|
colorString | string | The color string to examine. |
color | UIColor | Returns the parsed color. |
Returns
- bool:
true
if the color string was parsed successfully; otherwise,false
.
Operators
operator ==(UIColor, UIColor)
Compares two objects for equality.
public static bool operator ==(UIColor left, UIColor right)
Parameter | Type | Description |
---|---|---|
left | UIColor | The first object to compare. |
right | UIColor | The second object to compare. |
Returns
- bool:
true
if the two objects are equal; otherwise,false
.
implicit operator Color(UIColor)
Implicitly converts the specified UIColor into a Avalonia.Media.Color instance.
public static implicit operator Color(UIColor color)
Parameter | Type | Description |
---|---|---|
color | UIColor | the UIColor to examine. |
Returns
- Color
implicit operator HslColor(UIColor)
Implicitly converts the specified UIColor into a Avalonia.Media.HslColor instance.
public static implicit operator HslColor(UIColor color)
Parameter | Type | Description |
---|---|---|
color | UIColor | the UIColor to examine. |
Returns
- HslColor
implicit operator HsvColor(UIColor)
Implicitly converts the specified UIColor into a Avalonia.Media.HsvColor instance.
public static implicit operator HsvColor(UIColor color)
Parameter | Type | Description |
---|---|---|
color | UIColor | the UIColor to examine. |
Returns
- HsvColor
implicit operator UIColor(Color)
Implicitly converts the specified Avalonia.Media.Color into a UIColor instance.
public static implicit operator UIColor(Color color)
Parameter | Type | Description |
---|---|---|
color | Color | the Avalonia.Media.Color to examine. |
Returns
implicit operator UIColor(HslColor)
Implicitly converts the specified Avalonia.Media.HslColor into a UIColor instance.
public static implicit operator UIColor(HslColor color)
Parameter | Type | Description |
---|---|---|
color | HslColor | the Avalonia.Media.HslColor to examine. |
Returns
implicit operator UIColor(HsvColor)
Implicitly converts the specified Avalonia.Media.HsvColor into a UIColor instance.
public static implicit operator UIColor(HsvColor color)
Parameter | Type | Description |
---|---|---|
color | HsvColor | the Avalonia.Media.HsvColor to examine. |
Returns
operator !=(UIColor, UIColor)
Compares two objects for inequality.
public static bool operator !=(UIColor left, UIColor right)
Parameter | Type | Description |
---|---|---|
left | UIColor | The first object to compare. |
right | UIColor | The second object to compare. |
Returns
- bool:
true
if the two objects are not equal; otherwise,false
.