Skip to main content
.NET Framework 4.6.2+

CloneObjectViewController.CustomGetCloneActionTargetTypes Event

Occurs before getting the target types list available via the CloneObjectViewController.CloneObjectAction.

Namespace: DevExpress.ExpressApp.CloneObject

Assembly: DevExpress.ExpressApp.CloneObject.v25.1.dll

Declaration

public event EventHandler<CustomGetCloneActionTargetTypesEventArgs> CustomGetCloneActionTargetTypes

Event Data

The CustomGetCloneActionTargetTypes event's data class is CustomGetCloneActionTargetTypesEventArgs. The following properties provide information specific to this event:

Property Description
Handled Gets or sets a value that indicates whether the event handler has completely handled the event or whether the system should continue its own processing. Inherited from HandledEventArgs.
SourceType Gets the type of the source object to be cloned.
TargetTypes Gets the System.Collections.Generic.Dictionary object that is the collection of target types and their corresponding IModelNode nodes.

The event data class exposes the following methods:

Method Description
GetDefaultTargetTypes() Returns the default target types of the CloneObjectViewController.CloneObjectAction.

Remarks

Handle the CustomGetCloneActionTargetTypes event to add custom target types via the handler’s TargetTypes property. To prohibit adding the default target types, set the handler’s Handled parameter to true.

The CloneObject Action‘s ChoiceActionBase.Items collection includes the current object type and types inherited from the current object’s base class. To get a list of these types in a CustomGetCloneActionTargetTypes handler, use the CustomGetCloneActionTargetTypesEventArgs.GetDefaultTargetTypes method.

The following code prohibits adding descendant types of the current object type’s base type to the Action’s ChoiceActionBase.Items collection:

using DevExpress.ExpressApp.CloneObject;
//...
public class MyCloneObjectController : CloneObjectViewController {
    // ...
    protected override void OnActivated() {
        this.CustomGetCloneActionTargetTypes += 
            MyCloneObjectController_CustomGetCloneActionTargetTypes;
        base.OnActivated();
    }
    private void MyCloneObjectController_CustomGetCloneActionTargetTypes(
        object sender, CustomGetCloneActionTargetTypesEventArgs e) {
        e.Handled = true;
        e.TargetTypes.Clear();
        e.TargetTypes.Add(
            Application.Model.BOModel[View.ObjectTypeInfo.Type.FullName],
            View.ObjectTypeInfo.Type);
    }
}

If you implement this Controller, the CloneObject Action will clone the currently selected object to the object of the same type, because only the Action’s Item will be the current object type. Note, that you subscribe to the CustomGetCloneActionTargetTypes event before XAF calls the base OnActivated method. This is necessary because CustomGetCloneActionTargetTypes is raised from OnActivated. If you want to handle this event from a Controller that is not inherited from the CloneObjectViewController, subscribe in the OnFrameAssigned method.

To manually fill the Items of the CloneObject Action, access this Action in the Controller’s OnActivated method. For more information, refer to the CloneObjectViewController.CloneObjectAction topic.

See Also