Describes a color in terms of alpha, red, green, and blue channels.
Assembly: System.Windows (in System.Windows.dll)
XMLNS for XAML: Not mapped to an xmlns.
<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"/>
Thetype exposes the following members.
|Equals(Color)||Tests whether the specified structure is identical to the current color.|
|Equals(Object)||Tests whether the specified object is a structure and is equivalent to the current color. (Overrides ValueType.Equals(Object).)|
|Finalize||Allows an object to try to free resources and perform other cleanup operations before the Object is reclaimed by garbage collection. (Inherited from Object.)|
|FromArgb||Creates a new structure by using the specified sRGB alpha channel and color channel values.|
|GetHashCode||Gets a hash code for the current structure. (Overrides ValueType.GetHashCode().)|
|GetType||Gets the Type of the current instance. (Inherited from Object.)|
|MemberwiseClone||Creates a shallow copy of the current Object. (Inherited from Object.)|
|ToString()||Creates a string representation of the color using the ARGB channels in hex notation. (Overrides ValueType.ToString().)|
|ToString(IFormatProvider)||Creates a string representation of the color by using the ARGB channels and the specified format provider.|
The Windows Phone implementation of does not support Color.FromRgb. The Windows Phone implementation of also does not support synchronized properties that report both the sRGB and scRBG values; only the sRGB values are reported as properties. It is possible to specify a using an scRGB format string, but this requires a deliberate XAML usage to access the type conversion behavior, along with Load.
Properties of do not support an attribute syntax in XAML for Windows Phone. In XAML you should always specify -type properties through one of the following usages:
The XAML attribute usage, which infers properties that use the type and uses a type converter to process the attribute string into the specific values for the .
A property element usage, containing a object element. For that object element, set the properties using initialization text, as shown in the XAML Object Element Usage.
The XAML object element usage (with initialization text) is useful for declaring a as a resource dictionary.
Windows Phone uses a resource dictionary for theme resources, which includes colors. These color resources are the recommended way to apply color in Windows Phone applications because they ensure UI elements appear consistency and can change color based on the theme the user has selected. For a more consistent user experience, avoid using static colors. For more information, see Theme resources for Windows Phone.
A predefined color can either be a static property name of Colors, or one of the other color names that can be processed by string type conversion. The following are the 16 colors that can be set in code using a static property value of the Colors class, or set in XAML by setting an attribute to their name string.
There are additional predefined named colors that do not have static properties on the Colors class that store their values. Instead, from-string type conversion behavior is enabled when parsing the attribute in XAML. The following is a table of the available named colors (which includes the 16 colors that have static properties available).
Note that setting a color by this means is possible directly when setting a Brush or value as a XAML attribute, but setting the colors in code for the colors that are not specific Colors class static properties takes some indirection, as is described in the next section.
Setting Predefined Colors or scRGB Colors in Code
In Windows Phone, setting predefined colors in code also uses the type conversion behavior, combined with XamlReader.Load. You must create an instance of an object element with a property of type Brush or , specifying the value of the property as one of the predefined color names. Then you can retrieve either the Brush or from the created object. In the case of the Brush (which will be a SolidColorBrush), you can also retrieve its Color property. You do not need to attach your created object to the element tree, you are using Load here as a construction mechanism that can access the predefined color string type conversion behavior. This same technique can be used to create colors from scRBG strings, or even sRGB strings (although for these it might be more convenient to use the FromArgb method, first splitting the string and performing math operations on the A,R,G,B atoms to match the FromArgb 0-255 scale).
String xamlString = "<Canvas xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\" Background=\"MistyRose\"/>"; Canvas c = (Canvas) System.Windows.Markup.XamlReader.Load(xamlString); SolidColorBrush mistyRoseBrush = (SolidColorBrush) c.Background; Color mistyRose = mistyRoseBrush.Color;