Activities are represented in the object model by the IActivityViewModel interface. The root activities in the project hierarchy can be obtained from the Activities property of the IProjectViewModel. The subactivities of an activity can be accessed through its Subactivities property.
New activities can be created by calling the CreateActivity method. The first argument specifies the parent activity, the second argument specifies the 0-based position in the parent's children list where the new activity should be added. To create a root activity, pass null (Nothing in Visual Basic) as the first argument. Creating a new activity through the ViewModel is automatically reflected back to the Model if the Model implements the IList interface. The type of the newly created Model activity is specified by the ActivityType property of the project.
The following sample code creates and initializes a new activity in an existing project:
C# Copy Code |
---|
var activity = project.CreateActivity(null, -1); |
Visual Basic Copy Code |
---|
Dim activity = project.CreateActivity(Nothing, -1) |
Activities are deleted through the RemoveActivity method. Activity deletion is automatically reflected back to the Model if the Model implements the IList interface.
Activities can be modified through the properties exposed by the IActivityViewModel interface. All modifications to the activities are automatically reflected back to the Model through the binding expressions used to establish the mapping between the ViewModel and Model properties. For additional information about those binding expressions, check the Project topic.
All of the above operations are undoable. Check Undo and Redo for additional information.