Skip to main content
.NET Framework 4.5.2+

CreatableItemAttribute Class

Specifies whether a class will have a corresponding item in the New Action’s item list.

Namespace: DevExpress.Persistent.Base

Assembly: DevExpress.ExpressApp.v24.1.dll

NuGet Package: DevExpress.ExpressApp

Declaration

[AttributeUsage(AttributeTargets.Class | AttributeTargets.Interface, Inherited = false)]
public class CreatableItemAttribute :
    Attribute

Remarks

Each application built via the XAF has the New Action by default. This Action allows end-users to create objects of one of the types listed in the drop-down menu:

CreatableItemAttribute

Note that the first item in this list is the type of objects currently listed in a View. This item is added automatically. So, this item cannot be disabled by applying the CreatableItem(false) attribute to the corresponding business class. The remaining items are added from the Application Model‘s IModelCreatableItems node. This node’s items are created either manually via the Model Editor or in code via the CreatableItem attribute applied to the required business class. The attribute’s CreatableItemAttribute.IsCreatableItem property must be set to true.

If the CreatableItemAttribute.IsCreatableItem property is set to false, or if this attribute is not applied, the New Action item list will not have the corresponding item. However, if a user has the permissions required to create objects of a particular type and the currently active View is of this type, the New Action will still have the automatically added item. In this case, the user will still be able to create objects of this type via the New Action. You can, however, set the Application Model‘s IModelView.AllowNew property for the required Views | <ListView> or DetailView node to false. In this instance, the New Action will not be available.

In the example below, the CreatableItem attribute, with its IsCreatableItem property set to true, by default, is applied to the TestContact class. As a result, the Test Contact item is added to the New Action’s list (see the image above). This allows end-users to create TestContact objects, no matter what View is currently displayed.

[CreatableItem]
public class TestContact : BaseObject {
   public virtual string Name { get; set; }
}

// Make sure that you use options.UseChangeTrackingProxies() in your DbContext settings.

When you need to apply the NavigationItemAttribute and VisibleInReportsAttribute attributes, in addition to the CreatableItem attribute, it is easier to apply a single DefaultClassOptionsAttribute attribute.

Inheritance

Object
Attribute
CreatableItemAttribute
See Also