[Expand]General Information
[Expand]WinForms Controls
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]ASP.NET Core Bootstrap Controls
[Collapse]WPF Controls
  Prerequisites
 [Expand]What's Installed
 [Expand]Common Concepts
 [Collapse]MVVM Framework
  [Expand]ViewModels
  [Expand]Commands
  [Expand]Behaviors
  [Expand]Services
  [Expand]DXBinding
  [Expand]MIF
   Converters
   ViewLocator
   Messenger
   Data Annotation Attributes
   LayoutTreeHelper
   Weak Event
 [Expand]Controls and Libraries
 [Expand]Scaffolding Wizard
 [Expand]Localization
  Redistribution and Deployment
  Get More Help
 [Expand]API Reference
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Office File API
[Expand]Reporting
[Expand]Report and Dashboard Server
[Expand]Dashboard
[Expand]eXpressApp Framework
[Expand]eXpress Persistent Objects
[Expand]CodeRush
[Expand]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation
View this topic on docs.devexpress.com (Learn more)

Converters

The DevExpress.Xpf.Core.v18.2 library provides a set of extended value converters that help you perform conversions between different types and even between values of the same type. These converters are useful when binding one property to another of an incompatible type (for instance, when binding a control's Boolean property to a property of the Visibility type).

All converters are in the DevExpress.Mvvm.UI namespace.

Below is a list of available converters.

Expanded ObjectToObjectConverter

This converter acts as a dictionary, which maps predefined input values to output values of any type.

ObjectToObjectConverter provides three properties.

  • Map – this property contains a collection of MapItem objects that map input and output values.
  • DefaultTarget – this property contains an object, which should be returned in case of a failed conversion.
  • DefaultSource – the property is used in a backward conversion. It is returned when the conversion fails.

See the following example that explains how to use the ObjectToObjectConverter. Assume that there is a View Model exposing a property of the ColorState enumeration type.

A View bound to the View Model contains a TextBlock, which should display the text “Ready”, “Steady”, “Go” if the ViewModel.State property equals “Red”, “Yellow”, “Green” values respectively. This value mapping can be done with the ObjectToObjectConverter.

Expanded BooleanToObjectConverter

Converts the input Boolean, nullable Boolean or DefaultBoolean value to a value of any type.

This converter provides three mapping properties: TrueValue, FalseValue, and NullValue. These properties specify objects that should be returned if the input value is True, False, null (or DefaultBoolean.Default) respectively.

Expanded FormatStringConverter

This converter formats a value according to a specific format string. The standard binding supports this feature via the StringFormat property. However, bindings always use the default culture for the language defined in XAML. If it is necessary to use a custom culture, use the FormatStringConverter.

Expanded BooleanToVisibilityConverter

An extended version of the standard converter that maps Boolean values to the values of the Visibility type and vice versa.

Two additional properties are available in this converter.

  • Inverse – allows you to invert the conversion.
  • HiddenInsteadOfCollapsed – if this property is True, the converter returns the Hidden state instead of the Collapsed state when the input value is False.

Expanded NumericToBooleanConverter

Converts numeric values to the Boolean type.

If the input value is 0, the converter returns False; otherwise, it returns True.

Back conversion is not supported.

Expanded NumericToVisibilityConverter

Converts numeric values to the Visibility type.

If the input value is 0, the converter returns Visibility.Collapsed; otherwise, it returns Visibility.Visible.

Back conversion is not supported.

Two additional properties are available in this converter.

  • Inverse – allows you to invert the conversion.
  • HiddenInsteadOfCollapsed – if this property is True, the converter returns the Hidden state instead of the Collapsed state when the input value is 0.

Below is an example of how to use this converter.

Expanded BooleanNegationConverter

Inverts the input Boolean or DefaultBoolean value.

Expanded DefaultBooleanToBooleanConverter

Converts between the three-state DefaultBoolean type (Default, True and False) and the nullable Boolean type (null, true and false).

Expanded ObjectToBooleanConverter

If the input object is null, the converter returns False; otherwise, it returns True.

Back conversion is not supported.

Expanded StringToBooleanConverter

If the input string is empty or null, the converter returns False; otherwise, it returns True.

Back conversion is not supported.

Is this topic helpful?​​​​​​​