Share via


Task 2: Create the Workflow Designer Hosting Windows Form

Download sample

In this task, you create the host application that is used in the tutorial. The application consists of a Panel control that will be used to host the Windows Workflow Foundation Designer. Below the Panel control, a TextBox is used to allow a user to input XAML code and to automatically display the results of that code graphically in the workflow designer.

During the rest of the tutorial, you will add the remaining code that is required in order to display the Windows Workflow Designer on your Windows Form.

Note

Although you are encouraged to follow the exercises in a linear manner, it is not required. You can start on this exercise by opening the sample project and proceeding to the steps in the following section.

To create the Windows Form source code file

  1. In your projects directory, create a new file named WFEditForm.

Give it a .cs extension if you are creating a C# application or a .vb extension if you are creating a Visual Basic application.

  1. In your main project file (WFEdit), insert a new ItemGroup element before the Import element at the end of the file.

  2. In the ItemGroup element, add a new Compile element.

  3. Add a new attribute to the Compile element named Include by using the file name that you created in step 1 for the attribute value.

  4. Add a new child element to the Compile element named SubType.

    Give this element the value Form. Your ItemGroup node will appear as follows:

    <ItemGroup>
        <Compile Include="WFEditForm.vb">
          <SubType>Form</SubType>
        </Compile>
    </ItemGroup>
    
    <ItemGroup>
        <Compile Include="WFEditForm.cs">
          <SubType>Form</SubType>
        </Compile>
    </ItemGroup>
    

To add the Windows Form code to the host application

  1. In the WFEditForm source code file, add the following code for the Windows Form application.

    namespace Microsoft.Samples.Workflow.Quickstarts.WFEdit
    {
        using System;
        using System.Collections.Generic;
        using System.ComponentModel;
        using System.Data;
        using System.Drawing;
        using System.Text;
        using System.Windows.Forms;
        using System.Workflow.ComponentModel.Design;
        using System.ComponentModel.Design;
        using System.Workflow.ComponentModel;
        using System.Workflow.Activities;
        using System.IO;
        using System.Xml;
        using System.Workflow.ComponentModel.Serialization;
        using System.Collections;
    
        public class WFEditForm : Form
        {
            private System.ComponentModel.IContainer components = null;
            private System.Windows.Forms.SplitContainer splitContainer1;
            private System.Windows.Forms.TextBox xamlView;
            private System.Windows.Forms.Panel placeHolderPanel;
    
            public WFEditForm()
            {
                InitializeComponent();
            }
    
            protected override void Dispose(bool disposing)
            {
                if (disposing && (components != null))
                {
                    components.Dispose();
                }
                base.Dispose(disposing);
            }
    
            private void InitializeComponent()
            {
                this.splitContainer1 = new System.Windows.Forms.SplitContainer();
                this.placeHolderPanel = new System.Windows.Forms.Panel();
                this.xamlView = new System.Windows.Forms.TextBox();
                this.splitContainer1.Panel1.SuspendLayout();
                this.splitContainer1.Panel2.SuspendLayout();
                this.splitContainer1.SuspendLayout();
                this.SuspendLayout();
                // 
                // splitContainer1
                // 
                this.splitContainer1.Dock = System.Windows.Forms.DockStyle.Fill;
                this.splitContainer1.Location = new System.Drawing.Point(0, 0);
                this.splitContainer1.Name = "splitContainer1";
                this.splitContainer1.Orientation = System.Windows.Forms.Orientation.Horizontal;
                // 
                // splitContainer1.Panel1
                // 
                this.splitContainer1.Panel1.Controls.Add(this.placeHolderPanel);
                // 
                // splitContainer1.Panel2
                // 
                this.splitContainer1.Panel2.Controls.Add(this.xamlView);
                this.splitContainer1.Size = new System.Drawing.Size(736, 620);
                this.splitContainer1.SplitterDistance = 245;
                this.splitContainer1.TabIndex = 0;
                // 
                // placeHolderPanel
                // 
                this.placeHolderPanel.Dock = System.Windows.Forms.DockStyle.Fill;
                this.placeHolderPanel.Location = new System.Drawing.Point(0, 0);
                this.placeHolderPanel.Name = "placeHolderPanel";
                this.placeHolderPanel.Size = new System.Drawing.Size(736, 245);
                this.placeHolderPanel.TabIndex = 0;
                // 
                // xamlView
                // 
                this.xamlView.Dock = System.Windows.Forms.DockStyle.Fill;
                this.xamlView.Location = new System.Drawing.Point(0, 0);
                this.xamlView.Multiline = true;
                this.xamlView.Name = "xamlView";
                this.xamlView.Size = new System.Drawing.Size(736, 371);
                this.xamlView.TabIndex = 1;
                this.xamlView.TextChanged += new System.EventHandler(this.xamlView_TextChanged);
                // 
                // WFEditForm
                // 
                this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
                this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
                this.ClientSize = new System.Drawing.Size(736, 620);
                this.Controls.Add(this.splitContainer1);
                this.Name = "WFEditForm";
                this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Show;
                this.Text = "WFEdit";
                this.splitContainer1.Panel1.ResumeLayout(false);
                this.splitContainer1.Panel2.ResumeLayout(false);
                this.splitContainer1.Panel2.PerformLayout();
                this.splitContainer1.ResumeLayout(false);
                this.ResumeLayout(false);
    
            }
    
            protected override void OnLoad(EventArgs e)
            {
                base.OnLoad(e);
            }
    
            private void xamlView_TextChanged(object sender, EventArgs e)
            {
            }
        }
    }
    

To create the application entry point source file

  1. In your projects directory, create a new file named Program.

  2. Give the file a .cs extension if you are creating a C# application or a .vb extension if you are creating a Visual Basic application.

  3. In your main project file (RulesAndConditions), in the ItemGroup element that you created in the first procedure, add a new Compile element.

  4. Add a new attribute to the Compile element named Include.

    Use the file name that you created in step 1 for the attribute value.

  5. Your final ItemGroup node will appear as follows:

    <ItemGroup>
        <Compile Include="PointOfSaleSimulator.vb">
            <SubType>Form</SubType>
        </Compile>
        <Compile Include="Program.vb" />
    </ItemGroup>
    
    <ItemGroup>
        <Compile Include="PointOfSaleSimulator.cs">
            <SubType>Form</SubType>
        </Compile>
        <Compile Include="Program.cs" />
    </ItemGroup>
    

To add the code for the application entry point

  1. In the Program file that you created in the previous procedure, add the following code to open the Windows Form application when your application starts.

    namespace Microsoft.Samples.Workflow.Quickstarts.WFEdit
    {
        using System;
        using System.Collections.Generic;
        using System.ComponentModel;
        using System.Data;
        using System.Drawing;
        using System.Text;
        using System.Windows.Forms;
        using System.Workflow.ComponentModel.Design;
        using System.ComponentModel.Design;
        using System.Workflow.ComponentModel;
        using System.Workflow.Activities;
        using System.IO;
        using System.Xml;
        using System.Workflow.ComponentModel.Serialization;
        using System.Collections;
    
        public class WFEditForm : Form
        {
            private System.ComponentModel.IContainer components = null;
            private System.Windows.Forms.SplitContainer splitContainer1;
            private System.Windows.Forms.TextBox xamlView;
            private System.Windows.Forms.Panel placeHolderPanel;
    
            public WFEditForm()
            {
                InitializeComponent();
            }
    
            protected override void Dispose(bool disposing)
            {
                if (disposing && (components != null))
                {
                    components.Dispose();
                }
                base.Dispose(disposing);
            }
    
            private void InitializeComponent()
            {
                this.splitContainer1 = new System.Windows.Forms.SplitContainer();
                this.placeHolderPanel = new System.Windows.Forms.Panel();
                this.xamlView = new System.Windows.Forms.TextBox();
                this.splitContainer1.Panel1.SuspendLayout();
                this.splitContainer1.Panel2.SuspendLayout();
                this.splitContainer1.SuspendLayout();
                this.SuspendLayout();
                // 
                // splitContainer1
                // 
                this.splitContainer1.Dock = System.Windows.Forms.DockStyle.Fill;
                this.splitContainer1.Location = new System.Drawing.Point(0, 0);
                this.splitContainer1.Name = "splitContainer1";
                this.splitContainer1.Orientation = System.Windows.Forms.Orientation.Horizontal;
                // 
                // splitContainer1.Panel1
                // 
                this.splitContainer1.Panel1.Controls.Add(this.placeHolderPanel);
                // 
                // splitContainer1.Panel2
                // 
                this.splitContainer1.Panel2.Controls.Add(this.xamlView);
                this.splitContainer1.Size = new System.Drawing.Size(736, 620);
                this.splitContainer1.SplitterDistance = 245;
                this.splitContainer1.TabIndex = 0;
                // 
                // placeHolderPanel
                // 
                this.placeHolderPanel.Dock = System.Windows.Forms.DockStyle.Fill;
                this.placeHolderPanel.Location = new System.Drawing.Point(0, 0);
                this.placeHolderPanel.Name = "placeHolderPanel";
                this.placeHolderPanel.Size = new System.Drawing.Size(736, 245);
                this.placeHolderPanel.TabIndex = 0;
                // 
                // xamlView
                // 
                this.xamlView.Dock = System.Windows.Forms.DockStyle.Fill;
                this.xamlView.Location = new System.Drawing.Point(0, 0);
                this.xamlView.Multiline = true;
                this.xamlView.Name = "xamlView";
                this.xamlView.Size = new System.Drawing.Size(736, 371);
                this.xamlView.TabIndex = 1;
                this.xamlView.TextChanged += new System.EventHandler(this.xamlView_TextChanged);
                // 
                // WFEditForm
                // 
                this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
                this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
                this.ClientSize = new System.Drawing.Size(736, 620);
                this.Controls.Add(this.splitContainer1);
                this.Name = "WFEditForm";
                this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Show;
                this.Text = "WFEdit";
                this.splitContainer1.Panel1.ResumeLayout(false);
                this.splitContainer1.Panel2.ResumeLayout(false);
                this.splitContainer1.Panel2.PerformLayout();
                this.splitContainer1.ResumeLayout(false);
                this.ResumeLayout(false);
    
            }
    
            protected override void OnLoad(EventArgs e)
            {
                base.OnLoad(e);
            }
    
            private void xamlView_TextChanged(object sender, EventArgs e)
            {
            }
        }
    }
    
  2. Build and run the application.

Compiling the Code

For information about compiling your code, see Compiling the Code.

See Also

Concepts

Hosting Workflow Designers

Other Resources

Basic Designer Hosting Sample
Outlook Workflow Wizard Sample
Workflow Monitor Sample
Tracking Profile Designer Sample

Copyright © 2007 by Microsoft Corporation. All rights reserved.
Last Published: 2010-03-04