简单的应用程序使用Windows工作流和winforms不是控制台
我正在寻找一个简单的初学者应用程序,允许您键入一个值1 - 10此值传递给一个WF规则,如果它是更大,小于或等于5并将结果返回到窗体应用程序,该应用程序将结果显示在标签中。简单的应用程序使用Windows工作流和winforms不是控制台
我可以找到很多.net 3.5控制台应用程序教程,但没有显示如何传入并接收使用Windows窗体和.net 4的结果!
它不需要是上面的例子,但它需要告诉我如何将值传递给规则,编写规则并从规则中读取规则从.net中的Windows窗体应用程序4 c# 。
我迷路了!
我的基本代码现在工作的情况下它可以帮助别人:
var workflow = new Activity1();
IDictionary<string, object> inputs = new Dictionary<string, object>();
inputs["firstname"] = textBox1.Text;
IDictionary<string, object> outputs = WorkflowInvoker.Invoke(workflow, inputs);
textBox2.Text= outputs["greeting"].ToString();
名字是在传给工作流动方向的争论。 问候语是在工作流程中分配方向的参数。
这里如下我实现这一目标的方法:
1)创建一个Windows窗体称为WindowsFormsApplication7应用程序,使用最新的框架。
2)确保包括所有引用
3)添加班级用下面的代码。在形式
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Diagnostics;
using System.Threading;
using System.IO;
using System.Timers;
using System.Reflection;
using System.Activities;
using System.Activities.Statements;
namespace WindowsFormsApplication7
{
public class UpdateLabel : CodeActivity
{
Action y;
public InArgument<Label> lbl { get; set; }
public InArgument<string> text { get; set; }
protected override void Execute(CodeActivityContext context)
{
((Label)context.GetValue(lbl)).Invoke(y =() => ((Label)context.GetValue(lbl)).Text = context.GetValue(text).ToString());
}
}
}
4)双击和与这一个替换的代码。不要介意错误。它们将消失。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Diagnostics;
using System.Threading;
using System.IO;
using System.Timers;
using System.Reflection;
using System.Activities;
using System.Activities.Statements;
namespace WindowsFormsApplication7
{
public partial class Form1 : Form
{
Action y;
WorkflowApplication HomeCycleWFApp = null;
AutoResetEvent HomeEvent = null;
Dictionary<string, object> inArgs = new Dictionary<string, object>();
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
label1.Text = "";
}
private void button1_Click(object sender, EventArgs e)
{
RunHomeCycle(label1, textBox1.Text);
}
public void RunHomeCycle(Label lbl, string txt)
{
button1.Enabled = false;
if (!inArgs.ContainsKey("lbl"))
{
inArgs.Add("lbl", lbl);
}
if (!inArgs.ContainsKey("txt"))
{
inArgs.Add("txt", txt);
}
else
{
inArgs["txt"] = txt;
}
HomeEvent = new AutoResetEvent(false);
HomeCycleWFApp = new WorkflowApplication(new Activity1(), inArgs);
HomeCycleWFApp.Completed = delegate (WorkflowApplicationCompletedEventArgs e)
{
button1.Invoke(y =() => button1.Enabled = true);
HomeEvent.Set();
};
HomeCycleWFApp.Run();
}
}
}
5)将以下控件添加到窗体
LABEL1,TextBox1中和button1的
6)添加称为Activity1.xaml
7)编译解决方案(F6)。的UpdateLabel活动,如在Class1的(公共类UpdateLabel:CodeActivity)描述必须存在于工具箱
8)从工具箱,将UpdateLabel和的WriteLine活动纳入活性1
9)以下参数LBL(标签),TXT(串)添加到活动1
10)在UpdateLabel活动,按F4(属性)点击一次,更新活动的参数如图所示
11)按F5编译并运行应用程序。在文本框中插入一些文本,然后按按钮。文本必须显示在标签中,由Activity1更新,并在输出窗口中由WriteLine活动更新
12)恭喜!!!
你到目前为止编码了什么...? – MethodMan 2011-12-15 17:17:56
+1好问题,wf4需要更多的爱。然而,sl msdn vidz很好。 – 2012-07-25 00:44:15