This topic describes how to customize a built-in XAF Property Editor for ASP.NET applications (refer to the How to: Customize a Built-in Property Editor (WinForms) topic to see the similar example for WinForms). In this example, the ASPxDateTimePropertyEditor is customized to display the calendar and the clock:
本主题介绍如何为ASP.NET应用程序自定义内置 XAF 属性编辑器(请参阅"如何:自定义内置属性编辑器 (WinForms)"主题,请参阅 WinForms 的类似示例)。在此示例中,自定义 ASPxDateTimePropertyEditor 以显示日历和时钟:
.
Inherit the Property Editor
继承属性编辑器
In the ASP.NET module project, inherit the ASPxDateTimePropertyEditor class. Note that your editor should be public. To customize the Property Editor's control used in the edit mode, override the SetupControl method. To specify that the Property Editor can be used for the DateTime type properties, apply the PropertyEditorAttribute attribute:
在ASP.NET模块项目中,继承 ASPxDateTimePropertyEditor 类。请注意,您的编辑器应该是公开的。要自定义在编辑模式下使用的属性编辑器控件,请重写安装程序控制方法。要指定属性编辑器可用于 DateTime 类型属性,请应用属性编辑器属性:
using System; using System.Web.UI.WebControls; using DevExpress.Web; using DevExpress.ExpressApp.Model; using DevExpress.ExpressApp.Editors; using DevExpress.ExpressApp.Web.Editors.ASPx; //... [PropertyEditor(typeof(DateTime), false)] public class CustomDateTimeEditor : ASPxDateTimePropertyEditor { public CustomDateTimeEditor(Type objectType, IModelMemberViewItem info) : base(objectType, info) { } protected override void SetupControl(WebControl control) { base.SetupControl(control); if(ViewEditMode == ViewEditMode.Edit) { ASPxDateEdit dateEdit = (ASPxDateEdit)control; dateEdit.TimeSectionProperties.Visible = true; dateEdit.UseMaskBehavior = true; } } }
Use the Customized Property Editor
使用自定义属性编辑器
To use the implemented Property Editor for a specific property, run the Model Editor in the APP.NET project and set the IModelCommonMemberViewItem.PropertyEditorType of the required OwnMember or ViewItem node to CustomDateTimeEditor.
要对特定属性使用实现的属性编辑器,请使用APP.NET项目中运行模型编辑器,并将所需的"自有会员"或"ViewItem"节点的"IModelCommonMemberViewItem"类型设置为自定义日期时间编辑器。
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.
有关详细信息,请参阅设置属性值格式主题。