We will configure the WPF Grid that will contain the Workflow Designer. Then, We will create the WorkflowDesigner instance
programmatically, and add a Sequence
activity with designer support to it. As a consequence, you will be able to
host the Workflow Designer in the
WPF application.
b . (For Visual Basic
users only) Add a class constructor invoking the initialization of the window.
To do this, add the following Sub New
procedure to the MainWindow class.
Visual Basic
Public Sub New()
InitializeComponent()
End Sub
c . Declare a private member field to hold an instance of the WorkflowDesigner. To do this, add the
following code (shown in bold) to
the Window1 class.
C#
public partial class MainWindow : Window
{
private WorkflowDesigner
wd;
public MainWindow()
{
InitializeComponent();
}
}
Visual Basic
Class MainWindow
Private WithEvents wd
As WorkflowDesigner
Public Sub New()
InitializeComponent()
End Sub
End Class
d . Create an instance of the WorkflowDesigner, add a Sequence activity to it, and place it in middle column of the WPF grid. To do this, add the following AddDesigner method to MainWindow class.
C#
private void AddDesigner()
{
//Create an instance of WorkflowDesigner class
this.wd = new WorkflowDesigner();
//Place the WorkflowDesigner in the middle column of the
grid
Grid.SetColumn(this.wd.View,
1);
//Load a new Sequence as default.
this.wd.Load(new Sequence());
//Add the WorkflowDesigner to the grid
grid1.Children.Add(this.wd.View);
}
Visual Basic
Private Sub AddDesigner()
'Create an instance of WorkflowDesigner class
Me.wd = New WorkflowDesigner()
'Place the WorkflowDesigner in the middle column of the
grid
Grid.SetColumn(Me.wd.View,
1)
'Load a new Sequence as default.
Me.wd.Load(New Sequence())
'Add the WorkflowDesigner to the grid
grid1.Children.Add(Me.wd.View)
End Sub
e . Add
designer support to the Sequence
class by calling the register method of the DesignerMetadata class. This will allow you to drop activities
inside the Sequence activity. To do this, add the following private method to MainWindow class.
C#
private void RegisterMetadata()
{
(new DesignerMetadata()).Register();
}
Visual Basic
Private Sub RegisterMetadata()
Dim dm as New DesignerMetadata()
dm.Register()
End Sub
f. In
the MainWindow class constructor,
add calls (shown in bold) to the
methods declared previously to register the metadata for designer support and
create the WorkflowDesigner.
C#
public MainWindow()
{
InitializeComponent();
this.RegisterMetadata();
this.AddDesigner();
}
Visual Basic
Public Sub New()
InitializeComponent()
Me.RegisterMetadata()
Me.AddDesigner()
End Sub
g . Press CTRL + S to
save the changes.
7 . Set the HostingApplication
project as the startup project. To do this, right-click the HostingApplication
project in Solution Explorer and select Set as StartUp Project.
8 . Press CTRL+F5 to build and run the solution and verify that the Workflow Designer is hosted in the
application window.
|
No comments:
Post a Comment