CloneObjectViewController.CloneObjectAction Property
Gets a SingleChoiceAction Action used to clone persistent objects.
Namespace: DevExpress.ExpressApp.CloneObject
Assembly: DevExpress.ExpressApp.CloneObject.v25.1.dll
NuGet Package: DevExpress.ExpressApp.CloneObject
Declaration
Property Value
Type | Description |
---|---|
SingleChoiceAction | An Action used to clone persistent objects. |
Remarks
This Action enables you to create a clone of the current object as an object of the current type (it requires a single object to be selected). You can clone:
- an object currently selected in a List View
- a Detail View’s current object.
It invokes a Detail View with a new object. Property values of this object are copied from the object that has been cloned. To prohibit copying a specific property value, apply the NonCloneableAttribute attribute to it.
To activate the CloneObject Action for the List and Detail Views of an object type, navigate to the Application Model and set the object type’s IModelClassCloneable.IsCloneable property to true
.
In addition, you can create an object of the class inherited from the current object’s base class. For this purpose, set the base class’ IModelClassCloneable.IsCloneable property to true
.
To change the CloneObjectAction‘s behavior, create a custom View Controller, override the OnActivated
method, and access the CloneObjectViewController Controller and its Action.
The following code deactivates the sibling cloning functionality. Descendant types of the current object’s ancestor do not appear in the Action’s ChoiceActionBase.Items collection:
using DevExpress.ExpressApp.CloneObject;
//...
namespace YourApplicationName.Module.Controllers;
public partial class MyCloneObjectController : ViewController {
//...
protected override void OnActivated() {
base.OnActivated();
CloneObjectViewController cloneObjectController =
Frame.GetController<CloneObjectViewController>();
if (cloneObjectController != null) {
cloneObjectController.CloneObjectAction.Items.Clear();
ChoiceActionItem myItem =
new ChoiceActionItem(View.ObjectTypeInfo.Name, View.ObjectTypeInfo.Type);
myItem.ImageName =
Application.Model.BOModel.GetNode<IModelClass>(View.ObjectTypeInfo.FullName).ImageName;
cloneObjectController.CloneObjectAction.Items.Add(myItem);
}
}
}
If you implement this Controller, the CloneObject Action clones the selected object to the object of the same type because the Action’s Item will be the current object type. To manually fill the Items of the CloneObjectAction, handle the CloneObjectViewController.CustomGetCloneActionTargetTypes event. For more information, refer to the event’s description.
The CloneObject Action is disabled when there are unsaved changes in the current object because the clone process works in a separate Object Space (see BaseObjectSpace). To change this behavior, set the CloneObjectViewController.AllowCloneWhenModified property to true
.
Note
The CloneObjectViewController
adds a handler to the BaseObjectSpace.ModifiedChanged event of the View.ObjectSpace
object. This handler updates the Action’s ActionBase.Enabled property by the “NotModified” key according to AllowCloneWhenModified
and BaseObjectSpace.IsModified values. The “NotModified” key name is defined by the CloneObjectViewController.IsNotModifiedEnabledKey constant.
To determine why the CloneObject Action is currently deactivated or disabled, 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 property, respectively.
Information about the CloneObject Action is available in the Application Model‘s ActionDesign node. To access it, use the Model Editor.