While activity in WF 4 rehosted designer

时光怂恿深爱的人放手 提交于 2019-12-13 01:16:15

问题


I have written a custom activity which contains a simple 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 }" />

In the library, i've added Test property as follows:

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

So, this is the whole thing:

A while and a variable i of type i defined in its scope. I would expect to get back "Test1", "Test2" ... and so on, but instead i get :

So, that variable i is seen as a string and not interpreted as the integer defined in the variables section. I've tried this with a simple property of type string also. Then i thought that InArgument might handle the thing.. i don't know what to do more. Any clues about this?


回答1:


I might need more of your code posting to bb able to help more, and understand fully what you want to achieve. But from the screen shot I can see that your not accessing the Runtime Arguments in the cache meta data method. Subsequently the console writeline method you are calling is interpreting the raw text value rather than correctly evaluating the expression.

Try the following in your code activity

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)); 
        }
}

}



来源:https://stackoverflow.com/questions/29927893/while-activity-in-wf-4-rehosted-designer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!