NewObjectViewController.NewObjectAction Property
Stores settings for the New Action.
Namespace: DevExpress.ExpressApp.SystemModule
Assembly: DevExpress.ExpressApp.v24.1.dll
NuGet Package: DevExpress.ExpressApp
Declaration
Property Value
Type | Description |
---|---|
SingleChoiceAction | A SingleChoiceAction object that is the New Action. |
Remarks
The New Action allows users to create new objects of one of the predefined types.
Contents of the Items collection
Available object types come from the Action’s ChoiceActionBase.Items collection.
A Controller populates the Items collection in the UpdateActionState
method. The following platform-specific controllers (NewObjectViewController
descendants) override this method in slightly different ways: WinNewObjectViewController
, WebNewObjectViewController
, and BlazorNewObjectViewController
. This means that you can expect different sets of objects available in the New Action on different platforms.
In general, the following objects can be elements in the Items
collection:
The current View‘s object type (see ObjectView.ObjectTypeInfo) and its descendants.
Use the NewObjectActionItemListMode property to further specify which objects from this group populate the
Items
list.The types from the Application Model‘s IModelCreatableItems node. XAF automatically populates this node with business classes that use the CreatableItemAttribute or DefaultClassOptionsAttribute. You can also add a class to this node in the Model Editor.
In a Windows Forms application, the Controller populates the New Action’s Items
collection with all of the types above.
In an ASP.NET Web Forms application or a Blazor application, the Controller populates the New Action’s Items
collection only with the objects of the current View‘s object type and its descendants.
To create objects of the types from the Application Model’s node in an ASP.NET Web Forms application, use the QuickCreateAction Action.
Information on the New and Quick create Actions is available in the Application Model‘s ActionDesign node. To access it, use the Model Editor.
Modification of the Items collection
You can modify the Items
collection of the New Action and the Quick create Actions for Windows Forms, ASP.NET Web Forms, and Blazor by using one of the following techniques:
Controller / Class | Handle Event / Override Method | Details |
---|---|---|
NewObjectViewController or its descendants |
NewObjectViewController.CollectDescendantTypes event | Fires when XAF extends the list with the current View’s object type and its descendants. |
NewObjectViewController , WinNewObjectViewController or WebNewObjectViewController |
NewObjectViewController.CollectCreatableItemTypes event | Fires when XAF adds types listed in the CreatableItems node. |
Descendant(s) of WinNewObjectViewController , WebNewObjectViewController , or BlazorNewObjectViewController |
NewObjectViewController.UpdateActionState method |
XAF calls this method after it populates the collection with the types listed above. |
Visibility
The New Action is active (visible) under the following conditions:
- The current View is root (see View.IsRoot) or the current View is the “Many” part of the One-to-Many relationship.
- The IModelView.AllowNew property returns
true
. - The
Items
collection contains at least one active item.
An item can be missing in the Items
collection if the Session-specific constructor is missing in the XPO class. An item can be invisible if the applied Security System prohibits creating objects of the corresponding type.
To ascertain why the New Action is currently not active, use the DiagnosticInfo Action. If you need to change the Action’s “active” or “enabled” state in code, use its ActionBase.Active or ActionBase.Enabled properties.
UI Control: Standard Button or Dropdown List
The application can display the NewObjectAction
as a standard button or a drop-down control. The type of the control depends on the value of the ShowItemsOnClick property and the contents of the Action’s Items
collection.
If you set the ShowItemsOnClick property to true
, the application always renders the Action as a drop-down control. You can execute the required action only from the drop-down.
If you set the ShowItemsOnClick property to false
, the application takes into account the contents of the Items
collection and renders the Action as:
- A default button (if the collection contains a single active item)
- A drop-down control (if the collection contains several active items)
You can change the value of the ShowItemsOnClick property in the Model Editor. Go to the ActionDesign | Actions | New node and edit the ShowItemsOnClick property in the Behavior section.
Example
You can access and modify the New Action in code. For example, the code below accesses the NewObjectAction
and adds it to the Quick Access Toolbar:
using DevExpress.ExpressApp;
using DevExpress.ExpressApp.SystemModule;
// ...
public class NewObjectActionController : WindowController {
protected override void OnActivated() {
base.OnActivated();
NewObjectViewController newObjectViewController = Window.GetController<NewObjectViewController>();
if(newObjectViewController != null) {
newObjectViewController.NewObjectAction.QuickAccess = true;
}
}
}