This topic describes how to customize a built-in XAF Property Editor. The DatePropertyEditor will be customized to display date and time in the full format. The Property Editor control's dropdown will display the calendar and the clock in the Windows Vista style. The image below shows the resulting Property Editor:
Since the Property Editor inherits from the DatePropertyEditor class, which is the DXPropertyEditor class descendant, its settings can be accessed via the Repository Item. To apply the customization to the controls created both in 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 String type properties:
1: Imports System
2:
3: Imports DevExpress.ExpressApp
4: Imports DevExpress.ExpressApp.Editors
5: Imports DevExpress.ExpressApp.Win.Editors
6: Imports DevExpress.ExpressApp.Model
7:
8: <PropertyEditor(GetType(DateTime), "CustomDateTimeEditor", False)> _
9: Public Class CustomDateTimeEditor
10: Inherits DatePropertyEditor
11: Public Sub New(ByVal objectType As Type, ByVal info As IModelMemberViewItem)
12: MyBase.New(objectType, info)
13: End Sub
14:
15: Protected Overrides Sub SetupRepositoryItem(ByVal item As DevExpress.XtraEditors.Repository.RepositoryItem)
16: MyBase.SetupRepositoryItem(item)
17: DirectCast(item, RepositoryItemDateTimeEdit).VistaDisplayMode = _
18: DevExpress.Utils.DefaultBoolean.[True]
19: DirectCast(item, RepositoryItemDateTimeEdit).VistaEditTime = _
20: DevExpress.Utils.DefaultBoolean.[True]
21: DirectCast(item, RepositoryItemDateTimeEdit).Mask.EditMask = _
22: "MM.dd.yyyy hh:mm:ss"
23: End Sub
24: End Class
25:
we apply the Custom attribute to use the implemented Property Editor for a business object's property, and to specify the property's display format. The Custom attribute specifies the DisplayFormat and PropertyEditorType properties of the Views | DetailView | Items | PropertyEditor node that defines the target property:
1: Imports System
2: Imports System.ComponentModel
3:
4: Imports DevExpress.Xpo
5: Imports DevExpress.Data.Filtering
6:
7: Imports DevExpress.ExpressApp
8: Imports DevExpress.Persistent.Base
9: Imports DevExpress.Persistent.BaseImpl
10: Imports DevExpress.Persistent.Validation
11:
12: <DefaultClassOptions()> _
13: Public Class WinCustomPropertyEditorsObject
14: Inherits BaseObject
15: Public Sub New(ByVal session As Session)
16: MyBase.New(session)
17: ' This constructor is used when an object is loaded from a persistent storage.
18: ' Do not place any code here or place it only when the IsLoading property is false:
19: ' if (!IsLoading){
20: ' It is now OK to place your initialization code here.
21: ' }
22: ' or as an alternative, move your initialization code into the AfterConstruction method.
23: End Sub
24: Public Overrides Sub AfterConstruction()
25: MyBase.AfterConstruction()
26: ' Place here your initialization code.
27: End Sub
28:
29:
30: <[Custom]("DisplayFormat", "MM.dd.yyyy hh:mm:ss")> _
31: <EditorAlias("CustomDateTimeEditor")> _
32: Public Property DateTimeProperty() As DateTime
33: Get
34: Return GetPropertyValue(Of DateTime)("DateTimeProperty")
35: End Get
36: Set(ByVal value As DateTime)
37: SetPropertyValue("DateTimeProperty", value)
38: End Set
39: End Property
40:
41: End Class
[eXpressApp Framework]
No comments:
Post a Comment