EnumPropertyEditor. Getting Started

In this topic, you will learn how to use the XafariEnumPropertyEditor. We will use an example from the Feature Center demo. We will set the Property Editor to display EnumPropertyEditorObject type objects. Follow the steps described below.

  • Open the existing XAF solution and navigate to the Module Project.
  • Add enumerations MyDaysOfWeek and MyMonthes with Flags Attribute and enumeration Subject to the Module Project. Use the following code:
  • c#
  • VB

[Flags]
public enum MyDaysOfWeek
{
  None,
  [ImageName("1")]
  Monday = 1,
  [ImageName("2")]
  Tuesday = 2,
  [ImageName("3")]
  Wednesday = 4,
  [ImageName("4")]
  Thursday = 8,
  [ImageName("5")]
  Friday = 16,
  [ImageName("6")]
  Saturday = 32,
  [ImageName("7")]
  Sunday = 64,
  [ImageName("8")]
  Holiday = Saturday | Sunday,
  [ImageName("9")]
  WokDays = Monday | Tuesday | Wednesday | Thursday | Friday
}
[Flags]
public enum MyMonthes
{
  None,
  January = 1,
  February = 2,
  March = 4,
  April = 8,
  May = 16,
  Spring = March | April | May,
  June = 32,
  July = 64,
  August = 128,
  Summer = June | July | August,
  September = 256,
  October = 512,
  November = 1024,
  Autumn = September | October | November,
  December = 2048,
  Winter = January | February | December
}
public enum Subject
{
  Biology,
  Chemistry,
  Mathematics
}

<Flags> _
Public Enum MyDaysOfWeek
  None
  <ImageName("1")> _
Monday = 1
  <ImageName("2")> _
Tuesday = 2
  <ImageName("3")> _
Wednesday = 4
  <ImageName("4")> _
Thursday = 8
  <ImageName("5")> _
Friday = 16
  <ImageName("6")> _
Saturday = 32
  <ImageName("7")> _
Sunday = 64
  <ImageName("8")> _
Holiday = Saturday Or Sunday
  <ImageName("9")> _
WokDays = Monday Or Tuesday Or Wednesday Or Thursday Or Friday
End Enum
<Flags> _
Public Enum MyMonthes
  None
  January = 1
  February = 2
  March = 4
  April = 8
  May = 16
  Spring = March Or April Or May
  June = 32
  July = 64
  August = 128
  Summer = June Or July Or August
  September = 256
  October = 512
  November = 1024
  Autumn = September Or October Or November
  December = 2048
  Winter = January Or February Or December
End Enum
Public Enum Subject
  Biology
  Chemistry
  Mathematics
End Enum

  • Implement the EnumPropertyEditorObject business class, which exposes MyDaysOfWeek type, MyMonthes type, and Subject type properties. Use the following code snippet:
  • c#
  • VB

public class EnumPropertyEditorObject : BaseObject
{
  public EnumPropertyEditorObject(Session session)
    : base(session)
  {
  }
  public string LecturerName
  {
    get
    {
      return GetPropertyValue<string>("LecturerName");
    }
    set
    {
      SetPropertyValue<string>("LecturerName", value);
    }
  }
  public MyDaysOfWeek Day
  {
    get
    {
      return GetPropertyValue<MyDaysOfWeek>("Day");
    }
    set
    {
      SetPropertyValue<MyDaysOfWeek>("Day", value);
    }
  }
  public MyMonthes Month
  {
    get
    {
      return GetPropertyValue<MyMonthes>("Month");
    }
    set
    {
      SetPropertyValue<MyMonthes>("Month", value);
    }
  }
  public Subject Subject
  {
    get
    {
      return GetPropertyValue<Subject>("Subject");
    }
    set
    {
      SetPropertyValue<Subject>("Subject", value);
    }
  }
}

Public Class EnumPropertyEditorObject
  Inherits BaseObject
  Public Sub New(ByVal session As Session)
    MyBase.New(session)
  End Sub
  Public Property LecturerName As String
    Get
      Return GetPropertyValue(Of String)("LecturerName")
    End Get
    Set
      SetPropertyValue(Of String)("LecturerName", value)
    End Set
  End Property
  Public Property Day As MyDaysOfWeek
    Get
      Return GetPropertyValue(Of MyDaysOfWeek)("Day")
    End Get
    Set
      SetPropertyValue(Of MyDaysOfWeek)("Day", value)
    End Set
  End Property
  Public Property Month As MyMonthes
    Get
      Return GetPropertyValue(Of MyMonthes)("Month")
    End Get
    Set
      SetPropertyValue(Of MyMonthes)("Month", value)
    End Set
  End Property
  Public Property Subject As Subject
    Get
      Return GetPropertyValue(Of Subject)("Subject")
    End Get
    Set
      SetPropertyValue(Of Subject)("Subject", value)
    End Set
  End Property
End Class

  • Add XafariModule and XafariEditorsModule to the Module Project.
  • Add XafariWebModule and XafariEditorsWebModule to the ASP.NET Web Module Project.
  • Add XafariWinModule and XafariEditorsWinModule to the Windows Forms Application Project.
  • Invoke the Model Editor. Navigate to the BOModel|Xafari.FeatureCenter.Editors|EnumPropertyEditorObject|OwnMembers node and set the PropertyEditorType property to "Xafari.Editors.Win.WinEnumPropertyEditor" ("Xafari.Editors.Web.ASPxXafariEnumPropertyEditor" for the ASP.NET application). Set the same value for the Month and Subject nodes.  The Day node is shown in the figure below.

enum_property_editor_2

  • Navigate to the Views|Xafari.FeatureCenter.Editors|EnumPropertyEditorObject_DetailView|Items|Day node and set the EnumViewType property to the "CheckedListBox", as shown in the figure below.        

enum_property_editor_3

  • Navigate to the Month item and set the EnumViewType property to the "CheckedComboBox"; set the ColumnsCount property to 2.
  • Run the application (whether Windows Forms or ASP.NET) and select the EnumPropertyEditorObject item in the navigation control.

ASP.NET:

enum_property_editor_4