See Also: Color Members
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.
Color | Short Name | RGB Value |
---|---|---|
Color.Transparent | Transparent | 0, 0, 0 (With the alpha channel set to 0.) |
Color.Aqua | Aqua | 0, 255, 255 |
Color.Black | Black | 0, 0, 0 |
Color.Blue | Blue | 0, 0, 255 |
Color.Fuchsia | Fuchsia | 255, 0, 255 |
Color.Gray | Gray | 128, 128, 128 |
Color.Green | Green | 0, 128, 0 |
Color.Lime | Lime | 0, 255, 0 |
Color.Maroon | Maroon | 128, 0, 0 |
Color.Navy | Navy | 0, 0, 128 |
Color.Olive | Olive | 128, 128, 0 |
Color.Purple | Purple | 128, 0, 128 |
Color.Pink | Pink | 255, 102, 255 |
Color.Red | Red | 255, 0, 0 |
Color.Silver | Silver | 192, 192, 192 |
Color.Teal | Teal | 0, 128, 128 |
Color.White | White | 255, 255, 255 |
Color.Yellow | Yellow | 255, 255, 0 |