Activity Relationships Validation

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

This sample consists of three activities, CreateCity, CreateState, and CreateCountry. CreateCity must be inside a CreateState activity, and CreateState must be inside a CreateCountry activity. For the purpose of this sample, the validation logic is in code for the CreateState activity, and in XAML for the CreateCity activity. Both constraints have the same behavior.

The .NET Framework version 4 provides the following three helper activities that allow the developer to validate relationships between activities:

  • GetParentChain
    Provides the collection of all activities that belong to the parent of the current node
  • GetChildSubtree
    Provides the collection of all activities that belong to the sub-tree of the current node, excluding the current node
  • GetWorkflowTree
    Provides the collection of all activities in the same tree as the current node

In the sample, a ForEach activity is used to walk through the collection returned by GetParentChain. For every element in the collection, its type is compared to CreateCountry (or CreateState if CreateCity is being validated), and when a match is found the result flag is set to true. Finally, an AssertValidation is used to generate a validation error if the result flag is set to false.

To use this sample

  1. Open the ContainmentValidation.sln sample solution in Visual Studio 2010.

  2. Build the solution.

  3. Press CTRL + F5 to launch the program.

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


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: