Share via


Color Struct

Definition

Class that represents a color and exposes it as RGBA and HSL values.

[System.Diagnostics.DebuggerDisplay("R={R}, G={G}, B={B}, A={A}, Hue={Hue}, Saturation={Saturation}, Luminosity={Luminosity}")]
[Xamarin.Forms.TypeConverter(typeof(Xamarin.Forms.ColorTypeConverter))]
public struct Color
type Color = struct
Inheritance
System.ValueType
Color
Attributes
System.Diagnostics.DebuggerDisplayAttribute TypeConverterAttribute

Remarks

This type is immutable. Colors can be expressed in the RGB or HSL modes. While the Color(Double, Double, Double) constructor takes R, G, B, and A values, the Color class also calculates and makes available HSL data for the color.

In XAML, application developers can specify any property that is of type Color, for example, TextColor either as a XAML attribute or as a nested tag. The following code example shows how to specify the text color for a label by using an attribute:

<Label VerticalOptions="CenterAndExpand" HorizontalOptions="CenterAndExpand" TextColor="Green">
<Label.Text>Hello, World!</Label.Text>
</Label>

The example below shows how to specify the text color for a label by using a nested tag:

<Label VerticalOptions="CenterAndExpand" HorizontalOptions="CenterAndExpand">
<Label.Text>Hello, World!</Label.Text>
<Label.TextColor>Color.Blue</Label.TextColor>
</Label>

Application developers can specify colors in XAML either as a hexadecimal number or as a valid color name.

When specifying a color with a hexadecimal number, app developers can use 3, 4, or 6 digits. If the developer specifies 3 digits, they are interpreted as RGB doublet data for a fully opaque color. For example, "#123" specifies the color that is represented by "#FF112233". If the developer provides a 4-digit hexadecimal number, then the data are interpreted as above, except that the first digit specifies the alpha channel. For example, "#1234" specifies the color that is represented by "#11223344". Finally, if the developer provides a 6 digit hexadecimal number, the data are interpreted as a fully opaque color with those RGB values. For example, "#112233" specifies the color that is represented by "#FF112233".

When specifying a color with a string, app developers can use color name in isolation, or prefix it with "Color.". For example, both Purple and Color.Purple are valid ways to specify the color purple.

Constructors

Color(Double)

Initialize a new gray color.

Color(Double, Double, Double)

Initializes a new RGB color.

Color(Double, Double, Double, Double)

Initializes a new RGB color with an alpha channel.

Fields

AliceBlue

AliceBlue, the color that is represented by the RGB value #FFF0F8FF.

AntiqueWhite

AntiqueWhite, the color that is represented by the RGB value #FFFAEBD7.

Aqua

Aqua, the color that is represented by the RGB value #00ffff.

Aquamarine

Aquamarine, the color that is represented by the RGB value #FF7FFFD4.

Azure

Azure, the color that is represented by the RGB value #FFF0FFFF.

Beige

Beige, the color that is represented by the RGB value #FFF5F5DC.

Bisque

Bisque, the color that is represented by the RGB value #FFFFE4C4.

Black

Black, the color that is represented by the RGB value #000000.

BlanchedAlmond

BlanchedAlmond, the color that is represented by the RGB value #FFFFEBCD.

Blue

Blue, the color that is represented by the RGB value #0000ff.

BlueViolet

BlueViolet, the color that is represented by the RGB value #FF8A2BE2.

Brown

Brown, the color that is represented by the RGB value #FFA52A2A.

BurlyWood

BurlyWood, the color that is represented by the RGB value #FFDEB887.

CadetBlue

CadetBlue, the color that is represented by the RGB value #FF5F9EA0.

Chartreuse

Chartreuse, the color that is represented by the RGB value #FF7FFF00.

Chocolate

Chocolate, the color that is represented by the RGB value #FFD2691E.

Coral

Coral, the color that is represented by the RGB value #FFFF7F50.

CornflowerBlue

CornflowerBlue, the color that is represented by the RGB value #FF6495ED.

Cornsilk

Cornsilk, the color that is represented by the RGB value #FFFFF8DC.

Crimson

Crimson, the color that is represented by the RGB value #FFDC143C.

Cyan

Cyan, the color that is represented by the RGB value #FF00FFFF.

DarkBlue

DarkBlue, the color that is represented by the RGB value #FF00008B.

DarkCyan

DarkCyan, the color that is represented by the RGB value #FF008B8B.

DarkGoldenrod

DarkGoldenrod, the color that is represented by the RGB value #FFB8860B.

DarkGray

DarkGray, the color that is represented by the RGB value #FFA9A9A9.

DarkGreen

DarkGreen, the color that is represented by the RGB value #FF006400.

DarkKhaki

DarkKhaki, the color that is represented by the RGB value #FFBDB76B.

DarkMagenta

DarkMagenta, the color that is represented by the RGB value #FF8B008B.

DarkOliveGreen

DarkOliveGreen, the color that is represented by the RGB value #FF556B2F.

DarkOrange

DarkOrange, the color that is represented by the RGB value #FFFF8C00.

DarkOrchid

DarkOrchid, the color that is represented by the RGB value #FF9932CC.

DarkRed

DarkRed, the color that is represented by the RGB value #FF8B0000.

DarkSalmon

DarkSalmon, the color that is represented by the RGB value #FFE9967A.

DarkSeaGreen

DarkSeaGreen, the color that is represented by the RGB value #FF8FBC8F.

DarkSlateBlue

DarkSlateBlue, the color that is represented by the RGB value #FF483D8B.

DarkSlateGray

DarkSlateGray, the color that is represented by the RGB value #FF2F4F4F.

DarkTurquoise

DarkTurquoise, the color that is represented by the RGB value #FF00CED1.

DarkViolet

DarkViolet, the color that is represented by the RGB value #FF9400D3.

DeepPink

DeepPink, the color that is represented by the RGB value #FFFF1493.

DeepSkyBlue

DeepSkyBlue, the color that is represented by the RGB value #FF00BFFF.

DimGray

DimGray, the color that is represented by the RGB value #FF696969.

DodgerBlue

DodgerBlue, the color that is represented by the RGB value #FF1E90FF.

Firebrick

Firebrick, the color that is represented by the RGB value #FFB22222.

FloralWhite

FloralWhite, the color that is represented by the RGB value #FFFFFAF0.

ForestGreen

ForestGreen, the color that is represented by the RGB value #FF228B22.

Fuchsia

Fuchsia, the color that is represented by the RGB value #ff00ff.

Fuschia
Obsolete.

Fuchsia, the color that is represented by the RGB value #ff00ff. Deprecated. See Remarks.

Gainsboro

Gainsboro, the color that is represented by the RGB value #FFDCDCDC.

GhostWhite

GhostWhite, the color that is represented by the RGB value #FFF8F8FF.

Gold

Gold, the color that is represented by the RGB value #FFFFD700.

Goldenrod

Goldenrod, the color that is represented by the RGB value #FFDAA520.

Gray

Gray, the color that is represented by the RGB value #808080.

Green

Green, the color that is represented by the RGB value #008000.

GreenYellow

GreenYellow, the color that is represented by the RGB value #FFADFF2F.

Honeydew

Honeydew, the color that is represented by the RGB value #FFF0FFF0.

HotPink

HotPink, the color that is represented by the RGB value #FFFF69B4.

IndianRed

IndianRed, the color that is represented by the RGB value #FFCD5C5C.

Indigo

Indigo, the color that is represented by the RGB value #FF4B0082.

Ivory

Ivory, the color that is represented by the RGB value #FFFFFFF0.

Khaki

Khaki, the color that is represented by the RGB value #FFF0E68C.

Lavender

Lavender, the color that is represented by the RGB value #FFE6E6FA.

LavenderBlush

LavenderBlush, the color that is represented by the RGB value #FFFFF0F5.

LawnGreen

LawnGreen, the color that is represented by the RGB value #FF7CFC00.

LemonChiffon

LemonChiffon, the color that is represented by the RGB value #FFFFFACD.

LightBlue

LightBlue, the color that is represented by the RGB value #FFADD8E6.

LightCoral

LightCoral, the color that is represented by the RGB value #FFF08080.

LightCyan

LightCyan, the color that is represented by the RGB value #FFE0FFFF.

LightGoldenrodYellow

LightGoldenrodYellow, the color that is represented by the RGB value #FFFAFAD2.

LightGray

LightGray, the color that is represented by the RGB value #FFD3D3D3.

LightGreen

LightGreen, the color that is represented by the RGB value #FF90EE90.

LightPink

LightPink, the color that is represented by the RGB value #FFFFB6C1.

LightSalmon

LightSalmon, the color that is represented by the RGB value #FFFFA07A.

LightSeaGreen

LightSeaGreen, the color that is represented by the RGB value #FF20B2AA.

LightSkyBlue

LightSkyBlue, the color that is represented by the RGB value #FF87CEFA.

LightSlateGray

LightSlateGray, the color that is represented by the RGB value #FF778899.

LightSteelBlue

LightSteelBlue, the color that is represented by the RGB value #FFB0C4DE.

LightYellow

LightYellow, the color that is represented by the RGB value #FFFFFFE0.

Lime

Lime, the color that is represented by the RGB value #00ff00.

LimeGreen

LimeGreen, the color that is represented by the RGB value #FF32CD32.

Linen

Linen, the color that is represented by the RGB value #FFFAF0E6.

Magenta

Magenta, the color that is represented by the RGB value #FFFF00FF.

Maroon

Maroon, the color that is represented by the RGB value #800000.

MediumAquamarine

MediumAquamarine, the color that is represented by the RGB value #FF66CDAA.

MediumBlue

MediumBlue, the color that is represented by the RGB value #FF0000CD.

MediumOrchid

MediumOrchid, the color that is represented by the RGB value #FFBA55D3.

MediumPurple

MediumPurple, the color that is represented by the RGB value #FF9370DB.

MediumSeaGreen

MediumSeaGreen, the color that is represented by the RGB value #FF3CB371.

MediumSlateBlue

MediumSlateBlue, the color that is represented by the RGB value #FF7B68EE.

MediumSpringGreen

MediumSpringGreen, the color that is represented by the RGB value #FF00FA9A.

MediumTurquoise

MediumTurquoise, the color that is represented by the RGB value #FF48D1CC.

MediumVioletRed

MediumVioletRed, the color that is represented by the RGB value #FFC71585.

MidnightBlue

MidnightBlue, the color that is represented by the RGB value #FF191970.

MintCream

MintCream, the color that is represented by the RGB value #FFF5FFFA.

MistyRose

MistyRose, the color that is represented by the RGB value #FFFFE4E1.

Moccasin

Moccasin, the color that is represented by the RGB value #FFFFE4B5.

NavajoWhite

NavajoWhite, the color that is represented by the RGB value #FFFFDEAD.

Navy

Navy, the color that is represented by the RGB value #000080.

OldLace

OldLace, the color that is represented by the RGB value #FFFDF5E6.

Olive

Olive, the color that is represented by the RGB value #808000.

OliveDrab

OliveDrab, the color that is represented by the RGB value #FF6B8E23.

Orange

Orange, the color that is represented by the RGB value #ffa500.

OrangeRed

OrangeRed, the color that is represented by the RGB value #FFFF4500.

Orchid

Orchid, the color that is represented by the RGB value #FFDA70D6.

PaleGoldenrod

PaleGoldenrod, the color that is represented by the RGB value #FFEEE8AA.

PaleGreen

PaleGreen, the color that is represented by the RGB value #FF98FB98.

PaleTurquoise

PaleTurquoise, the color that is represented by the RGB value #FFAFEEEE.

PaleVioletRed

PaleVioletRed, the color that is represented by the RGB value #FFDB7093.

PapayaWhip

PapayaWhip, the color that is represented by the RGB value #FFFFEFD5.

PeachPuff

PeachPuff, the color that is represented by the RGB value #FFFFDAB9.

Peru

Peru, the color that is represented by the RGB value #FFCD853F.

Pink

Pink, the color that is represented by the RGB value #ff66ff.

Plum

Plum, the color that is represented by the RGB value #FFDDA0DD.

PowderBlue

PowderBlue, the color that is represented by the RGB value #FFB0E0E6.

Purple

Purple, the color that is represented by the RGB value #800080.

Red

Red, the color that is represented by the RGB value #ff0000.

RosyBrown

RosyBrown, the color that is represented by the RGB value #FFBC8F8F.

RoyalBlue

RoyalBlue, the color that is represented by the RGB value #FF4169E1.

SaddleBrown

SaddleBrown, the color that is represented by the RGB value #FF8B4513.

Salmon

Salmon, the color that is represented by the RGB value #FFFA8072.

SandyBrown

SandyBrown, the color that is represented by the RGB value #FFF4A460.

SeaGreen

SeaGreen, the color that is represented by the RGB value #FF2E8B57.

SeaShell

SeaShell, the color that is represented by the RGB value #FFFFF5EE.

Sienna

Sienna, the color that is represented by the RGB value #FFA0522D.

Silver

Silver, the color that is represented by the RGB value #c0c0c0.

SkyBlue

SkyBlue, the color that is represented by the RGB value #FF87CEEB.

SlateBlue

SlateBlue, the color that is represented by the RGB value #FF6A5ACD.

SlateGray

SlateGray, the color that is represented by the RGB value #FF708090.

Snow

Snow, the color that is represented by the RGB value #FFFFFAFA.

SpringGreen

SpringGreen, the color that is represented by the RGB value #FF00FF7F.

SteelBlue

SteelBlue, the color that is represented by the RGB value #FF4682B4.

Tan

Tan, the color that is represented by the RGB value #FFD2B48C.

Teal

Teal, the color that is represented by the RGB value #008080.

Thistle

Thistle, the color that is represented by the RGB value #FFD8BFD8.

Tomato

Tomato, the color that is represented by the RGB value #FFFF6347.

Transparent

The transparent color, represented by the RGB value #00ffffff.

Turquoise

Turquoise, the color that is represented by the RGB value #FF40E0D0.

Violet

Violet, the color that is represented by the RGB value #FFEE82EE.

Wheat

Wheat, the color that is represented by the RGB value #FFF5DEB3.

White

White, the color that is represented by the RGB value #ffffff.

WhiteSmoke

WhiteSmoke, the color that is represented by the RGB value #FFF5F5F5.

Yellow

Yellow, the color that is represented by the RGB value #ffff00.

YellowGreen

YellowGreen, the color that is represented by the RGB value #FF9ACD32.

Properties

A

Gets the alpha component of the color.

Accent

Gets the accent or tint color from the application.

B

Gets the blue component of the color.

Default

Returns the default color.

G

Gets the Green component of the color.

Hue

Gets the Hue of the color.

IsDefault

For internal use by the Xamarin.Forms platform.

Luminosity

Gets the Luminosity fo the color.

R

Gets the Red component of the color.

Saturation

Gets the Saturation of the color

Methods

AddLuminosity(Double)

Returns a new Color with a modified luminosity channel.

Equals(Object)

Determine if the provided System.Object is equivalent to the current Color.

FromHex(String)

Returns a new RGB Color instance with the requested Red, Green, and Blue channels. The Alpha channel is set if hex contains one.

FromHsla(Double, Double, Double, Double)

Returns a new HSL Color with an alpha channel

FromHsv(Double, Double, Double)
FromHsv(Int32, Int32, Int32)
FromHsva(Double, Double, Double, Double)
FromHsva(Int32, Int32, Int32, Int32)
FromRgb(Double, Double, Double)

Returns a new rgb color instance.

FromRgb(Int32, Int32, Int32)

Returns a new rgb color instance.

FromRgba(Double, Double, Double, Double)

Returns a new RGBA color instance.

FromRgba(Int32, Int32, Int32, Int32)

Returns a new RGBA color instance.

FromUint(UInt32)

Returns a new Color with the requested RGBA value.

GetHashCode()

Returns the Hashcode for this System.Object.

MultiplyAlpha(Double)

Returns a new color with the alpha channel multiplied by alpha, clamped to the inclusive range [0-1].

SetAccent(Color)

For internal use by the Xamarin.Forms platform.

ToHex()
ToString()

Returns a string representation of the Color.

WithHue(Double)

Returns a color with modified Hue, but keeping the same Saturation and Luminosity.

WithLuminosity(Double)

Returns a color with modified Luminosity.

WithSaturation(Double)

Returns a new color with modified Saturation.

Operators

Equality(Color, Color)

Returns true if color1 represents the same color as color1.

Implicit(Color to Color)

Converts the provided color to a System.Drawing.Color.

Implicit(Color to Color)

Converts the provided color to a Color.

Inequality(Color, Color)

Returns true if color1 does not represent the same color as color1.

Applies to