In This Article

UIColor Struct

Provides an enhanced representation of a System.Windows.Media.Color object that supports the RGB, HSB, and HLS color models, conversion between models, and numerous other color helper methods.

public struct UIColor

Properties

A

Gets or sets the alpha component value of this UIColor structure.

public byte A { get; set; }

Property Value

System.Byte:

The alpha component value of this UIColor structure.

Remarks

Valid values are in the range 0 to 255.

B

Gets or sets the RGB blue component value of this UIColor structure.

public byte B { get; set; }

Property Value

System.Byte:

The RGB blue component value of this UIColor structure.

Remarks

Valid values are in the range 0 to 255.

ExceedsW3CBrightnessThreshold

Gets whether the color exceeds the W3C threshold for brightness.

public bool ExceedsW3CBrightnessThreshold { get; }

Property Value

System.Boolean:

true if the color exceeds the W3C threshold for brightness; otherwise, false.

G

Gets or sets the RGB green component value of this UIColor structure.

public byte G { get; set; }

Property Value

System.Byte:

The RGB green component value of this UIColor structure.

Remarks

Valid values are in the range 0 to 255.

HlsHue

Gets or sets the HLS hue component value of this UIColor structure.

public double HlsHue { get; set; }

Property Value

System.Double:

The HLS hue component value of this UIColor structure.

Remarks

Valid values are in the range 0 to 360.

HlsLightness

Gets or sets the HLS lightness component value of this UIColor structure.

public double HlsLightness { get; set; }

Property Value

System.Double:

The HLS lightness component value of this UIColor structure.

Remarks

Valid values are in the range 0 to 1.

HlsSaturation

Gets or sets the HLS saturation component value of this UIColor structure.

public double HlsSaturation { get; set; }

Property Value

System.Double:

The HLS saturation component value of this UIColor structure.

Remarks

Valid values are in the range 0 to 1.

HsbBrightness

Gets or sets the HSB brightness component value of this UIColor structure.

public double HsbBrightness { get; set; }

Property Value

System.Double:

The HSB brightness component value of this UIColor structure.

Remarks

Valid values are in the range 0 to 1.

HsbHue

Gets or sets the HSB hue component value of this UIColor structure.

public double HsbHue { get; set; }

Property Value

System.Double:

The HSB hue component value of this UIColor structure.

Remarks

Valid values are in the range 0 to 360.

HsbSaturation

Gets or sets the HSB saturation component value of this UIColor structure.

public double HsbSaturation { get; set; }

Property Value

System.Double:

The HSB saturation component value of this UIColor structure.

Remarks

Valid values are in the range 0 to 1.

IsGrayscale

Gets whether the color is grayscale.

public bool IsGrayscale { get; }

Property Value

System.Boolean:

true if the color is grayscale; otherwise, false.

IsLight

Gets whether the color is a light color.

public bool IsLight { get; }

Property Value

System.Boolean:

true if the color is a light color; otherwise, false.

Luminance

Gets the luminance of the color.

public byte Luminance { get; }

Property Value

System.Byte:

The luminance of the color.

Remarks

Valid values are in the range 0 to 255.

R

Gets or sets the RGB red component value of this UIColor structure.

public byte R { get; set; }

Property Value

System.Byte:

The RGB red component value of this UIColor structure.

Remarks

Valid values are in the range 0 to 255.

W3CBrightness

Gets the brightness of the color, based on the W3C formula for calculating brightness.

public byte W3CBrightness { get; }

Property Value

System.Byte:

The brightness of the color, based on the W3C formula for calculating brightness.

Methods

AdaptToBackground(Double, Double, Double, Boolean)

Converts the color so that it renders clearly on the specified background color.

public void AdaptToBackground(double backColorHue, double backColorLightness, double backColorSaturation, bool isHighContrast)
Parameter Type Description
backColorHue System.Double

The background color hue.

backColorLightness System.Double

The background color lightness.

backColorSaturation System.Double

The background color saturation.

isHighContrast System.Boolean

Whether in a high-contrast theme.

AdaptToBackground(Color, Boolean)

Converts the color so that it renders clearly on the specified background color.

public void AdaptToBackground(Color backColor, bool isHighContrast)
Parameter Type Description
backColor System.Windows.Media.Color

The background color.

isHighContrast System.Boolean

Whether in a high-contrast theme.

Darken(Double)

Darkens the color by the specified amount.

public void Darken(double percentage)
Parameter Type Description
percentage System.Double

The percentage by which to darken the color. The value must be between 0 and 1.

Equals(Object)

Determines whether the specified Object is equal to the current Object.

public override bool Equals(object obj)
Parameter Type Description
obj System.Object

The Object to compare to the current Object.

Returns

System.Boolean:

true if the specified Object is equal to the current Object; otherwise, false.

Equals(Color)

Determines whether the specified Object is equal to the current Object.

public bool Equals(Color obj)
Parameter Type Description
obj System.Windows.Media.Color

The Object to compare to the current Object.

Returns

System.Boolean:

true if the specified Object is equal to the current Object; otherwise, false.

FromAhls(Byte, Double, Double, Double)

Creates a UIColor structure from an alpha value and the specified HLS color values (hue, lightness, and saturation).

public static UIColor FromAhls(byte alpha, double hue, double lightness, double saturation)
Parameter Type Description
alpha System.Byte

The alpha component value for the new UIColor structure. Valid values are 0 through 255.

hue System.Double

The hue component value for the new UIColor structure. Valid values are 0 through 360.

lightness System.Double

The lightness component value for the new UIColor structure. Valid values are 0 through 1.

saturation System.Double

The saturation component value for the new UIColor structure. Valid values are 0 through 1.

Returns

UIColor:

The UIColor structure that this method creates.

Remarks

Although this method allows a 32-bit value to be passed for each color component, the value of each component is limited to the values indicated above.

FromAhsb(Byte, Double, Double, Double)

Creates a UIColor structure from an alpha value and the specified HSB color values (hue, saturation, and brightness).

public static UIColor FromAhsb(byte alpha, double hue, double saturation, double brightness)
Parameter Type Description
alpha System.Byte

The alpha component value for the new UIColor structure. Valid values are 0 through 255.

hue System.Double

The hue component value for the new UIColor structure. Valid values are 0 through 360.

saturation System.Double

The saturation component value for the new UIColor structure. Valid values are 0 through 1.

brightness System.Double

The brightness component value for the new UIColor structure. Valid values are 0 through 1.

Returns

UIColor:

The UIColor structure that this method creates.

Remarks

Although this method allows a 32-bit value to be passed for each color component, the value of each component is limited to the values indicated above.

FromArgb(Byte, Byte, Byte, Byte)

Creates a UIColor structure from an alpha value and the specified RGB color values (red, green, and blue).

public static UIColor FromArgb(byte alpha, byte red, byte green, byte blue)
Parameter Type Description
alpha System.Byte

The alpha component value for the new UIColor structure. Valid values are 0 through 255.

red System.Byte

The red component value for the new UIColor structure. Valid values are 0 through 255.

green System.Byte

The red component value for the new UIColor structure. Valid values are 0 through 255.

blue System.Byte

The red component value for the new UIColor structure. Valid values are 0 through 255.

Returns

UIColor:

The UIColor structure that this method creates.

Remarks

Although this method allows a 32-bit value to be passed for each color component, the value of each component is limited to 8 bits.

FromColor(Color)

Creates a UIColor structure from the specified System.Windows.Media.Color.

public static UIColor FromColor(Color color)
Parameter Type Description
color System.Windows.Media.Color

The System.Windows.Media.Color to use as a template.

Returns

UIColor:

The UIColor structure that this method creates.

FromColorComplement(Color)

Creates a UIColor structure from the complement of the specified System.Windows.Media.Color.

public static UIColor FromColorComplement(Color color)
Parameter Type Description
color System.Windows.Media.Color

The System.Windows.Media.Color to complement and use as a template.

Returns

UIColor:

The UIColor structure that this method creates.

FromColorComplement(Color, Byte)

Creates a UIColor structure from the complement of the specified System.Windows.Media.Color.

public static UIColor FromColorComplement(Color color, byte alpha)
Parameter Type Description
color System.Windows.Media.Color

The System.Windows.Media.Color to complement and use as a template.

alpha System.Byte

The alpha channel value to use for the new color.

Returns

UIColor:

The UIColor structure that this method creates.

FromHls(Double, Double, Double)

Creates a UIColor structure from the specified HLS color values (hue, lightness, and saturation).

public static UIColor FromHls(double hue, double lightness, double saturation)
Parameter Type Description
hue System.Double

The hue component value for the new UIColor structure. Valid values are 0 through 360.

lightness System.Double

The lightness component value for the new UIColor structure. Valid values are 0 through 1.

saturation System.Double

The saturation component value for the new UIColor structure. Valid values are 0 through 1.

Returns

UIColor:

The UIColor structure that this method creates.

Remarks

The alpha value is implicitly 255 (fully opaque). Although this method allows a 32-bit value to be passed for each color component, the value of each component is limited to the values indicated above.

FromHsb(Double, Double, Double)

Creates a UIColor structure from the specified HSB color values (hue, saturation, and brightness).

public static UIColor FromHsb(double hue, double saturation, double brightness)
Parameter Type Description
hue System.Double

The hue component value for the new UIColor structure. Valid values are 0 through 360.

saturation System.Double

The saturation component value for the new UIColor structure. Valid values are 0 through 1.

brightness System.Double

The brightness component value for the new UIColor structure. Valid values are 0 through 1.

Returns

UIColor:

The UIColor structure that this method creates.

Remarks

The alpha value is implicitly 255 (fully opaque). Although this method allows a 32-bit value to be passed for each color component, the value of each component is limited to the values indicated above.

FromMix(Color, Color, Double)

Creates a UIColor structure that is the specified percentage between the value of two System.Windows.Media.Color objects.

public static UIColor FromMix(Color color1, Color color2, double percentage)
Parameter Type Description
color1 System.Windows.Media.Color

The first System.Windows.Media.Color to examine.

color2 System.Windows.Media.Color

The second System.Windows.Media.Color to examine.

percentage System.Double

The percentage from the first color to the second in which to return a color.

Returns

UIColor:

The UIColor structure that this method creates.

FromName(String)

Creates a UIColor structure from the specified name of a pre-defined color.

public static UIColor FromName(string name)
Parameter Type Description
name System.String

A string that is the name of a pre-defined color. Valid names are the same as the names of the elements of the known color names.

Returns

UIColor:

The UIColor structure that this method creates.

FromRgb(Byte, Byte, Byte)

Creates a UIColor structure from the specified RGB color values (red, green, and blue).

public static UIColor FromRgb(byte red, byte green, byte blue)
Parameter Type Description
red System.Byte

The red component value for the new UIColor structure. Valid values are 0 through 255.

green System.Byte

The red component value for the new UIColor structure. Valid values are 0 through 255.

blue System.Byte

The red component value for the new UIColor structure. Valid values are 0 through 255.

Returns

UIColor:

The UIColor structure that this method creates.

Remarks

The alpha value is implicitly 255 (fully opaque). Although this method allows a 32-bit value to be passed for each color component, the value of each component is limited to 8 bits.

FromWebColor(String)

Creates a UIColor structure from the specified web color.

public static UIColor FromWebColor(string text)
Parameter Type Description
text System.String

A string containing the color.

Returns

UIColor:

The UIColor structure that this method creates.

Remarks

This method can process HTML color specifications (e.g. #FF00FF) and known color names.

GetContrastRatioWith(UIColor)

Returns the contrast ratio of this color with the specified color.

public double GetContrastRatioWith(UIColor contrastingColor)
Parameter Type Description
contrastingColor UIColor

The contrasting color to compare.

Returns

System.Double:

The contrast ratio of this color with the specified color.

GetHashCode()

Returns a hash code for this object.

public override int GetHashCode()

Returns

System.Int32:

An integer value that specifies a hash value for this object.

GetStandardCustomColors()

Returns a System.Windows.Media.Color array containing all of the standard custom values.

public static Color[] GetStandardCustomColors()

Returns

System.Windows.Media.Color[]:

An array of System.Windows.Media.Color objects.

GetSystemColors()

Returns a System.Windows.Media.Color array containing all of the SystemColors values.

public static Color[] GetSystemColors()

Returns

System.Windows.Media.Color[]:

An array of System.Windows.Media.Color objects.

GetTintedColor(Color, Color)

Returns the custom tinted color for the specified base color.

public static Color GetTintedColor(Color baseColor, Color tintColor)
Parameter Type Description
baseColor System.Windows.Media.Color

The base System.Windows.Media.Color to examine.

tintColor System.Windows.Media.Color

The tint System.Windows.Media.Color.

Returns

System.Windows.Media.Color:

The custom tinted color for the specified base color.

GetWebColors()

Returns an array containing all of the web color values.

public static Color[] GetWebColors()

Returns

System.Windows.Media.Color[]:

An array of System.Windows.Media.Color objects.

Grayscale()

Converts the color to grayscale.

public void Grayscale()

Lighten(Double)

Lightens the color by the specified amount.

public void Lighten(double percentage)
Parameter Type Description
percentage System.Double

The percentage by which to lighten the color. The value must be between 0 and 1.

Tint(Color)

Tints this color towards the specified tint System.Windows.Media.Color.

public void Tint(Color tintColor)
Parameter Type Description
tintColor System.Windows.Media.Color

The tint System.Windows.Media.Color.

ToColor()

Gets the System.Windows.Media.Color value of this UIColor structure.

public Color ToColor()

Returns

System.Windows.Media.Color:

The System.Windows.Media.Color that is encapsulated by this UIColor.

ToString()

Returns a String that represents the current Object.

public override string ToString()

Returns

System.String:

A String that represents the current Object.

ToWebColor()

Converts the UIColor to a web color.

public string ToWebColor()

Returns

System.String:

The color in HTML color specification format (e.g. #FF00FF).

ToWebColor(Boolean)

Converts the UIColor to a web color.

public string ToWebColor(bool includeAlpha)
Parameter Type Description
includeAlpha System.Boolean

Whether to include the alpha specification.

Returns

System.String:

The color in HTML color specification format (e.g. #FFFF00FF).

TryFromName(String, out UIColor)

Tries to create a UIColor structure from the specified name of a pre-defined color.

public static bool TryFromName(string name, out UIColor color)
Parameter Type Description
name System.String

A string that is the name of a pre-defined color. Valid names are the same as the names of the elements of the known color names.

color UIColor

Returns the UIColor structure that this method creates.

Returns

System.Boolean:

true if the name was recognized successfully; otherwise, false.

TryFromWebColor(String, out UIColor)

Tries to create a UIColor structure from the specified web color.

public static bool TryFromWebColor(string text, out UIColor color)
Parameter Type Description
text System.String

A string containing the color.

color UIColor

Returns the UIColor structure that this method creates.

Returns

System.Boolean:

true if the text was parsed successfully; otherwise, false.

Remarks

This method can process HTML color specifications (e.g. #FF00FF) and known color names.

Operators

Equality(UIColor, UIColor)

Compares two color objects for equality.

public static bool operator ==(UIColor left, UIColor right)
Parameter Type Description
left UIColor

A UIColor to compare.

right UIColor

A UIColor to compare.

Returns

System.Boolean:

true if the color values of left and right are equal; otherwise, false.

Inequality(UIColor, UIColor)

Compares two color objects for inequality.

public static bool operator !=(UIColor left, UIColor right)
Parameter Type Description
left UIColor

A UIColor to compare.

right UIColor

A UIColor to compare.

Returns

System.Boolean:

true if the color values of left and right are unequal; otherwise, false.

Inherited Members

  • System.Object.Equals(System.Object, System.Object)
  • System.Object.ReferenceEquals(System.Object, System.Object)
  • System.Object.GetType()