This documentation is archived and is not being maintained.

Programming Model Item Tree

This topic applies to Windows Workflow Foundation 4 (WF4).

This sample demonstrates how to navigate the ModelItem tree using declarative data binding from the Windows Presentation Foundation (WPF) Tree View.

Sample Details

The ModelItem tree is the abstraction that is used by the Windows Workflow Designer infrastructure to expose the data about the underlying instance being edited. The following illustration is a depiction of the various layers of infrastructure within the Workflow Designer.

Workflow Designer Architecture

A ModelItem consists of a pointer to the underlying value, as well as a collection of ModelProperty objects. A ModelProperty object in turn, consists of data such as the name and type of the property and then a pointer to the value, which in turn, is another ModelItem. A value converter is used to manipulate some of the ModelItems returned from a ModelProperty to make them appear correctly in the tree view. The sample then demonstrates how to imperatively program against the ModelItem tree using the imperative syntax, as seen in the following example.

ModelItem mi = wd.Context.Services.GetService<ModelService>().Root;
ModelProperty mp = mi.Properties["Activities"];
mp.Collection.Add(new Persist());
ModelItem justAdded = mp.Collection.Last();
justAdded.Properties["DisplayName"].SetValue("new name");

To use this sample

  1. Open the ProgrammingModelItemTree.sln solution in Visual Studio 2010.

  2. Build the solution by selecting Build Solution from the Build menu.

  3. Press F5 to run the application. The WPF form is then displayed.

  4. Click the Load WF button to load the ModelItem and bind it to the tree view.

  5. Clicking the Change Model Item Tree button executes the preceding code to add an item into the tree and set a property.

Ee662951.Important(en-us,VS.100).gif Note:
The samples may already be installed on your computer. Check for the following (default) directory before continuing.

<InstallDrive>:\WF_WCF_Samples

If this directory does not exist, go to Windows Communication Foundation (WCF) and Windows Workflow Foundation (WF) Samples for .NET Framework 4 to download all Windows Communication Foundation (WCF) and WF samples. This sample is located in the following directory.

<InstallDrive>:\WF_WCF_Samples\WF\Basic\Designer\ProgrammingModelItemTree

See Also

Reference

IValueConverter

Show: