#210 – Specifying Colors in XAML As RGB Values
February 7, 2011 Leave a comment
The type converter that converters names of colors to a SolidColorBrush of the specified color will also create a brush of a specified RGB color. You can specify RGB color values in XAML in one of several ways.
In the example below, we specify each of the R, G and B values as a 2 hex-digit number (00-FF), representing the range 0-255. The digits are ordered RRGGBB, so the value #FF0000 is solid red.
<Button Height="25" Width="100" Content="A button" Background="#FF0000"/>
Here are some other formats that you can use:
- #rgb – RGB value with only 1 digit per color (0-F). E.g. #FF0 (Red+Green = Yellow)
- #argb – single-digit RGB + alpha value (0-F)
- #aarrggbb – 2 digits for R, G, B + 2 digits for alpha channel (transparency)
- sc#scA,scR,scG,scB – scRGB formatted number, each value ranging from 0.0 to 1.0