Xamarin.Forms Guides | Samples

Xamarin.Forms.ColorTypeConverter Class

A TypeConverter that converts from strings to a Color.

See Also: ColorTypeConverter

Syntax

public class ColorTypeConverter : TypeConverter

Remarks

The following example shows some variations of ColorTypeConverter:

C# Example

var converter = new ColorTypeConverter ();
Assert.True (converter.CanConvertFrom (typeof(string)));
Assert.AreEqual (Color.Blue, converter.ConvertFrom ("Color.Blue"));
Assert.AreEqual (Color.Blue, converter.ConvertFrom ("Blue"));
Assert.AreEqual (Color.Blue, converter.ConvertFrom ("#0000ff"));
Assert.AreEqual (Color.Default, converter.ConvertFrom ("Color.Default"));
Assert.AreEqual (Color.Accent, converter.ConvertFrom ("Accent"));
var hotpink = Color.FromHex ("#FF69B4");
Color.Accent = hotpink;
Assert.AreEqual (Color.Accent, converter.ConvertFrom ("Accent"));

Requirements

Namespace: Xamarin.Forms
Assembly: Xamarin.Forms.Core (in Xamarin.Forms.Core.dll)
Assembly Versions: 1.0.0.0, 1.1.0.0, 1.2.0.0, 1.3.0.0, 1.4.0.0, 1.5.0.0, 2.0.0.0

The members of Xamarin.Forms.ColorTypeConverter are listed below.

See Also: TypeConverter

Public Constructors

Creates a new ColorTypeConverter with default values.

Public Methods

override
CanConvertFrom(Type) : Boolean
Returns a Boolean value that indicates whether this ColorTypeConverter can convert the sourceType to a Color instance.
override
ConvertFrom(CultureInfo, Object) : Object
Converts value into a Color by using the specified culture.
override
ConvertFromInvariantString(String) : Object
Creates a color from a valid color name.