Introduction : Window Workflow can be used to customize the business logic. In this case we just use it to call the WCF service. The standard Activity Library introduced a number of low level activities. These low level activities include Assign, Add to Collection, Clear collection. The Windows Presentation Foundation can be use in two diffrent ways.
  • In code (like normal Widows Forms).
  • In XAML, HTML like code.

Create the Activity Library

Step 1
Open Visual Studio 2010.

  • Select File->New ->Project.
  • Select Activity Library.
ac1.gif

After clicking the OK option, the Activity1.Xaml Window opens.

ac1`.gif

Create a WPF Application :

Step 2 :
Go to Solution Explorer and right-click.

  • Go to Add-> New Item->WPF Application.
  • Write the below code.
  • Add Stack panel with a Main Window.xaml.
wpf1.gif

Panel :

<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<StackPanel>
<Button Content="Run activity2"
HorizontalAlignment="Left" Name="button1"
Margin="20" Click="button1_Click" />
</StackPanel>
</Grid>
</
Window>

Step 3 : Now go to the WPF Application and right-click.

  • Go to Add Reference->.NET.
  • Select System.Activities, ActivityLibrary.
wpf2.gif

Step 4 : Add new Activity for the new WPF Application.

  • Go to Solution Explorer and right-click.
  • Select Add-> New Item->Activity.

Step 5 : Now go to Activity1.xaml option and drag activity from Toolbox.

  • Select Flowchart, WritelLine activity.
  • Define Text Name activtiy2.

wpf3.gif

Step 6 : Now Go to the MaineWindow.xaml.cs option and write the below code.

Code :

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Activities;
using ActivityLibrary7;
namespace WpfApplication1
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
WorkflowApplication _application;

public MainWindow()
{
InitializeComponent();
}
private void button1_Click(object sender, RoutedEventArgs e)
{
_application = new WorkflowApplication(new Activity2());
_application.Run();
MessageBox.Show("my workflow");
}
}
}

Step 7 : Now again go to MaineWindow.xaml option.

  • Add a Click - Event handler to MaineWindow.xaml.cs option.

Event :

private void button1_Click(object sender, RoutedEventArgs e)
{
_application = new WorkflowApplication(new Activity2());
_application.Run();
MessageBox.Show("my workflow");
}

Step 8 : Go to Solution Explorer and right-click.

  • Select WPF project and right-click.
  • Select Set As Start Project.

wpf4.gif

Step 9 : Now Press F5 and run the application.

WPF7.gif

Step 10 : When we click in runactivity2 then a window pops up showing my workflow.

wpf6.gif