none
WF4.0设计时是否可以使用代码添加variable RRS feed

  • 问题

  • 是这样的,我自己rehosted的设计器,在设计时我是否可以通过代码添加删除设计器root activity的variable集合?我自己试过添加后,点击variable区域会报错 
    2014年2月18日 9:08

答案

  • Hi,

    In order to successfully add a variable programmatically, you must get the ModelItem that represents the root item of the workflow, and add the variable to its variables collection. This is deonstrated in the following example.

    ModelService modelService = this.wd.Context.Services.GetService<ModelService>();
    ModelItem mi = modelService.Root;
    if (mi.ItemType.Equals(typeof(Sequence)))
    {
        Variable<int> n = new Variable<int>("n");
        n.Default = 1;
        mi.Properties["Variables"].Collection.Add(n);
    }

    For more information, you can refer here

    #How to Programmatically Add a Workflow Variable when Rehosting the Workflow Designer

    http://social.technet.microsoft.com/wiki/contents/articles/1283.how-to-programmatically-add-a-workflow-variable-when-rehosting-the-workflow-designer.aspx

    Hope it can help you.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place. <br/> Click <a href="http://support.microsoft.com/common/survey.aspx?showpage=1&scid=sw%3Ben%3B3559&theme=tech"> HERE</a> to participate the survey.

    2014年2月19日 2:12
    版主

全部回复

  • Hi,

    In order to successfully add a variable programmatically, you must get the ModelItem that represents the root item of the workflow, and add the variable to its variables collection. This is deonstrated in the following example.

    ModelService modelService = this.wd.Context.Services.GetService<ModelService>();
    ModelItem mi = modelService.Root;
    if (mi.ItemType.Equals(typeof(Sequence)))
    {
        Variable<int> n = new Variable<int>("n");
        n.Default = 1;
        mi.Properties["Variables"].Collection.Add(n);
    }

    For more information, you can refer here

    #How to Programmatically Add a Workflow Variable when Rehosting the Workflow Designer

    http://social.technet.microsoft.com/wiki/contents/articles/1283.how-to-programmatically-add-a-workflow-variable-when-rehosting-the-workflow-designer.aspx

    Hope it can help you.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place. <br/> Click <a href="http://support.microsoft.com/common/survey.aspx?showpage=1&scid=sw%3Ben%3B3559&theme=tech"> HERE</a> to participate the survey.

    2014年2月19日 2:12
    版主
  • Thanks a lot! 
    2014年2月19日 5:49