Piers Lawson

I want to use an inner activity to set the output parameter of the workflow. This seems simple enough with a simple workflow:

<DT:MySequentialWorkflowActivity Response="{ActivityBind Name=child, Path=Message}" ...>
<MyChildActivity x:Name="child" Message="This was read from a child" />
</DT:MySequentialWorkflowActivity >

But how do I optionally bind to different activities

For example if I used an ifElse activity how can I push a property from an Activity within the branch that executed into the output parameter:

<DT:MySequentialWorkflowActivity Response="{ }" ...>
<IfElseActivity x:Name="ifElseActivity1">
<IfElseBranchActivity x:Name="ifElseBranchActivity1" >
<MyChildActivity x:Name="child1" Message="Child1 Executed" />
</IfElseBranchActivity />
<IfElseBranchActivity x:Name="ifElseBranchActivity2" >
<MyChildActivity x:Name="child2" Message="Child2 Executed" />
</IfElseBranchActivity />
</IfElseActivity>

</DT:MySequentialWorkflowActivity >

I guess I cannot use ActivityBind.



Re: Windows Workflow Foundation How to optionally set an output parameter in xaml

Jon Flanders

ActivityBind both properties on the child *to* the property on the workflow. Whichever activity executes will set the property value.




Re: Windows Workflow Foundation How to optionally set an output parameter in xaml

Piers Lawson

Could you update my code above to show how that is done Do you mean put the ActivityBind on the children, or do you mean put two ActivityBinds on the parent

If on the children, how do you set the direction of the bind (i.e. that it is an output binding)





Re: Windows Workflow Foundation How to optionally set an output parameter in xaml

Jon Flanders

Two ActivityBinds - one on each child -both pointing to the same parent property




Re: Windows Workflow Foundation How to optionally set an output parameter in xaml

Piers Lawson

I will try this later, but I'm not sure how it will work. I thought ActivityBinds were one way, i.e. setting an Activity Bind such as:

<MyChildActivity x:Name="child1" Message="{ActivityBind Name=parent, Path=Response}" />

Would set the child1's Message property to the value in the parent's "Response" property. Are you saying that after execution, if MyChildActivity has programaticaly set Message to some other value, that will be pushed into the parent's "Response" parameter





Re: Windows Workflow Foundation How to optionally set an output parameter in xaml

Jon Flanders

Modulo readonly properties - ActivityBind's are two way




Re: Windows Workflow Foundation How to optionally set an output parameter in xaml

Tom Lake - MSFT

As Jon said both custom activities need to bind to the workflow property. You need to set the value of the workflow property in the custom activity¡¯s Execute method like the following:

public partial class MyChildActivity: Activity

{

public MyChildActivity()

{

InitializeComponent();

}

protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)

{

this.Message = string.Format("{0} Executed", this.Name);

return ActivityExecutionStatus.Closed;

}

public static DependencyProperty MessageProperty = System.Workflow.ComponentModel.DependencyProperty.Register("Message", typeof(string), typeof(MyChildActivity));

[Browsable(true)]

[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]

public string Message

{

get

{

return ((string)(base.GetValue(MyChildActivity.MessageProperty)));

}

set

{

base.SetValue(MyChildActivity.MessageProperty, value);

}

}

}

You workflow would look like the following:

<ns0:Workflow1 x:Class="WorkflowConsoleApplication13.MySequentialWorkflowActivity" x:Name="MySequentialWorkflowActivity" Response="{x:Null}" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/workflow" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:ns0="clr-namespace:WorkflowLibrary1;Assembly=WorkflowLibrary1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null">

<IfElseActivity x:Name="ifElseActivity1">

<IfElseBranchActivity x:Name="ifElseBranchActivity1">

<IfElseBranchActivity.Condition>

<CodeCondition Condition="ShouldIRun" />

</IfElseBranchActivity.Condition>

<ns0:MyChildActivity Message="{ActivityBind MySequentialWorkflowActivity,Path=Response}" x:Name="child1" />

</IfElseBranchActivity>

<IfElseBranchActivity x:Name="ifElseBranchActivity2">

<ns0:MyChildActivity Message="{ActivityBind MySequentialWorkflowActivity,Path=Response}" x:Name="child2" />

</IfElseBranchActivity>

</IfElseActivity>

</ns0:Workflow1>