Custom Activity Designer: how do I bind a WPF control to an InArgument?

All replies

  • Follow up: in all the binding samples I've found, ExpressionTextBox is used. Is it possible to use a "classic" WPF TextBox?

    Lars Wilhelmsen | Development Lead | KrediNor, Norway | Connected Systems MVP |
    Friday, February 26, 2010 10:24 AM
  • Hi Lars,

    It is definitely possible - you would need some type converter support though.

    You probably should start by using the same binding path as in an ExpressionTextBox: {Binding Path=ModelItem.TheArgument}
    And add in a value converter which can convert between {control's expected type} and {ModelItem wrapping InArgument<T>}.

    One info you might want suggestions for is 'in the converter, how do I create an InArgument?', here's a few options that might work, depending:

    new InArgument<T>(new Microsoft.VisualBasic.Activities.VisualBasicValue<T>("expressionString"));
    new InArgument<T>(new Literal<T>)
    new InArgument<T>(var) - where var is some Variable<T> in your workflow...
    new InArgument<T>(new System.Activities.Expressions.New<T>())

    Friday, February 26, 2010 7:44 PM
  • Hi Tim,

     Ok, I'm trying to implement a IValueConverter for the job, but I'm a bit puzzled:
     If I want to convert an InArgument<string> instance back to a string, I need an ActivityContext instance
     to get the argument value. Is there any way to get the ActivityContext inside the converter? Can it
     be passed as a parameter to the converter from the designer XAML?

    Lars Wilhelmsen | Development Lead | KrediNor, Norway | Connected Systems MVP |
    Saturday, February 27, 2010 7:18 PM
  • Hi Lars,

    ActivityContext only normally exists while an activity (or expression) is executing. I don't think you actually need an ActivityContext unless you want to evaluate the expression, and that isn't something we usually think it makes sense to do inside of the designer.

    For instance if there's an expression "a.Append('x')" it doesn't make much sense to turn it into 'variablevaluex' inside of the designer, and serialize "variablevaluex" because you lose the original expression semantics.

    But - it does make sense to do things like look inside of the InArugment, find the underlying expression, and pull out the definition of the expression, whether it is a literal, a VBValue, etc.

    Monday, March 01, 2010 7:23 PM
  • Although I'm sure you solved this problem already I do have a solution (should anyone need it sometime),


    do not use the Set function of the inArgument and simply cast the value into the constructor as such:


    public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)

           InArgument convertedValue = new InArgument<string>(value as string);

           return convertedValue;


    Hope it helps any


    Monday, March 21, 2011 3:30 PM