Condividi tramite


Color

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Describes a color in terms of alpha, red, green, and blue channels.

<object property="colorString"  .../>
object.property = "colorString"

colorString Grammar

In Silverlight 1.0, colors are specified through a string that is parsed by one of three conventions or schemes: a named color, a hexadecimal string, or an ScRGB string. The hexadecimal string convention uses either one-character or two-character hexadecimal components, representing 8-bit and 16-bit colors for alpha, red, green, blue components, prefixed by a hash sign (#). The alpha component for hexadecimal schemes is optional, defaults to 100% alpha, and is used only if the string that follows the hash sign is exactly 4 or 8 characters. The ScRGB convention uses the prefix "sc#" (case-sensitive) and then alpha, red, green, and blue components as double values between 0 and 1. Each such value is separated by either a space or a comma. The alpha component for the ScRGB scheme is optional, defaults to 1, and is used only if there are 4 components (3 separators). All of the examples in the following table 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 hexadecimal, no alpha

#RGB

"#00f"

8-bit hexadecimal, alpha

#ARGB

"#800f"

16-bit hexadecimal, no alpha

#RRGGBB

"#0000ff"

16-bit hexadecimal, 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"

Definitions

predefinedColorName

One of the values from the following table.

Predefined colors

Colors.

A

Alpha component of an 8-bit hexadecimal scheme for defining a color. This value can be a hexadecimal string from 0 (full alpha, transparent) to F (no alpha, opaque).

RGB

Red (R), green (G), or blue (B) component of an 8-bit hexadecimal scheme for defining a color. This value can be a hexadecimal string from 0 (no saturation) to F (full saturation) for each of the R, G, and B components.

AA

Alpha component of a 16-bit hexadecimal scheme for defining a color. This value can be a hexadecimal string from 00 (full alpha, transparent) to FF (no alpha, opaque).

RRGGBB

Red (RR), green (GG), or blue (BB) component of a 16-bit hexadecimal scheme for defining a color. This value can be a hexadecimal string from 00 (no saturation) to FF (full saturation) for each of the RR, GG, and BB components.

a

Alpha component of an ScRGB scheme for defining a color. This value can be a decimal value 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 decimal value from 0 (no saturation) to 1 (full saturation) for each of the r, g, and b components.

Managed Equivalent

Color

Remarks

When you use JavaScript to create a Silverlight application, a declared color often will not have a backing object. 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 example, an animated Background). However, because Color has no properties in script (other than Name, which is always an empty string), an object reference to a Color has very limited application.

In scripting, you specify a color as a quoted string, and you use the same type conversion behavior as for XAML attributes. You can use a named color string, a hexadecimal string (either 8-bit or 16-bit color depth), or an ScRGB string. If you get the value of most Color properties (such as Color (SolidColorBrush)) 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 you can set one Color property with the value of another existing Color, but directly comparing these values to named color strings, hexadecimal strings, or ScRGB strings that were used to initially specify the color 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.

For more information on basic concepts, see Brushes. Note that the Brushes topic is written primarily for users of the managed API, and may not have code examples or specific information that address the JavaScript API scenarios.

See Also

Reference