[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
 [Expand]What's Installed
 [Expand].NET Core 3 Support
 [Expand]Common Concepts
 [Expand]MVVM Framework
 [Collapse]Controls and Libraries
  [Expand]Data Grid
  [Expand]Ribbon, Bars and Menu
  [Expand]Charts Suite
  [Expand]Pivot Grid
   [Expand]Getting Started
    Time Regions
   [Expand]Visual Elements
   [Expand]Styles and Templates
   [Expand]Design-Time Features
    Time Zones
   [Collapse]Data Binding
     Mapping Converters
     Custom Fields
    Appearance Customization
    Clipboard Operations
    Printing Templates
    Drag and Drop Customization
    End-User Restrictions
    Migration Guidelines
  [Expand]Rich Text Editor
  [Expand]Tree List
  [Expand]Gauge Controls
  [Expand]Map Control
  [Expand]Layout Management
  [Expand]Windows Modern UI
  [Expand]Data Editors
  [Expand]Navigation Controls
  [Expand]Spell Checker
  [Expand]Property Grid
  [Expand]PDF Viewer
  [Expand]TreeMap Control
  [Expand]Gantt Control
  [Expand]Diagram Control
  [Expand]Windows and Utility Controls
   Dialogs, Notifications and Panels
  [Expand]Scheduler (legacy)
 [Expand]Scaffolding Wizard
  Redistribution and Deployment
  Get More Help
 [Expand]API Reference
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Office File API
[Expand]Report and Dashboard Server
[Expand]eXpressApp Framework
[Expand]eXpress Persistent Objects
[Expand]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation
View this topic on docs.devexpress.com (Learn more)

Mapping Converters

Mapping converters allow you to apply custom logic to mapping.

Expanded Overview

Converters can change data from one type to another, translate data based on additional information, or change the format in which the data is stored. To associate a value converter with a mapping, create a class that implements the System.Windows.Data.IValueConverter interface and its Convert and ConvertBack methods and specify it in XAML using the Mapping.Converter property.

The data is propagated back and forth between the property, default mapping method and a data source field. You can insert a converter between the property and the default mapping method, or between default mapping method and the data source field, or instead of a default mapping method. Converter position in that propagation chain is defined by the MappingConversionBehavior enumeration.

The following image illustrates the converter's processing order:

Expanded How to Create a Converter

This section demonstrates how a mapping converter can solve a particular problem.

Problem: When the AppointmentLabelMappings.ColorSavingType is set to DXColorSavingType.ColorString, the color is stored as hex string in the "0xARGB" format. However, HTML color codes cannot be used to specify the label colors because they use the ARGB format with a hash (#) prefix.

Solution: Implement a custom converter to store colors as HTML color codes when the color saving type is ColorString.

  1. Implement a class with a System.Windows.Data.IValueConverter interface (inherited from the System.Windows.Markup.MarkupExtension class).

  2. Assign the converter to the label color mapping's Mapping.Converter property. Set the Mapping.ConversionBehavior to the MappingConversionBehavior.BetweenFieldAndMapping value so that it provides "0xARGB" formatted data from the data source to the default mapping and converts data obtained from the default mapping to the "#ARGB" format before passing it to the data source.

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