问题
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