Log In
Home
Support
Demos
Documentation
Blogs
Training
Webinars
[Expand]Welcome to DevExpress .NET Documentation
[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
  [Expand]Windows and Utility Controls
   Dialogs, Notifications and Panels
   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]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]Document Server
[Expand]Reporting
[Expand]Report 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 converter processing order is illustrated in the following image.

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 format "0xARGB". However, HTML color codes use ARGB format prefixed with hash (#) mark and thus cannot be used to directly specify the label colors.

Solution: To store colors as HTML color codes when the color saving type is ColorString, we have to implement a custom converter.

  1. Implement a class with the 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 "#ARGB" format before passing them 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?​​​​​​​