MindFusion.Scheduling for Silverlight Programmer's Guide
Project

MVVM Pattern

MindFusion.DataViews for Silverlight incorporates the MVVM pattern. The Model is represented by the user's business model, the View is either the ActivityChart or the ResourceChart and the ViewModel is represented by a set of interfaces abstracting the Model from the View. The ViewModel helps accommodate different custom models to the views and provides several features, such as undo and redo. The ViewModel automatically propagates all changes back to the Model. The general rule of thumb is, that once the ViewModel is established, all changes to the project should be performed through it and not directly through the Model.

The principal interface in the ViewModel is the IProjectViewModel - this is a container of all the objects in the ViewModel, such as activities, dependencies and resources. It provides methods for creating, deleting and managing various objects.

Creating the ViewModel

To create the ViewModel, call the CreateViewModel method of the BaseChart class. This call automatically associates the newly created IProjectViewModel with the BaseChart control through its DataContext property. The CreateViewModel method accepts several IEnumerable arguments, which identify the objects in the Model. In addition, the method accepts several Type object which identify the runtime types of the respective objects in the Model. The later are used by the ViewModel during object creation when it needs to create the corresponding elements in the Model. Not all of the arguments are required. For example the following call is valid and will create a project over a set of activities:

C#  Copy Code

var project = chart.CreateViewModel(activities, null, null, nulltypeof(Activity), null, null, null);

Visual Basic  Copy Code

Dim project = chart.CreateViewModel(activities, Nothing, Nothing, NothingGetType(Activity), Nothing, Nothing, Nothing)

During the creation of the ViewModel several properties are automatically used in order to resolve various properties in the Model and establish a relationship between them and the corresponding properties in the ViewModel. The following table lists these properties grouped by the model object they are related to:

Related Model Object

Property

Activity

ActivityChildrenExpression
ActivityNameExpression
ActivityStartTimeExpression
ActivityEndTimeExpression
ActivityProgressExpression

Resource Allocation

AllocationActivityExpression
AllocationStartTimeExpression
AllocationEndTimeExpression
AllocationProgressExpression
AllocationResourceExpression

Resource

ResourceTitleExpression
ResourceDescriptionExpression

Other ViewModel Objects

There are interfaces in the ViewModel object model, which correspond to the different project elements - activities, dependencies and resources, respectively IActivityViewModel, IDependencyViewModel and IResourceViewModel. Those objects are automatically created from the Model when the IProjectViewModel is initially created and can be accessed from the corresponding properties - Activities, Dependencies, Resources.

For additional information about the individual ViewModel objects, check the dedicated topics - Activities, Dependencies and Resources.