虽然WF 4中的活动重新设计了设计师

时间:2015-04-28 19:10:19

标签: workflow-foundation-4 workflow-foundation workflow-activity

我编写了一个自定义活动,其中包含一个简单的ExpressionTextBox:

       <sapv:ExpressionTextBox HintText="List of Strings" 
        Grid.Row ="0" Grid.Column="1" MaxWidth="150" MinWidth="150" Margin="5"
        OwnerActivity="{Binding Path=ModelItem}"
        Expression="{Binding Path=ModelItem.Test, Mode=TwoWay, 
            Converter={StaticResource ArgumentToExpressionConverter}, 
            ConverterParameter=In }" />

在库中,我添加了Test属性,如下所示:

       public InArgument<string> Test { get; set; }

所以,这就是整个事情:

enter image description here

一段时间和类型i的变量i在其范围内定义。我希望得到“Test1”,“Test2”......等等,但我得到了:

enter image description here

因此,该变量i被视为一个字符串,而不是解释为变量部分中定义的整数。 我用类型字符串的简单属性尝试了这个。然后我认为InArgument可以处理这件事......我不知道该怎么做。关于这个的任何线索?

1 个答案:

答案 0 :(得分:1)

我可能需要更多的代码发布给bb能够提供更多帮助,并充分了解您想要实现的目标。但是从屏幕截图中我可以看到你没有访问缓存元数据方法中的运行时参数。随后,您调用的控制台writeline方法是解释原始文本值,而不是正确评估表达式。

在代码活动中尝试以下操作

using System; 
using System.ComponentModel; 
using System.IO;
using System.Runtime; 
using System.Activities.Validation;
using System.Collections.Generic;
using System.Windows.Markup;
using System.Collections.ObjectModel;
using System.Activities; 

namespace WorkflowConsoleApplication2
{

    public sealed class CodeActivity1 : CodeActivity
    {
        // Define an activity input argument of type string
        [DefaultValue(null)]
        public InArgument<string> Test
        {
            get;
            set;
        }

        protected override void CacheMetadata(CodeActivityMetadata metadata)
        {
            RuntimeArgument textArgument = new RuntimeArgument("Test",    typeof(string), ArgumentDirection.In);
            metadata.Bind(this.Test, textArgument);


            metadata.SetArgumentsCollection(
            new Collection<RuntimeArgument> 
            {
                textArgument,
            });
        }

        // If your activity returns a value, derive from CodeActivity<TResult>
        // and return the value from the Execute method.
        protected override void Execute(CodeActivityContext context)
        {
            Console.WriteLine(this.Test.Get(context)); 
        }
}

}

相关问题