Color.FromHex(String) Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Returns a new RGB Color instance with the requested Red, Green, and Blue channels. The Alpha channel is set if hex
contains one.
public static Xamarin.Forms.Color FromHex (string hex);
static member FromHex : string -> Xamarin.Forms.Color
Parameters
- hex
- System.String
A string that contains the hexadecimal (A)RGB color representation.
Returns
A color.
Remarks
When specifying a color with a hexadecimal number, app developers can use 3, 4, 6, or 8 digits, with an optional "#" prefix. 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". 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". Finally, the developer can explicitly provide an 8-digit number that completely specifies the Alpha, Red, Green, and Blue channels, in that order.
Note that, in the paragraph above, the fully expanded color description is of the format, AARRGGBB. That is: the first pair of hexadecimal digits specifies the Alpha channel; the second pair specifies the Red channel; the third pair specifies the Green channel; and the final pair specifies the Blue channel.
If the input string can not be parsed, Color.Default is returned.