In This Article

Media

The ActiproSoftware.UI.Avalonia.Media namespace defines a UIColor structure for working with colors and an extension method to easily convert Avalonia.Media.Color to a UIColor.

UIColor Structure

The UIColor structure provides an enhanced representation of a color that supports the RGB, HSL, HSV, OKLAB, and OKLCH color models, conversion between models, and numerous other helper methods. Static methods on the structure are used to create instances of the structure based on the supported models.

These instance members are found in the structure:

Member Description
Alpha Property The alpha component of the color, which is a percentage value in the range 0.0 to 1.0.
HslHue Property The HSL hue component of the color, which is a color wheel degree value in the range 0 to 360.
HslLightness Property The HSL lightness component of the color, which is a percentage value in the range 0.0 to 1.0.
HslSaturation Property The HSL saturation component of the color, which is a percentage value in the range 0.0 to 1.0.
HsvHue Property The HSV hue component of the color, which is a percentage value in the range 0.0 to 1.0.
HsvSaturation Property The HSV saturation component of the color, which is a percentage value in the range 0.0 to 1.0.
HsvValue Property The HSV value (brightness) component of the color, which is a percentage value in the range 0.0 to 1.0.
IsDark Property Gets whether the color is a dark color.
IsLight Property Gets whether the color is a light color.
OklabAChromaticity Property The OKLAB A chromaticity component of the color, which is a value in the range -0.4..0.4.
OklabBChromaticity Property The OKLAB B chromaticity component of the color, which is a value in the range -0.4..0.4.
OklabLightness Property The OKLAB lightness component of the color, which is a percentage value in the range 0.0 to 1.0.
OklchChroma Property The OKLCH chroma (saturation) component of the color, which is a value in the range 0.0..0.4.
OklchHue Property The OKLCH hue component of the color, which is a color wheel degree value in the range 0..360.
OklchLightness Property The OKLCH lightness component of the color, which is a percentage value in the range 0.0 to 1.0.
RbgAlpha Property The RGB alpha component of the color, which is a byte value in the range 0 to 255.
RbgBlue Property The RGB blue component of the color, which is a byte value in the range 0 to 255.
RbgGreen Property The RGB green component of the color, which is a byte value in the range 0 to 255.
RbgRed Property The RGB red component of the color, which is a byte value in the range 0 to 255.
ToChromaticAdaptation Method Uses chromatic adaptation to create a new UIColor that renders clearly on the specified background color. Chromatic adaptation is commonly used to adapt a color that was intended for use with light backgrounds to render properly on dark backgrounds.
ToGrayscale Method Creates a new UIColor that is a grayscale transformation of the specified color.
ToHexString Method Converts the color value to an RGB hexadecimal string (e.g., "#ff00ff", "#80ff00ff").
ToHsl Method Converts the color value to an HslColor instance that represents the color in the HSL (hue, saturation, and lightness) color model.
ToHsv Method Converts the color value to an HsvColor instance that represents the color in the HSV (hue, saturation, and value) color model.
ToRgb Method Converts the color value to a Color instance that represents the color in the RGB (red, green, and blue) color model.
Warning

The Alpha property is a percentage of opacity from 0.0 to 1.0. Be careful to use the RgbAlpha property (which is a byte value from 0 to 255) when working with the RGB color model.

These static members are found in the structure:

Member Description
FromHsl Method Creates a UIColor instance from the specified HSL (hue, saturation, and lightness) and optional alpha components, or HslColor instance.
FromHsv Method Creates a UIColor instance from the specified HSV (hue, saturation, and value) and optional alpha components, or HsvColor instance.
FromMix Method Creates a UIColor instance that is the specified percentage between the value of two Color objects.
FromOklab Method Creates a UIColor instance from the specified OKLAB (lightness, A, and B) and optional alpha components.
FromOklch Method Creates a UIColor instance from the specified OKLCH (lightness, chroma, and hue) and optional alpha components.
FromRgb Method Creates a UIColor instance from the specified RGB (red, green, and blue) and optional alpha components, or Color instance.
Parse Method Creates a UIColor instance from the specified color name, RGB hexadecimal string, or any other color string supported by Color.Parse.
TryParse Method Tries to creates a UIColor instance from the specified color name, RGB hexadecimal string, or any other color string supported by Color.Parse.
Tip

UIColor defines several implicit cast overloads to easily convert to/from UIColor and the Avalonia types for Color, HslColor, and HsvColor.

Color Extensions

The following extension methods to Avalonia.Media.Color are defined on ColorExtensions:

Member Description
ToUIColor Method Creates a new UIColor initialized from the Color for easily accessing the additional capabilities of UIColor.
Important

The ActiproSoftware.UI.Avalonia.Media namespace must be imported with a using statement to access the extensions.