- Check Problem in displaying Enum List in Chart ( Enum List is not Displayed as required) for an example on how to localize chart control axis texts and legend;
- Handle the ASPxXXXExporter.RenderBrick event to localize the exported enumeration value. To access it, cast the ASPxGridListEditor.Printable property to ASPxGridViewExporter. Further details can be found at Access Grid Control Properties. See also the Export to Excel (and other) doesn’t use DisplayNameAttibute for enums. ticket for some example code.
To get the localized enumeration value, use the EnumDescriptor.GetCaption method.
See Also:
PivotGrid and Chart modules - Provide the capability to localize field captions and other texts via the wizard
Localization - How to use localized enumeration values from the Application Model with data bound controls
Answers approved by DevExpress Support
There are two possible ways of accomplishing this task, which apply at different application layers:
1. UI control level
You can implement a ViewController that will access the required underlying visual control directly and customize its settings every time the control is shown in the UI. The idea is to integrate control-specific solutions you would use for the same task in a regular non-XAF application. For more information on this, refer to the Access Grid Control Properties and List Editors help articles as well as the documentation on customized controls.
Here are also some tips on the most popular scenarios, which are not yet covered by the standard XAF code:
- Chart ( localizing axis texts and legend): handle the CustomDrawSeries and CustomDrawAxisLabel events as shown in the Problem in displaying Enum List in Chart ( Enum List is not Displayed as required) ticket;
- Pivot Grid (localizing data field values): handle the CustomCellDisplayText and FieldValueDisplayText events as shown in the PivotGrid module - CaptionForTrue and CaptionForFalse are not taken into account when displaying field values ticket.
- Web Grid and TreeList (localizing exported data field values): handle the ASPxXXXExporter.RenderBrick event as shown in the Export to Excel (and other) doesn’t use DisplayNameAttibute for enums. ticket (you can access the exporter object by casting the ASPxXXXListEditor.Printable property to ASPxXXXExporter).
If you have questions on these control-specific solutions, it is better to create tickets for the corresponding control/product in the Support Center so the responsible team could provide you with the best solution possible for their control.
To get the localized enumeration value from the Application Model in your custom XAF Controller, use the EnumDescriptor.GetCaption method.
OR
2. Data model level
You can declare a new calculated System.String property in your business model that would internally return the result of the EnumDescriptor.GetCaption call. Then, you can use this duplicate property exclusively with required visual controls.
The .Net Framework does not provide a built-in way to localize enumeration values when they are shown in UI. So, to support this behavior, we had to add event handlers to each specific control that can show an enumeration value (e.g in the DropDownEdit), and add an event handler to each algorithm that generates a text from an enumeration value (e.g. in XtraReports). However, there are still some areas that are not covered by our code and places that we cannot handle properly because of their internal design. Also, with the current approach, we will have to do significant work to migrate these adjustments onto the WPF and SL platforms. We need some time to re-investigate our design, and the .Net Framework design in regard to this issue to find an appropriate solution.