ToString method

Color.ToString method

Creates a String representation of this Color.


public override string ToString()


This method has no parameters.

Return value

Type: System.String

A String representation of this Color.


This method overrides the virtual Object.ToString so that a Color can report its serialized values rather than a type reference when you call ToString.

The string representations of Color values are similar to XAML attribute string syntax for specifying Color values in markup. It is the syntax that is most commonly used by designer tools to specify a (non-named) Color. The string is in the form #AARRGGBB, where each letter pair represents one of the color channels as a value between 00 and FF. Each letter pair is interpreted as if it were a hex value and thus represents a value between 0 and 255. The string always starts with a hash (#). For example, the string form of the color where A=255, R=0, G=128, B=255 is "#FF0080FF". For named colors you get the serialized string and not the constant name; for example calling ToString on Colors.Blue gives "#FF0000FF".

The ToString value isn't immediately usable to construct another color unless you do use XAML parse behavior at run-time (for example, you could construct a XAML fragment that uses the string as an attribute, load that fragment with XamlReader.Load, and assign the returned object to a property). But you could process the string yourself and divide it into values that are suitable for each parameter of Color.FromArgb to construct a matching color value.

Note  Visual C++ component extensions (C++/CX) doesn't use nondata members of Color, and doesn't enable this form of string returned from ToString. The ToString value returned from C++/CX for a Color is the unmodified Platform::Object::ToString behavior, which gives a representation of the type (boxed by IReference) and does not indicate the value.

Requirements (Windows 10 device family)

Device family

API contract



Requirements (Windows 8.x and Windows Phone 8.x)

Minimum supported client

Windows 8

Minimum supported server

Windows Server 2012

Minimum supported phone

Windows Phone 8.1 [Windows Runtime apps only]





See also

Object.ToString (.NET)



© 2016 Microsoft