locked
Using Calendar control in Custom Activity RRS feed

  • Question

  • Hi, I was wondering if anyone could give a simple answer to my problem.  I want to use a calendar control in a custom activity designer.  I've had no problems in the past loading values into combo boxes and then using an implementation of IValueConverter to convert the bound combobox's  SelectedValueID to a value that appears in the hosted workflow designer's property panel (InArgument).

     

    class

     

     

    CalendarDateTimeConverter : IValueConverter {

     

     

    public Object Convert(Object value, Type targetType, Object parameter, System.Globalization.CultureInfo culture) {

     

     

    ModelItem modelItem = value as ModelItem;

     

     

    if (value != null) {

     

     

    InArgument<DateTime> inArgument = modelItem.GetCurrentValue() as InArgument<DateTime>;

     

     

    if (inArgument != null) {

     

     

    Activity<DateTime> expression = inArgument.Expression;

     

     

    VisualBasicValue<DateTime> vbexpression = expression as VisualBasicValue<DateTime>;

     

     

    Literal<DateTime> literal = expression as Literal<DateTime>;

     

     

    if (literal != null) {

     

     

    return "\"" + literal.Value + "\"";

    }

     

    else if (vbexpression != null) {

     

     

    return vbexpression.ExpressionText;

    }

    }

    }

     

     

    return null;

    }

     

     

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

     

     

    String itemContent = value.ToString();

     

     

    VisualBasicValue<DateTime> vbArgument = new VisualBasicValue<DateTime>(itemContent);

     

     

    InArgument<DateTime> inArgument = new InArgument<DateTime>(vbArgument);

     

     

    return inArgument;

    }

    Using the same approach (above) to get a calendar control's SelectedDate (DateTime) property value into the a DateTime InArgument in my activity however doesn't seem so straightforward.  After selecting a date, the actual value passed is "dd/mm/yyyy hh:mm:ss" and I get the red exclamation mark validation error.. if I then simply open up the property in the hosted designer and delete the hh:mm:ss then it gets accepted..

    IF however within my IValueConvertor methods I try and format the "value" beforehand to remove the hh:mm:ss I then get a different error..  "Conversion from Double to Date requires calling the Date.FromOADate method".. any help gratefully appreciated :)

    Friday, February 25, 2011 12:16 PM

Answers

  • I recreated the exact same error message.

     public Object ConvertBack(Object value, Type targetType, Object parameter, System.Globalization.CultureInfo culture)
        {
          DateTime dateTime = (DateTime)value;
    
    
          String itemContent = dateTime.ToShortDateString();
    
    
          //VisualBasicValue<DateTime> vbArgument = new VisualBasicValue<DateTime>(itemContent);
    
          InArgument<DateTime> inArgument = new InArgument<DateTime>(dateTime);
    
          return inArgument;
    
        }
    

    As you can see, i use the ToShortDateString method to get the date string.

    Even if you replace that call be a constant string, "02/03/2011" for example,
    the property in the property grid in the designer, when focused, will show "02 / 03  / 2011" with spaces - thats why it thinks this is a double.

    Commenting the line of code with VisualBasicValue, and passing instead the actual DateTime value solves this issue.

    • Marked as answer by MFrancois Friday, February 25, 2011 3:54 PM
    Friday, February 25, 2011 2:25 PM

All replies

  • I recreated the exact same error message.

     public Object ConvertBack(Object value, Type targetType, Object parameter, System.Globalization.CultureInfo culture)
        {
          DateTime dateTime = (DateTime)value;
    
    
          String itemContent = dateTime.ToShortDateString();
    
    
          //VisualBasicValue<DateTime> vbArgument = new VisualBasicValue<DateTime>(itemContent);
    
          InArgument<DateTime> inArgument = new InArgument<DateTime>(dateTime);
    
          return inArgument;
    
        }
    

    As you can see, i use the ToShortDateString method to get the date string.

    Even if you replace that call be a constant string, "02/03/2011" for example,
    the property in the property grid in the designer, when focused, will show "02 / 03  / 2011" with spaces - thats why it thinks this is a double.

    Commenting the line of code with VisualBasicValue, and passing instead the actual DateTime value solves this issue.

    • Marked as answer by MFrancois Friday, February 25, 2011 3:54 PM
    Friday, February 25, 2011 2:25 PM
  • Many thanks, that worked just fine.. I take it you also meant to comment out the line..

    String itemContent = dateTime.ToShortDateString();  

    :-)

     

     

    Friday, February 25, 2011 3:56 PM