文章出處

本示例演示在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的效果如下:

文章列表


不含病毒。www.avast.com
arrow
arrow
    全站熱搜
    創作者介紹
    創作者 大師兄 的頭像
    大師兄

    IT工程師數位筆記本

    大師兄 發表在 痞客邦 留言(0) 人氣()