【问题标题】:While activity in WF 4 rehosted designer虽然 WF 4 中的活动重新托管了设计器
【发布时间】:2015-04-28 19:10:19
【问题描述】:

我编写了一个自定义活动,其中包含一个简单的 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; }

所以,这就是全部:

在其作用域中定义了一个类型为 i 的变量 i。我希望得到“Test1”,“Test2”......等等,但我得到了:

因此,变量 i 被视为字符串,而不是变量部分中定义的整数。 我也尝试过使用字符串类型的简单属性。然后我认为 InArgument 可能会处理这件事..我不知道该怎么做。有什么线索吗?

【问题讨论】:

  • 你能把你所有的代码都加进去吗?
  • @DotNetHitMan。我刚刚在这里发现了一个类似的问题:stackoverflow.com/questions/8350154/…。正如 Ron Jacobs 当年所说,这是不可能的。我不确定是否有任何新功能,但对我来说,它仍然无法正常工作。

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


【解决方案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)); 
        }
}

}

【讨论】:

  • 哇,这成功了。非常感谢。我现在要休息一下,喝杯咖啡庆祝一下。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-06-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多