Skip to main content
A newer version of this page is available. .

How to: Customize a Built-in Property Editor (WinForms)

  • 3 minutes to read

This topic describes how to customize a built-in XAF Property Editor for WinForms applications (refer to the How to: Customize a Built-in Property Editor (ASP.NET) topic to see the similar examples for ASP.NET). In this example, the DatePropertyEditor is customized to display the calendar and the clock:

CustomPropertyEditor2

Note

You can see the code demonstrated here, along with more examples on custom property editors in the Feature Center Demo installed with XAF. The Feature Center demo is installed in %PUBLIC%\Documents\DevExpress Demos 18.2\Components\eXpressApp Framework\FeatureCenter by default. The ASP.NET version of this demo is available online at https://demos.devexpress.com/XAF/FeatureCenter/.

Inherit the Property Editor

In the WinForms module project, inherit the DatePropertyEditor class. Note that your editor should be public. Since this class is the DXPropertyEditor class descendant, its settings can be accessed using the Repository Item. To apply the customization to the controls created in both the Detail View and List View, override the SetupRepositoryItem method. The PropertyEditor attribute is applied to the implemented Property Editor, to specify that it can be used for the DateTime type properties:

using DevExpress.Utils;
using DevExpress.XtraEditors.Repository;
using DevExpress.ExpressApp.Editors;
using DevExpress.ExpressApp.Model;
using DevExpress.ExpressApp.Win.Editors;
//...
[PropertyEditor(typeof(DateTime), false)]
public class CustomDateTimeEditor : DatePropertyEditor {
    public CustomDateTimeEditor(Type objectType, IModelMemberViewItem info) : 
        base(objectType, info) { }
    protected override void SetupRepositoryItem(RepositoryItem item) {
        base.SetupRepositoryItem(item);
        RepositoryItemDateTimeEdit dateProperties = (RepositoryItemDateTimeEdit)item;
        dateProperties.CalendarTimeEditing = DefaultBoolean.True;
        dateProperties.CalendarView = CalendarView.Vista;
    }
}

Use the Customized Property Editor

To use the implemented Property Editor for a specific property, run the Model Editor in the WinForms project and set the IModelCommonMemberViewItem.PropertyEditorType of the required OwnMember or ViewItem node to CustomDateTimeEditor.

Tip

To use the implemented Property Editor for all DateTime properties, set the PropertyEditorAttribute constructor’s defaultEditor parameter to true in the code above. The CompositeView.GetItems<T> method allows you to use a custom Property Editor for all properties instead of the default Property Editor.

Note that the business class’ property value associated with the created Property Editor should be formatted in order to display the time part of the DateTime value

using DevExpress.ExpressApp.Model;
//...
[ModelDefault("DisplayFormat", "{0:MM.dd.yyyy hh:mm:ss}")]
[ModelDefault("EditMask", "MM.dd.yyyy hh:mm:ss")]
public DateTime CreatedOn { get; set;}

For details, refer to the Format a Property Value topic.

See Also