WF4实例对象转化成XAML文档

本文介绍了如何在Microsoft Windows Workflow Foundation中创建工作流实例,并将其转换为XML格式的过程,包括创建项目、编写代码、实例化工作流、主机工作流以及将工作流实例转换为XML字符串的操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

示例来自Microsoft Windows Workflow Foundation 4.0 Cookbook P29

1.  Create a workfow project:
Create a new Workfow Console Application under the Chapter01 solution and
name the project ConvertWFInstanceToXML. Delete the Workflow1.xaml fle
that is created by default.
2.  Write code to create the workfow and its host:
Open Program.cs fle and change the code as follows:
using System;
using System.Activities;
using System.Activities.Statements;
using System.Text;
using System.Xaml;
using System.Activities.XamlIntegration;
using System.IO;
namespace ConvertWFObjectToXML {
    class Program {
        static void Main(string[] args) {
            //Create a Workflow instance object             
ActivityBuilder ab = new ActivityBuilder();
            ab.Implementation = new Sequence()
            {
                Activities =
                {
                    new WriteLine{Text="Message from Workflow"}
                }
            };
            //Convert Workflow instance to xml string
            StringBuilder sb = new StringBuilder();
            StringWriter sw = new StringWriter(sb);
            XamlWriter xw =
                ActivityXamlServices.CreateBuilderWriter(
                new XamlXmlWriter(sw,
                                  new XamlSchemaContext()));
            XamlServices.Save(xw, ab);
            Console.WriteLine(sb.ToString());
        }
    }
}
 

转载于:https://www.cnblogs.com/Rising/archive/2012/09/11/2679741.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值