10/11/2012

Building a Composite Activity Designer part(4 - 4)

Part 4  Adding a TextBox to the Workflow Designer

We will add a TextBox control to the hosted Workflow designer that will serve as a XAML code viewer. This will allow us to see the XAML source code as the workflow is edited.

  1. Open Microsoft Visual Studio 2010 from Start | All Programs | Microsoft Visual Studio 2010 | Microsoft Visual Studio 2010.
  2. Open the project from last post Building a Composite Activity Designer part(3 - 4).
  3. Add the TextBox to the designer window. To do this, open MainWindow.xaml in the XAML editor and replace the current element with the following code (shown in bold).
    XAML
    <Window ...>
      <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="4*" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <Grid Name="grid1">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="1*" />
                <ColumnDefinition Width="4*" />
                <ColumnDefinition Width="1*" />
            </Grid.ColumnDefinitions>
        </Grid>
        <TextBox Grid.Row="1" Height="250" Name="textBox1" VerticalScrollBarVisibility="Visible" />
        </Grid>
    </Window>
  4. Wire up the ModelChanged event from the Workflow Designer to force it to write the current XAML to its buffer (WorkflowDesigner.Text property). To do this, in Solution Explorer right-click MainWindow.xaml and select View Code. Add the following method to MainWindow class:
    C#
    private void AddXamlTextBox()
    {
        wd.ModelChanged += ((s, e) => wd.Flush());
    }

    Visual Basic
    Private Sub AddXamlTextBox()
        AddHandler wd.ModelChanged, (Sub(s, e) wd.Flush())
    End Sub
  5. Call the method from the MainWindow constructor. To do this, add the following code (shown in bold) to the constructor:
    public MainWindow()
    {
        InitializeComponent();

        this.RegisterMetadata();
        this.AddDesigner();
        this.AddToolBox();
        this.AddXamlTextBox();
        this.AddPropertyInspector();
    }

    Visual Basic
    Public Sub New()
        InitializeComponent()
        Me.RegisterMetadata()
        Me.AddDesigner()
        Me.AddToolBox()
        Me.AddXamlTextBox()
        Me.AddPropertyInspector()
    End Sub
  6. Set the HostingApplication project as startup project. To do this, right-click HostingApplication project in Solution Explorer and select Set as StartUp Project.
  7. Press CTRL+F5 to run the application.
  8. Drag a MyTryCatchFinally activity from the Toolbox and drop it in the Sequence designer surface.
    Adding a TryCatchFinally activity
    Adding a TryCatchFinally activity
    1. Drag two Prompt activities from the Toolbox and use them as Try and Finally activities respectively.
      Adding Prompt activities
      Adding Prompt activities
        Note: Notice that the workflow XAML is being displayed in the TextBox at the bottom of the window.
      1. Remove the TryCatchFinally activity. To do this, click over the activity surface and press Delete.
      2. Drag a PrePostSequence activity from the Toolbox and drop it into the empty sequence.
        Adding a PrePostSequence activity
        Adding a PrePostSequence activity
      3. Drag and drop Prompt activities into the Pre and Post sections of the PrePostSequence activity.
        Adding Pre and Post Activities
        Adding Pre and Post Activities
        1. Drag several Prompt activities into the Activities section of the PrePostSequence activity.
          Adding Activities
          Adding Activities
          1. Close the window to end this verification.

          No comments:

          Post a Comment