Color Object
Describes a color in terms of alpha, red, green, and blue channels.
XAML |
<object property="colorString" .../>
|
Scripting |
object.property = "colorString"
|
In Silverlight 1.0, colors are specified through a string that is parsed by one of three conventions or schemes: a named color, a hex string, or an ScRGB string. The hex string convention uses either one-character or two-character hex components, representing 8-bit and 16-bit colors for alpha, red, green, blue components, prefixed by a hash sign (#). The alpha component for hex schemes is optional, defaults to 100% alpha, and is only used if the string following the hash sign is exactly 4 or exactly 8 characters. The ScRGB convention uses the prefix "sc#" (case sensitive), then alpha, red, green, blue components as double values between 0 and 1. Each such value is separated by a separator (either a space or a comma). The alpha component for the ScRGB scheme is optional, defaults to 1, and is only used if there are 4 components (3 separators). All of the examples produce the same color value. Those that specify an alpha value all specify 50% alpha.
Scheme | Grammar | Example |
---|---|---|
Predefined Color Name | predefinedColorName | "Blue" |
8-bit hex, no alpha | #RGB | "#00f" |
8-bit hex, alpha | #ARGB | "#800f" |
16-bit hex, no alpha | #RRGGBB | "#0000ff" |
16-bit hex, alpha | #AARRGGBB | "#800000ff" |
scRGB, no alpha | sc# r,g,b |
"sc#0,0,1" |
scRGB, alpha | sc# a,r,g,b |
"sc#0.5,0,0,1" |
predefinedColorName
One of the values from the following table.
Predefined colors
A
Alpha component of an 8-bit hex scheme for defining a color. This value can be a hex string from 0 (full alpha, transparent) to F (no alpha, opaque).
RGB
Red (R) Green (G) or Blue (B) component of an 8-bit hex scheme for defining a color. This value can be a hex string from 0 (no saturation) to F (full saturation) for each of the R,G,B components.
AA
Alpha component of a 16-bit hex scheme for defining a color. This value can be a hex string from 00 (full alpha, transparent) to FF (no alpha, opaque).
RRGGBB
Red (RR) Green (GG) or Blue (BB) component of a 16-bit hex scheme for defining a color. This value can be a hex string from 00 (no saturation) to FF (full saturation) for each of the RR,GG,BB components.
a
Alpha component of an scRGB scheme for defining a color. This value can be a double from 0 (full alpha, transparent) to 1 (no alpha, opaque).
rgb
Red (r) Green (g) or Blue (b) component of an scRGB scheme for defining a color. This value can be a double from 0 (no saturation) to 1 (full saturation) for each of the r,g,b components.
Equals, FindName, GetHost, GetValue, SetValue
In Silverlight 1.0 JavaScript, there is often no object backing a declared color. A Color is often a convention for the common type conversion behavior for properties that take colors, both in scripting and XAML. Color is accessible as an object for the By, From, To, or Value properties of animations that you use to animate a Color type property (for instance an animated Background). However, because Color has no properties in script (other than Name, which is always an empty string), having an object reference to a Color has very limited application.
In scripting, you specify a color as a quoted string, and the same type conversion behavior as for XAML attributes is used. You can provide a string for the named color, hex, or ScRGB conventions. If you get the value of most Color properties (such as SolidColorBrush.Color) through scripting, using the ToString() result, the value obtained will generally not be the same string that was used to specify it. This is because the value from scripting is now type converted and no longer reflects any of the input schemes. The runtime scripting value of an existing Color is potentially stored differently on different browsers and platforms. You can compare color values obtained from scripting between existing instances, or set one Color property with the value of another existing Color, but directly comparing these values to named color strings, hex strings, or ScRGB strings that were used to specify the color initially is not supported.
The Silverlight named color choices match the Microsoft .NET Framework version 1.0, Windows Forms, and Microsoft Internet Explorer color names. This representation is based on UNIX X11 named color values.