Skip to main content
.NET 6.0+

Type Properties

  • 4 minutes to read

In XAF, properties of the System.Type type can be displayed in a combo box editor that lists the available object types in ASP.NET Core Blazor, WinForms, and ASP.NET Web Forms applications.

Examples

ASP.NET Core Blazor

XAF Type Properties ASP.NET Core Blazor, DevExpress

TypePropertyEditor

Used for Type properties by default.

When you declare a Type property displayed with the help of TypePropertyEditor, apply the System.ComponentModel.TypeConverter attribute to it. In the attribute, pass the type of the converter that returns a collection of values representing data types in the Property Editor. For example, pass a built-in LocalizedClassInfoTypeConverter. It returns values of the Caption property of the corresponding BOModel | <Class> nodes.

If you do not use the TypeConverter attribute for a type property, XAF loads a string representation of found types to the editor’s Items collection.

VisibleInReportsTypePropertyEditor

The editor is inherited from TypePropertyEditor. Used by the Reports V2 Module. It lists the types of business classes that have the VisibleInReports property of the Application Model‘s IModelClass node set to true.

WinForms

XAF Type Properties WinForms

Each Windows Forms Property Editor is available in two forms:

  • A standalone control (displays property value in a Detail View)
  • A repository item (displays property value in a List Editor that supports in-place editing)

TypePropertyEditor

Control: ImageComboBoxEdit editor from the XtraEditors Library.

Repository Item: RepositoryItemImageComboBox item from the XtraEditors Library.

Description:

Used for Type properties by default.

When you declare a Type property displayed with the help of TypePropertyEditor, apply the System.ComponentModel.TypeConverter attribute to it. In the attribute, pass the type of the converter that returns a collection of values representing data types in the Property Editor. For example, pass a built-in LocalizedClassInfoTypeConverter. It returns values of the Caption property of the corresponding BOModel | <Class> nodes.

If you do not use the TypeConverter attribute for a type property, XAF loads a string representation of found types to the editor’s Items collection.

Use Alt + Down Arrow to expand the TypePropertyEditor‘s drop-down window.

VisibleInReportsTypePropertyEditor

Control: ImageComboBoxEdit editor from the XtraEditors Library.

Repository Item: RepositoryItemImageComboBox item from the XtraEditors Library.

Description:

The editor is inherited from TypePropertyEditor. Used by the Pivot Chart Module and Reports V2 Module. It lists the types of business classes that have the VisibleInReports property of the Application Model‘s IModelClass node set to true.

ASP.NET Web Forms

XAF Type Properties ASP.NET Web Forms

Each ASP.NET Web Forms Property Editor includes controls that display a property in a Detail View in View and Edit mode.

ASPxTypePropertyEditor

View mode control: System.Web.UI.WebControls.Label.

Edit mode control: ASPxComboBox editor from the ASPxEditors Library.

Description:

Used for Type properties by default.

When you declare a Type property displayed with the help of TypePropertyEditor, apply the System.ComponentModel.TypeConverter attribute to it. In the attribute, pass the type of the converter that returns a collection of values representing data types in the Property Editor. For example, pass a built-in LocalizedClassInfoTypeConverter. It returns values of the Caption property of the corresponding BOModel | <Class> nodes.

If you do not use the TypeConverter attribute for a type property, XAF loads a string representation of found types to the editor’s Items collection.

To expand the editor’s drop-down window, use Alt + Down Arrow.

ASPxVisibleInReportsTypePropertyEditor

View mode control: System.Web.UI.WebControls.Label.

Edit mode control: ASPxComboBox editor from the ASPxEditors Library.

Description:

The editor is inherited from ASPxTypePropertyEditor. Used by the Pivot Chart Module and Reports V2 Module. It lists the types of business classes that have the VisibleInReports property of the Application Model‘s IModelClass node set to true.

Customize the Types List

Type Property Editors use the LocalizedClassInfoTypeConverter type converter to create the list of values displayed in the editor’s combo box. This converter returns persistent types only. To add all registered non-persistent types to this collection, follow these steps:

  1. Create a custom converter. Inherit LocalizedClassInfoTypeConverter and set the AllowAddNonPersistentObjects field value to true.

    using DevExpress.Persistent.Base;
    // ...
    public class MyLocalizedClassInfoTypeConverter : LocalizedClassInfoTypeConverter {
        public MyLocalizedClassInfoTypeConverter() {
            AllowAddNonPersistentObjects = true;
        }
    }
    
  2. Pass the custom converter to the TypeConverter attribute.

    using System.ComponentModel;
    using DevExpress.Xpo;
    using DevExpress.ExpressApp.Utils;
    // ...
    [ValueConverter(typeof(TypeToStringConverter))]
    [TypeConverter(typeof(LocalizedClassInfoTypeConverter))]
    [Size(SizeAttribute.Unlimited)]
    public Type DataType {
        get { return GetPropertyValue<Type>(nameof(DataType)); }
        set { SetPropertyValue<Type>(nameof(DataType), value); }
    }
    
  3. Override the AddCustomItems method in your custom converter to add specific types to the collection.

    using DevExpress.Persistent.Base;
    // ...
    public class MyLocalizedClassInfoTypeConverter : LocalizedClassInfoTypeConverter {
        // ...
        public override void AddCustomItems(List<Type> list) {
        list.Add(typeof(MyType));
        list.Sort(this);
        base.AddCustomItems(list);
        }
    }
    
  4. Override the GetSourceCollection method to create the entire collection manually.

    using DevExpress.Persistent.Base;
    // ...
    public class MyLocalizedClassInfoTypeConverter : LocalizedClassInfoTypeConverter {
        // ...
        public override List<Type> GetSourceCollection(ITypeDescriptorContext context) {
            List<Type> result = new List<Type>();
            // Populate the type list here.
            return result;
        }
    }
    

Tip

You can see more customization techniques in the How to hide or filter out certain types from the drop-down editor for the System.Type properties KB article.

See Also