Skip to main content

ColorToHexConverter Class

Definition​

Assembly:Avalonia.Controls.ColorPicker
Package:Avalonia.Controls.ColorPicker

Converts a color to a hex string and vice versa.

public class ColorToHexConverter

Inheritance: object -> ColorToHexConverter

Implements:IValueConverter

Constructors​

NameDescription
ColorToHexConverterNo summary available.

ColorToHexConverter Constructor​

public ColorToHexConverter()

Methods​

NameDescription
ConvertConverts a value.
ConvertBackConverts a value.
ParseHexStringParses a hex color value string into a new Avalonia.Media.Color.
ToHexStringConverts the given color to its hex color value string representation.

Convert Method​

Converts a value.

public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)

Parameters​

value object

The value to convert.

targetType Type

The type of the target.

parameter object

A user-defined parameter.

culture System.Globalization.CultureInfo

The culture to use.

Returns​

object

The converted value.

Remarks​

This method should not throw exceptions. If the value is not convertible, return a Avalonia.Data.BindingNotification in an error state. Any exceptions thrown will be treated as an application exception.

ConvertBack Method​

Converts a value.

public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)

Parameters​

value object

The value to convert.

targetType Type

The type of the target.

parameter object

A user-defined parameter.

culture System.Globalization.CultureInfo

The culture to use.

Returns​

object

The converted value.

Remarks​

This method should not throw exceptions. If the value is not convertible, return a Avalonia.Data.BindingNotification in an error state. Any exceptions thrown will be treated as an application exception.

ParseHexString Method​

Parses a hex color value string into a new Avalonia.Media.Color.

public Nullable<Avalonia.Media.Color> ParseHexString(string hexColor, Avalonia.Controls.AlphaComponentPosition alphaPosition)

Parameters​

hexColor string

The hex color string to parse.

alphaPosition Avalonia.Controls.AlphaComponentPosition

The input position of the alpha component.

Returns​

Nullable<Avalonia.Media.Color>

The parsed Avalonia.Media.Color; otherwise, null.

ToHexString Method​

Converts the given color to its hex color value string representation.

public string ToHexString(Avalonia.Media.Color color, Avalonia.Controls.AlphaComponentPosition alphaPosition, bool includeAlpha, bool includeSymbol)

Parameters​

color Avalonia.Media.Color

The color to represent as a hex value string.

alphaPosition Avalonia.Controls.AlphaComponentPosition

The output position of the alpha component.

includeAlpha bool

Whether the alpha component will be included in the hex string.

includeSymbol bool

Whether the hex symbol '#' will be added.

Returns​

string

The input color converted to its hex value string.

Properties​

NameDescription
AlphaPositionGets or sets the position of a color's alpha component relative to all other components.
IsAlphaVisibleGets or sets a value indicating whether the alpha component is visible in the Hex formatted text.

AlphaPosition Property​

Gets or sets the position of a color's alpha component relative to all other components.

public Avalonia.Controls.AlphaComponentPosition AlphaPosition { get; set; }

IsAlphaVisible Property​

Gets or sets a value indicating whether the alpha component is visible in the Hex formatted text.

public bool IsAlphaVisible { get; set; }

Remarks​

When hidden the existing alpha component value is maintained. Also when hidden the user is still able to input an 8-digit number with alpha. Alpha will be processed but then removed when displayed.

Because this property only controls whether alpha is displayed (and it is still processed regardless) it is termed 'Visible' instead of 'Enabled'.