5
votes

I'm having a problem using custom activities and designers in Workflow Foundation. For the sake of the question, I've created a very simple activity, as shown below:

[Designer(typeof(TesteDesigner))]
public sealed class Teste : CodeActivity
{
    // Define an activity input argument of type string
    [RequiredArgument]
    public InArgument<string> Text { get; set; }

    // If your activity returns a value, derive from CodeActivity<TResult>
    // and return the value from the Execute method.
    protected override void Execute(CodeActivityContext context)
    {
        // Obtain the runtime value of the Text input argument
        string text = context.GetValue(this.Text);
    }
}

And the designer is the following:

<sap:ActivityDesigner x:Class="ActivityDesignerLibrary1.TesteDesigner"
                      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                      xmlns:sap="clr-namespace:System.Activities.Presentation;assembly=System.Activities.Presentation"
                      xmlns:sapv="clr-namespace:System.Activities.Presentation.View;assembly=System.Activities.Presentation"
                      xmlns:System="clr-namespace:System;assembly=mscorlib"
                      xmlns:Converters="clr-namespace:System.Activities.Presentation.Converters;assembly=System.Activities.Presentation">
    <sap:ActivityDesigner.Resources>
        <Converters:ArgumentToExpressionConverter x:Key="ArgumentToExpressionConverter" />
    </sap:ActivityDesigner.Resources>
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition />
            <ColumnDefinition />
        </Grid.ColumnDefinitions>
        <TextBlock Text="Valor: "
                   VerticalAlignment="Center" />
        <sapv:ExpressionTextBox HintText="Valor"
                                Expression="{Binding Path=ModelItem.Text, Mode=TwoWay, Converter={StaticResource ArgumentToExpressionConverter}, ConverterParameter=In}"
                                ExpressionType="{x:Type System:String}"
                                OwnerActivity="{Binding Path=ModelItem}"
                                UseLocationExpression="True"
                                Grid.Column="1"
                                Margin="3,0,0,0" />
    </Grid>
</sap:ActivityDesigner>

When I type something in the TextBox, I get an error: invalid l-value expression, but if I type the value on the property grid, the TextBox is updated.

Has anyone ever seen this?

Thanks.

1
You sure your SSCCE is correct? As it stands, at the time of design, Text will be null, which might cause issues with the ArgumentToExpressionConverter on first go. Try implementing IActivityTemplateFactory within your Activity, set Text equal to a new InArgument<string>, re-create your workflow (drag it from the toolbox onto the design surface!) and see if that fixes your problem. If so, let me know and I'll convert this to an answer with addl details. - user1228
If you want more info about IATF, check out my answers regarding how it works and how its used. - user1228
Text won't be null at design time. If you bind it correctly it won't be null from the time you write something on ExpressionTextBox. Otherwise you wouldn't be able to do validation on CacheMetadata, for example. - Joao

1 Answers

5
votes

Remove UseLocationExpression property from your XAML or turn it to False. The rest of your code seems correct.

Check the property remarks on MSDN:

A location expression (or L-value expression) is a type of expression that evaluates to an identifier and can be placed on the left hand side of an assignment statement. When you are binding the ExpressionTextBox to an Out argument, you would set this property to True.

It's only to be used when you want to bind an OutArgument.