Hello,
This question needs someone familiar with the CollectionControl as well as Workflow.
I'm building a WF Activity which simply executes a stored procedure. The Activity is associated with a WPF Designer that contains the WFT Toolkit CollectionControl. Everything looks fine and dandy, except I am trying to bind the CollectionControl to an InArgument of the Activity.
The WF Activity has a property of
public InArgument<List<System.Data.SqlClient.SqlParameter>> Parameters { get; set; }
I want to edit this InArgument using the CollectionControl on the designer, and in fact the CollectionControl itself seems to work fine. I have written a custom converter to try to get the Items from the CollectionControl and bind them to the InArgument of the Activity, but it doesn't seem to work. I can't get the collection from the CollectionControl and get it over to the InArgument.
The question: I want to edit the list of SqlParameters using the CollectionControl (which seems to work fine in the designer), but how can I get those SqlParameters to be persisted over to the Activity Property?
Much Thanks!
Activity.cs
The Activity defines an InArgument that wants a list of SqlParameters
public class MyCustomActivity: CodeActivity
In the activity designer, the CollectionControl is bound to the ItemsSource, over to the Parameters property of the activity.
<sap:ActivityDesigner.Resources>
//Convert from the activity properties to the designer element
This question needs someone familiar with the CollectionControl as well as Workflow.
I'm building a WF Activity which simply executes a stored procedure. The Activity is associated with a WPF Designer that contains the WFT Toolkit CollectionControl. Everything looks fine and dandy, except I am trying to bind the CollectionControl to an InArgument of the Activity.
The WF Activity has a property of
public InArgument<List<System.Data.SqlClient.SqlParameter>> Parameters { get; set; }
I want to edit this InArgument using the CollectionControl on the designer, and in fact the CollectionControl itself seems to work fine. I have written a custom converter to try to get the Items from the CollectionControl and bind them to the InArgument of the Activity, but it doesn't seem to work. I can't get the collection from the CollectionControl and get it over to the InArgument.
The question: I want to edit the list of SqlParameters using the CollectionControl (which seems to work fine in the designer), but how can I get those SqlParameters to be persisted over to the Activity Property?
Much Thanks!
Activity.cs
The Activity defines an InArgument that wants a list of SqlParameters
public class MyCustomActivity: CodeActivity
{
public InArgument<List<SqlParameter>> Parameters { get; set; }
protected override void Execute(CodeActivityContext context)
{
//stuff
}
}
Activity Designer XamlIn the activity designer, the CollectionControl is bound to the ItemsSource, over to the Parameters property of the activity.
<sap:ActivityDesigner.Resources>
<ResourceDictionary>
<converters:CollectionEditorToSqlParameterListConverter x:Key="sqlParametersConverter"/>
</ResourceDictionary>
</sap:ActivityDesigner.Resources>
<Grid Margin="0,0,0,-162">
<xctk:CollectionControl x:Name="SprocParameters" HorizontalAlignment="Left" Margin="0,28,0,10" Width="668"
IsReadOnly="True" ItemsSource="{Binding Path=ModelItem.Parameters, Mode=TwoWay, Converter={StaticResource sqlParametersConverter}}"/>
</Grid>
Converter//Convert from the activity properties to the designer element
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
var modelItem = value as ModelItem;
if (modelItem != null)
{
var inArgument = modelItem.GetCurrentValue() as InArgument<string>;
if (inArgument != null)
{
var expression = inArgument.Expression;
var literal = expression as Literal<string>;
var csexpression = expression as CSharpValue<string>;
if (literal != null)
return literal.Value;
}
}
return null;
}
//Convert from the designer element to the activity property
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
var itemContent = (string)value;
var csArgument = new Literal<string>(itemContent);
var inArgument = new InArgument<string>(csArgument);
return inArgument;
}