I would like to know if it is possible to declare a workflow parameter and then pass that parameter into a custom activity using xaml. I see that in beta 2 that ParameterDeclaration has been removed so I am unclear if this is possible. This is my current workflow, very simple, i just want to pass in a parameter and assign it to "To"
Thanks
<
SequentialWorkflowActivity x:Class="Microsoft.Samples.Workflow.SequentialWorkflowWithParameters.Workflow1" x:Name="Workflow1" xmlns:ns0="clr-namespace:ActivityLibrary1;Assembly=ActivityLibrary1, Version=3.0.0.0, Culture=neutral, PublicKeyToken=null" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/workflow"><
ns0:Activity2 x:Name="activity21" To="{x:Null}"/></
SequentialWorkflowActivity>

Workflow Parameters and Activity Properties in xaml Beta2
Vittalbabu
This is one way to do it. Another way to do it would be:
1) Maintain your own code compile unit with MemberCreationService. This code compile unit will have the type and all the associated properties, methods etc.
2) Everytime you CreateProperty() or CreateField() update this code compile unit with the relevant information
3) Refresh the type provider with the new code compile unit
Hope this helps!
- Vihang
Brent Snyder
A couple of things,
first: can i declare my workflow parameter in the xaml
second: i tried doing this
<ns0:Activity2 x:Name="activity21" To ="{ActivityBind Name=Workflow1, Path=To}"/>
where I have defined a property "To" of type string in my Workflow1. When i try to compile this i get the following error
Error 115 Could not deserialize member 'To'. Could not set value '{ActivityBind Name=Workflow1, Path=To}' on member 'To' of type 'ActivityLibrary1.Activity2'. Object of type 'System.Workflow.ComponentModel.ActivityBind' cannot be converted to type 'System.String'. C:\Temp Projects\SequentialWorkflowWithParameters\Workflow1.xoml 4 5
I have definded "To" as a property of type string in my custom activity as well. I don't want to assign an ActivityBind object to my Property. I think I have a little problem.
Thanks,
Dorie
meno
Any hints how to update the existing root activity in the designer so it reflects just added properties (so, for instance, after promoting an activity property you can immediately see the newly created workflow property in "Activity Reference..." dialog when binding another property)
I'm thinking about the following:
- after I get CreateProperty() in IMemberCreationService - generate and compile a new root activity class (with the new property added),
- create an instance of the new workflow (serialize old one and deserialize to new one),
- load the new workflow into the designer control.
I have a feeling that the above might result in unpleasent visual effects. Is there any other, better way to update the root activity class Or maybe there is some service used by the binding logic I could implement to alter the way it "sees" properties on the activity classes (something like TypeDescriptionProvider for property grids) so it can see the new properties without actually updating the root activity class
Well, I can always use my own GUI to make bindings but I'd like to avoid this, if possible.
raysblog
Hi Dorie,
You can pass the parameter to the activity using Activity bind
<SequentialWorkflowActivity x:Class="Microsoft.Samples.Workflow.SequentialWorkflowWithParameters.Workflow1" x:Name="Workflow1" xmlns:ns0="clr-namespace:ActivityLibrary1;Assembly=ActivityLibrary1, Version=3.0.0.0, Culture=neutral, PublicKeyToken=null" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/workflow">
<ns0:Activity2 x:Name="activity21" To ="{ActivityBind Name=Workflow1, Path=MyWorkfloaParameter}"/>
</SequentialWorkflowActivity>
This code will bind the workflow parameter 'MyWorkflowParameter' to 'To' property of the activity.
Hope this helps.
Vihang
DevDanS
No you cannot declare the workflow parameter in xaml, but there are two ways way to achieve what you are try to do here.
1) Declare the workflow parameter in the Workflow.xoml.cs file. You can do this using the code snippet provided.
public
static DependencyProperty ToProperty = System.Workflow.ComponentModel.DependencyProperty.Register("To", typeof(string), typeof(Workflow1));[Description("This is the description which appears in the Property Browser")]
[Category("This is the category which will be displayed in the Property Browser")]
[Browsable(true)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
public string To
{
get
{
return ((string)(base.GetValue(Workflow1.ToProperty)));
}
set
{
base.SetValue(Workflow1.ToProperty, value);
}
} 2) Create your own type that derives from SequentialWorkflow and add the workflow parameter to it and compile it. Now create xaml only workflow which has this type as the root and add your activity and set the property using activity bind. For more information on how to do this please take a look at this post
If both the properties are declared as string properties, this should work fine. Try deleting the activity from the workflow, recompiling and adding it again.
Thanks,
Vihang
KiddKane
The idea for a project I'm working on currently is to use WF to let users define workflows with a designer control hosted in our application. Workflows can be then shared/distributed among other users. The trick is that the workflows need to be parametrizable. For example, a user is composing a workflow for, say, sending emails and he promotes the "sender" property of some nested activity to a workflow property. Then, the workflow is given to some other user who opens it our application for execution and he is _prompted_ to enter all necessary parameters ("sender" property here).
How such scenario can be implemented in WF First of all, the workflow property (the one we want to bind to) does not exist on the top-level activity class at design time (typically this would be SequentialWorkflowActivity). I'd like to have the same behavior like in VS.NET when you select <Promote...> for a property - to be asked for a name of a new property to be added to the workflow.
Correct me if I'm wrong. It seems the way to implement the above is basically to compile the designed workflow plus implement IMemberCreationService to add members which are missing (does the default handler for "Promote Bindable Properties" result in invoking of IMemberCreationService ). And then workflows need to be shared as DLLs, not XOML files.
Thanks
Arden
Yes. Only Public properties with getters and setters can be passed as parameters
Yes you are correct. Hitting "Promote Bindable Properties" invokes CreateProperty on IMemberCreationService and emits the code in the code beside file. You will have to do a similar thing and then share the workflow as DLL's.
vgurgov
As I understand, the default TypeProvider class already has some support for serving types dynamically built by CCUs:
public void AddCodeCompileUnit(CodeCompileUnit codeCompileUnit);
public void RefreshCodeCompileUnit(CodeCompileUnit codeCompileUnit, EventHandler refresher);
public void RemoveCodeCompileUnit(CodeCompileUnit codeCompileUnit);
So, I add my CCU (kept in MemberCreationService) to the TypeProvider and then refresh it each time a new property is created.
Question: What the 'refresher' handler is supposed to do I guess I should update the CCU in CreateProperty() just before calling RefreshCodeCompileUnit(...), anyway.