Partager via


ExpressionTextBox – works on Activity properties too!

So Matt Winkler read my previous post and said hey, what about properties of type Activity<foo>, can’t they be bound to ExpressionTextBoxes too? Snap, I had forgotten about that case. The answer is actually yes, because VisualBasicValue and VisualBasicReference derive from Activity, expressions are then assignable to Activity and then the activity can be scheduled. This is a special case of the property binding. The ExpressionTextBox always generates a VBValue or VBReference and if the returned object is assignable to the property, then the binding is valid and the expression can be serialized.

So for an activity that looks like this:

 namespace WorkflowConsoleApplication3
{
    [Designer(typeof(CodeActivityDesigner1))]
    public sealed class CodeActivity1 : CodeActivity
    {
        public Activity<bool> Foo { get; set; }

        protected override void Execute(CodeActivityContext context)
        {
        }
    }
}

The designer looks like this:

 <sap:ActivityDesigner x:Class="WorkflowConsoleApplication3.CodeActivityDesigner1"
    xmlns="https://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="https://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:s="clr-namespace:System;assembly=mscorlib">

    <Grid>
        <sapv:ExpressionTextBox Expression="{Binding Path=ModelItem.Foo, Mode=TwoWay}"
                                ExpressionType="{x:Type TypeName=s:Boolean}"
                                OwnerActivity="{Binding Path=ModelItem, Mode=OneWay}"/>  
    </Grid>

</sap:ActivityDesigner>

Good catch Matt, thanks. Happy holidays.