0 out of 6 rated this helpful - Rate this topic

Color structure

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

Syntax


var color = {
    a : /* Your value */,
    b : /* Your value */,
    g : /* Your value */,
    r : /* Your value */
}


<Color ...>predefinedColor</Color>
- or -
<Color ...>#rgb</Color>
- or -
<Color ...>#argb</Color>
- or -
<Color ...>#rrggbb</Color>
- or -
<Color ...>#aarrggbb</Color>
- or -
<Color ...>sc#scR,scG,scB</Color>
- or -
<Color ...>sc#scA,scR,scG,scB</Color>


<object property="predefinedColor"/>
- or -
<object property="#rgb"/>
- or -
<object property="#argb"/>
- or -
<object property="#rrggbb"/>
- or -
<object property="#aarrggbb"/>
- or -
<object property="sc#scR,scG,scB"/>
- or -
<object property="sc#scA,scR,scG,scB"/>

XAML Values

predefinedColor

One of the colors predefined by the Colors class. See members of Colors for a list. These are static properties. Specify just the color name, for example "Transparent". Do not include the static class qualifier in the string: for example "Colors.Transparent" does not parse in XAML.

rgb

A three-character hexadecimal value. The first character specifies the color's R value, the second character specifies the G value, and the third character specifies the B value. For example, 00F.

argb

A four-character hexadecimal value. The first character specifies the color's A value, the second character specifies its R value, the third character specifies the G value, and the fourth character specifies its B value. For example, F00F.

rrggbb

A six-character hexadecimal value. The first two characters specify the color's R value, the next two specify its G value, and the final two specify its B value. For example, 0000FF.

aarrggbb

An eight-character hexadecimal value. The first two characters specify the color's A value, the next two specify its R value, the next two specify its G value, and the final two specify its B value. For example, FF0000FF.

scA

The color's ScA value as a value between 0 and 1.

scR

The color's ScR value as a value between 0 and 1.

scG

The color's ScG value as a value between 0 and 1.

scB

The color's ScB value as a value between 0 and 1.

Attributes

VersionAttribute(NTDDI_WIN8)

Members

The Color structure has these types of members:

Fields

The Color structure has these fields.

FieldData typeDescription
A | a [C++, JavaScript]

Number [JavaScript] | System.Byte [.NET] | uint8 [C++]

Gets or sets the sRGB alpha channel value of the color.

B | b [C++, JavaScript]

Number [JavaScript] | System.Byte [.NET] | uint8 [C++]

Gets or sets the sRGB blue channel value of the color.

G | g [C++, JavaScript]

Number [JavaScript] | System.Byte [.NET] | uint8 [C++]

Gets or sets the sRGB green channel value of the color.

R | r [C++, JavaScript]

Number [JavaScript] | System.Byte [.NET] | uint8 [C++]

Gets or sets the sRGB red channel value of the color.

 

Methods

The Color structure has these methods. With C#, Visual Basic, and C++, it also inherits methods from the Object class.

MethodDescription
Equals(Color) [C#, VB]Compares two Color structures for equality.
Equals(Object) [C#, VB]Determines whether the specified object is equal to a Color.
FromArgb [C#, VB]Creates a new Color structure by using the specified sRGB alpha channel and color channel values.
GetHashCode [C#, VB]Gets a hash code for this object.
ToString [C#, VB]Converts a Color to a String representation.
ToString(IFormatProvider) [C#, VB]Creates a String representation of this Color.

 

Operators

The Color structure has these operators.

OperatorDescription
Equality Compares two Color structures for equality.
Inequality Compares two Color structures for inequality.

 

Properties

The Color structure has these properties.

PropertyAccess typeDescription

A [C#, VB]

Read/writeGets or sets the sRGB alpha channel value of the color.

B [C#, VB]

Read/writeGets or sets the sRGB blue channel value of the color.

G [C#, VB]

Read/writeGets or sets the sRGB green channel value of the color.

R [C#, VB]

Read/writeGets or sets the sRGB red channel value of the color.

 

Remarks

Color is a Windows Runtime structure that represents a color that has four channels: A (alpha), R (red), G (green), B (blue). Each of the values is stored as a Byte type with value 0-255.

Color values are used in these features and scenarios:

  • Colors for start screens and general UI (for example SecondaryTile.BackgroundColor and UISettings.UIElementColor). These can be used in JavaScript.
  • Color values for the Windows 8 ink system. Specifically, InkDrawingAttributes.Color. This can be used in JavaScript.
  • Color values for XAML UI and Windows Store apps built for Windows using C++, C#, or Visual Basic, particularly for brushes. These APIs can't be used in JavaScript.
  • Defining color values that are used for interfaces representing text, in the Windows.UI.Text namespace. These APIs can't be used in JavaScript.

Color values and XAML definitions

The most frequent application of Color is to define color-related properties in a UI element as part of a Windows Store app using C++, C#, or Visual Basic and its XAML UI definition.

Various predefined Color values are available as static properties on the Colors class. These properties are useful for setting Color values in code that match the attribute string form used in XAML to set a named Color. For example, the Colors.AliceBlue property returns a Color that is equal in value to the Color set in XAML with a syntax such as <SolidColorBrush Color="AliceBlue" />. You can also use the Colors values for equality comparisons.

In most XAML UI scenarios, a Color isn't used directly as a property value of a UIElement. Instead, a Color is used as a component value of a Brush (either SolidColorBrush or LinearGradientBrush). However, the Brush type enables a XAML shorthand that lets you set an attribute value of type Brush using a named color string, or a format string that can be parsed into an ARGB form. For example, you can set the Brush-type value TextBlock.Foreground using a syntax such as <TextBlock Foreground="Cyan" />. This syntax implicitly creates a new SolidColorBrush with a Color value equal to Cyan that fills the Brush-type value of TextBlock.Foreground for that element. For more info on using brushes and colors in XAML, see Quickstart: Using brushes.

There are also some XAML properties that take a direct Color value. These mostly support animating a Color value that exists on a Brush. The Windows Runtime supports an interpolation logic so that you can animate from one Color to another in a From/To animation and the animation will use interpolated Color values as the animation runs. For more info, see Storyboarded animations.

Notes on XAML syntax

If you use the "#" token to specify color values in hex form, the hex values are stored in the structure as values between 0 and 255, not as the original hex strings. If you use the "sc#" token, the values are also stored as values between 0 and 255, not the original value of 0 to 1.

Strings for named colors are interpreted based on the associated Colors constants, and the values for A, R, G and B are set in the structure as values between 0 and 255 that are representative of that color.

The XAML object element usage (with initialization text) is useful for declaring a Color as a resource in a XAML ResourceDictionary. For more info, see ResourceDictionary and StaticResource references.

Projection and members of Color

If you are using a Microsoft .NET language (C# or Microsoft Visual Basic), then Color has a static method FromArgb that acts as a Color value generator. Also, the data members of Color are exposed as read-write properties, not fields.

If you are programming with C++, then only the data member fields exist as members of Color, and you cannot use the utility methods or properties listed in the members table. C++ code can access an equivalent FromArgb method on the ColorHelper class.

Requirements

Minimum supported client

Windows 8

Minimum supported server

Windows Server 2012

Minimum supported phone

Windows Phone 8

Namespace

Windows.UI
Windows::UI [C++]

Metadata

Windows.winmd

See also

Quickstart: Using brushes
Colors
ColorHelper
SolidColorBrush
ResourceDictionary and StaticResource references

 

 

Build date: 2/25/2013

© 2013 Microsoft. All rights reserved.