XAF-如何修改内置的编辑器(Property Editor)

本示例演示在web/win中给 日期选择控制显示出一个时钟及修改时间的控件。效果如下:

如果你装了XAF在这个路径中已经有了这个示例:

%PUBLIC%\Documents\DevExpress Demos 16.2\Components\eXpressApp Framework\FeatureCenter.

在线也有一个版本: http://demos.devexpress.com/XAF/FeatureCenter/.

 

一、继承属性编辑器
 ASP.NET 模块项目,建个新类出来,继承ASPxDateTimePropertyEditor 
复制代码
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;
        }
    }
}
复制代码

如果是win项目:

复制代码
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;
    }
}
复制代码

 

二、应用这个编辑器

上面的代码写完了,编译一下,重新打开xafml.

找到bo,找到日期型属性,在PropertyEditor中找到CustomDateTimeEditor.

在xafml中设置日期属性的displayformat和editmask

或直接在bo中设置。

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;}

运行项目,去看结果吧!

win的效果如下:
posted @   code first life  阅读(964)  评论(1编辑  收藏  举报
编辑推荐:
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
阅读排行:
· 周边上新:园子的第一款马克杯温暖上架
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· Ollama——大语言模型本地部署的极速利器
· DeepSeek如何颠覆传统软件测试?测试工程师会被淘汰吗?
· 使用C#创建一个MCP客户端
点击右上角即可分享
微信分享提示