[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
 [Expand]MVVM Framework
 [Collapse]Controls and Libraries
   Reporting
  [Expand]Data Grid
  [Expand]Ribbon, Bars and Menu
  [Expand]Charts Suite
  [Expand]Pivot Grid
  [Collapse]Scheduler
   [Expand]Getting Started
   [Expand]Appointments
    Resources
    Reminders
   [Expand]Views
   [Expand]Visual Elements
   [Expand]Styles and Templates
   [Expand]Design-Time Features
    Time Zones
   [Collapse]Data Binding
     Mappings
     Mapping Converters
     Custom Fields
    Grouping
    Selecting
    Navigating
    Printing
    End-User Restrictions
   [Expand]Examples
    Migration Guidelines
  [Expand]Spreadsheet
  [Expand]Rich Text Editor
  [Expand]Tree List
  [Expand]Gauge Controls
  [Expand]Map Control
  [Expand]Layout Management
  [Expand]Windows Modern UI
  [Expand]Printing-Exporting
  [Expand]Data Editors
  [Expand]Navigation Controls
  [Expand]Spell Checker
  [Expand]Property Grid
  [Expand]PDF Viewer
  [Expand]TreeMap Control
  [Expand]Diagram Control
  [Expand]Windows and Utility Controls
   Dialogs, Notifications and Panels
  [Expand]Scheduler (legacy)
 [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]CodeRush
[Expand]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation

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

    Show Me

    A complete sample project is available in the DevExpress Code Examples database at http://www.devexpress.com/example=T587301.

  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.

    Show Me

    A complete sample project is available in the DevExpress Code Examples database at http://www.devexpress.com/example=T587301.

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