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 example for ASP.NET). In this example, the DatePropertyEditor is customized to display the calendar and the clock:

本主题介绍如何为 WinForms 应用程序自定义内置 XAF 属性编辑器(请参阅"如何:自定义内置属性编辑器 (ASP.NET)"主题,请参阅有关ASP.NET的类似示例)。在此示例中,自定义了日期属性编辑器以显示日历和时钟:

.

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:

在 WinForms 模块项目中,继承日期属性编辑器类。请注意,您的编辑器应该是公开的。由于此类是 DXPropertyEditor 类后代,因此可以使用存储库项访问其设置。要将自定义应用于在"详细信息视图"和"列表视图"中创建的控件,请重写安装程序存储库项方法。属性编辑器属性应用于实现的属性编辑器,以指定可用于 DateTime 类型属性:

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.

要对特定属性使用实现的属性编辑器,请使用 WinForms 项目中的模型编辑器,并将 IModelCommonMemberViewItem.属性编辑器所需的"自有会员"或"ViewItem"节点的"属性编辑器"设置为自定义日期时间编辑器。

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

请注意,应设置与创建的属性编辑器关联的 Business 类属性值的格式,以便显示 DateTime 值的时间部分

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.

有关详细信息,请参阅设置属性值格式主题。

12-26 13:53