Xamarin.Forms.Color Structure
Class that represents a color and exposes it as RGBA and HSL values.

See Also: Color Members

Syntax

[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

Remarks

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

In XAML, application developers can specify any property that is of type Xamarin.Forms.Color, for example, Label.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:

XAML Example

<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:

XAML Example

<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. The following table describes the valid color names that can be used to specify colors in XAML.
ColorShort NameRGB Value
Color.TransparentTransparent0, 0, 0 (With the alpha channel set to 0.)
Color.AquaAqua0, 255, 255
Color.BlackBlack0, 0, 0
Color.BlueBlue0, 0, 255
Color.FuchsiaFuchsia255, 0, 255
Color.GrayGray128, 128, 128
Color.GreenGreen0, 128, 0
Color.LimeLime0, 255, 0
Color.MaroonMaroon128, 0, 0
Color.NavyNavy0, 0, 128
Color.OliveOlive128, 128, 0
Color.PurplePurple128, 0, 128
Color.PinkPink255, 102, 255
Color.RedRed255, 0, 0
Color.SilverSilver192, 192, 192
Color.TealTeal0, 128, 128
Color.WhiteWhite255, 255, 255
Color.YellowYellow255, 255, 0

Requirements

Namespace: Xamarin.Forms
Assembly: Xamarin.Forms.Core (in Xamarin.Forms.Core.dll)
Assembly Versions: 1.0.0.0, 1.1.0.0, 1.2.0.0, 1.3.0.0