Custom Composite Designers - Workflow Items Presenter

The System.Activities.Presentation.WorkflowItemsPresenter is a key type in the WF designer programming model that allows for the editing of a collection of contained elements. This sample shows how to build an activity designer that surfaces such an editable collection.

This sample demonstrates:

Set up, build, and run the sample

  1. Open the UsingWorkflowItemsPresenter.sln sample solution for C# or for Visual Basic in Visual Studio 2010.

  2. Build and run the solution.

    A rehosted workflow designer application opens, and you can drag activities onto the canvas.

Sample Highlights

The code for this sample shows the following:

  • The activity a designer is built for: Parallel

  • The creation of a custom activity designer with a System.Activities.Presentation.WorkflowItemsPresenter. A few things to point out:

    • Note the use of WPF data binding to bind to ModelItem.Branches. ModelItem is the property on WorkflowElementDesigner that refers to the underlying object the designer is being used for, in this case, our Parallel.

    • The WorkflowItemsPresenter.SpacerTemplate can be used to put a visual to display between the individual items in the collection.

    • WorkflowItemsPresenter.ItemsPanel is a template that can be provided to determine the layout of the items in the collection. In this case, a horizontal stack panel is used.

    This following example code shows this.

    <sad:WorkflowItemsPresenter HintText="Drop Activities Here"
                                  Items="{Binding Path=ModelItem.Branches}">
            <Ellipse Width="10" Height="10" Fill="Black"/>
            <StackPanel Orientation="Horizontal"/>
  • Perform an association of the DesignerAttribute to the Parallel type and then output the attributes reported.

    • First, register all of the default designers.

      The following is the code example.

      // register metadata
      (new DesignerMetadata()).Register();
      ' register metadata
      Dim metadata = New DesignerMetadata()
      ' register custom metadata
    • Then, override the parallel in RegisterCustomMetadata method.

      The following code shows this in C# and Visual Basic.

      void RegisterCustomMetadata()
            AttributeTableBuilder builder = new AttributeTableBuilder();
            builder.AddCustomAttributes(typeof(Parallel), new DesignerAttribute(typeof(CustomParallelDesigner)));
      Sub RegisterCustomMetadata()
         Dim builder As New AttributeTableBuilder()
         builder.AddCustomAttributes(GetType(Parallel), New DesignerAttribute(GetType(CustomParallelDesigner)))
      End Sub
  • Finally, note the use of differing data templates and triggers to select the appropriate template based on the IsRootDesigner property.

    The following is the code example.

    <sad:ActivityDesigner x:Class="Microsoft.Samples.CustomParallelDesigner"
        <DataTemplate x:Key="Expanded">
            <TextBlock>This is the Expanded View</TextBlock>
            <sad:WorkflowItemsPresenter HintText="Drop Activities Here"
                                        Items="{Binding Path=ModelItem.Branches}">
                  <Ellipse Width="10" Height="10" Fill="Black"/>
                  <StackPanel Orientation="Horizontal"/>
        <DataTemplate x:Key="Collapsed">
          <TextBlock>This is the Collapsed View</TextBlock>
        <Style x:Key="ExpandOrCollapsedStyle" TargetType="{x:Type ContentPresenter}">
          <Setter Property="ContentTemplate" Value="{DynamicResource Collapsed}"/>
            <DataTrigger Binding="{Binding Path=IsRootDesigner}" Value="true">
              <Setter Property="ContentTemplate" Value="{DynamicResource Expanded}"/>
      </sad: ActivityDesigner.Resources>
        <ContentPresenter Style="{DynamicResource ExpandOrCollapsedStyle}" Content="{Binding}"/>
    </sad: ActivityDesigner>


The samples may already be installed on your machine. 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.


See also