In This Article

MathConverter Class

A value converter that can perform basic mathematic calculations.

public class MathConverter : IMultiValueConverter, IValueConverter
Inheritance:
object object
Implements:
IMultiValueConverter IValueConverter

Remarks

The mathematical expression is passed as the parameter to the converter. Use the variables x, y, and z in the expression to refer to the first, second, and third values of the binding, respectively. Alternatively, use p0, p1, p2, ... pN to refer to each value where N is the zero-based index of the value.

It is recommended to use one instance of MathConverter for each unique expression since the parsed syntax tree of the expression can be cached for future calculations.

Constructors

MathConverter()

Initializes an instance of the class.

public MathConverter()

Methods

Convert(IList<object?>, Type, object?, CultureInfo)

Converts multi-binding inputs to a final value.

public object? Convert(IList<object?> values, Type targetType, object? parameter, CultureInfo culture)
Parameter Type Description
values IList<object>

The values to convert.

targetType Type

The type of the target.

parameter object

A user-defined parameter.

culture CultureInfo

The culture to use.

Returns

object:

The converted value.

Remarks

This method should not throw exceptions. If the value is not convertible, return Avalonia.AvaloniaProperty.UnsetValue. Any exception thrown will be treated as an application exception.

Convert(object?, Type, object?, CultureInfo)

Converts a value.

public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
Parameter Type Description
value object

The value to convert.

targetType Type

The type of the target.

parameter object

A user-defined parameter.

culture 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(object?, Type, object?, CultureInfo)

Converts a value.

public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
Parameter Type Description
value object

The value to convert.

targetType Type

The type of the target.

parameter object

A user-defined parameter.

culture 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.

Inherited Members

Extension Methods