In This Article

Value Converters

The ActiproSoftware.Windows.Data, ActiproSoftware.Windows.Controls, ActiproSoftware.Windows.Media namespaces contain numerous value converters that can be used in XAML for working with data.

Type Description

BooleanAndConverter

Represents a multi-value converter that performs a logical AND (&&) operation on one or more Boolean values passed to the associated MultiBinding object.

BooleanNotConverter

Represents a value converter that performs a NOT (!) operation on a specified Boolean value.

BooleanOrConverter

Represents a multi-value converter that performs a logical OR (||) operation on one or more Boolean values passed to the associated MultiBinding object.

BrushOpacityConverter

Represents a value converter that clones a specified Brush and updates the Brush.Opacity property based on the converter's parameter.

CharacterCasingConverter

Represents a value converter that can be used to change a string's character casing to uppercase or lowercase. Set the CharacterCasingConverter.CharacterCasing property to either Upper (the default) or Lower to specify the casing mode.

CoalesceConverter

Represents a value converter that returns the value if it is non-null; otherwise, the value of the converter's parameter. This converter can also be used in a MultiBinding, in which case the first non-null value is returned; otherwise, the converter's parameter is returned.

ColorInterpolationConverter

This converter can be used in XAML bindings to return the linear Color value that is the specified percentage between the value of two Color objects.

The optional percentage is indicated in the converter parameter. If not specified, the default of 0.5 (50%) will be used.

Exactly two Color objects must be passed into the converter using a MultiBinding.

This XAML shows how to use the converter to find a color that is between the system control and window colors but 90% towards the window color:

<MultiBinding Converter="{StaticResource ColorInterpolationConverter}" ConverterParameter="0.9">
	<Binding Source="{x:Static SystemColors.ControlColor}" />
	<Binding Source="{x:Static SystemColors.WindowColor}" />
</MultiBinding>

ConditionalConverter

Represents a value and multi-value converter that provides if-else functionality for Binding and MultiBinding objects.

This converter expects the following source values to be specified:

  1. Condition - A boolean value indicating whether the true or false value should be returned.
  2. TrueValue - An object that is returned when the Condition is true. This can be omitted if the FalseValue parameter is also omitted, in which case the value of the TrueValue property will be used.
  3. FalseValue - An object that is returned when the Condition is false. This can be omitted, in which case the value of the FalseValue property will be used.

This sample code shows how to use the converter in a MultiBinding in XAML:

<MultiBinding Converter="{StaticResource ConditionalConverter}">
	<Binding Path="IfConditionValue" />
	<Binding Path="TrueValue" />
	<Binding Path="FalseValue" />
</MultiBinding>

This sample code shows how to use the converter in a Binding in XAML:

<shared:ConditionalConverter x:Key="ConditionalConverter" TrueValue="The Value is true" FalseValue="The Value is false" />
...
<TextBlock Text="{Binding Path=BooleanProperty, Converter={StaticResource ConditionalConverter}}" />

If the condition is not a boolean, other condition evaluation logic executes as follows. Strings evaluate true if they are not null or empty. Non-null objects also return true.

CornerRadiusConverter

Represents a value converter that converts between a CornerRadius and a number.

... Value="{Binding Path=Number, Converter={StaticResource CornerRadiusConverter}}" ...

DelegateConverter

Represents a value converter that uses delegates to perform the underlying conversion to/from the source. Set the ConvertCallback and ConvertBackCallback properties to the delegates to use for conversion and back conversion respectively.

DurationToMillisecondConverter

Represents a value converter that converts between a Duration and a number of milliseconds.

EnumDescriptionConverter

Represents a value converter that uses the DescriptionAttribute for the string representation of the enumeration values, when available.

ImageConverter

Represents a value converter that returns a new DynamicImage (inherits Image) control instance created using a specified URI or BitmapSource.

This converter expects the source value to be a Uri, a URI String, or a BitmapSource that can be used to create a new DynamicImage instance. A prefix can be defined in UriPrefix which will be prepended to all source values of type String before the DynamicImage is created.

The Width and Height properties can optionally be set to set the related properties on the DynamicImage control that is created.

The ImageProvider property can optionally be set to a specific ImageProvider to assign to the ImageSource created by the converter. Leave the property its default value of null to use the static default ImageProvider instance.

InverseConverter

Represents a value converter that inverts another value converter. Set an instance of the IValueConverter to invert in the Converter property.

IsEnumFlagSetConverter

Represents a value converter that returns whether the specified enumeration value has the flag, specified by the converter's parameter, set.

IsNullOrEmptyConverter

Represents a value converter that returns whether the specified value is null, and if it is a string, also if it is null or empty.

IsTypeConverter

Represents a value converter that returns whether the specified object is the Type indicated in the converter's parameter.

MultiplicationConverter

Represents a single and multi-value converter that multiplies all the source values provided, and optionally the converter's parameter.

NoOpConverter

Represents a value converter that does not alter the value in any way (e.g. no operation).

This converter can be used to bypass an issue that arises from an optimization present in the WPF binding system.

ParallaxConverter

Represents a value converter that can be used to create a parallax background scrolling effect.

Use the converter in a binding on a background element's RenderTransform's TranslateTransform.X or Y property, and bind to a related ScrollViewer.HorizontalOffset or VerticalOffset property.

PercentageConverter

Represents a value converter that converts between a number and a percentage. The percentage is simply the number multiplied by 100.

StringFormatConverter

Represents a multi-value converter that provides String.Format functionality for both simple Binding and MultiBinding objects.

Pass the format string in the converter's parameter. Since { characters are normally interpreted as markup extension starts, you can escape them by placing {} before the format string like this:

<MultiBinding Converter="{StaticResource StringFormatConverter}" ConverterParameter="{}{0} of {1}">...

ThicknessConverter

Represents a value converter that converts between a Thickness and a number.

By default, the Thickness returned will have all four sides (Thickness.Left, Thickness.Top, Thickness.Right, and Thickness.Bottom) set to the specified number. An optional parameter of type Sides can be specified, which can be used to customize the sides that are set.

<!-- Set all four sides -->
... Value="{Binding Path=Number, Converter={StaticResource ThicknessConverter}}" ...
								
<!-- Only set the Left and Right sides -->
... Value="{Binding Path=Number, Converter={StaticResource ThicknessConverter}, ConverterParameter='Left,Right'}" ...

TypeNameConverter

Represents a value converter that converts a value to a String of its short type name.

UnitToDoubleConverter

Represents a value converter that converts between a Unit and a Double.

This converter needs additional information in order to convert a Double into a Unit. Specifically, it needs to the know whether the value is measured in pixels or as a percentage. To accommodate this need, the property Type is used to specify the type of measurement.

UriConverter

Represents a value converter that returns a new Uri instance created using the specified URI string combined with an optional URI prefix.

This converter expects the source value to be a String which, when combined with the UriPrefix, can be used to create a new Uri instance.

ZoomLevelToTextFormattingModeConverter

Represents a value converter that alters the TextFormattingMode based on the specified zoom level.

Display mode is used when the zoom level is 1.0. Ideal mode is used when the zoom level is increased.