locked
How to add "validation" errors to custom Activity Designer? RRS feed

  • Question

  • I've created a custom Activity Designer control that derives from ActivityDesigner.  I've completed retemplated the control and am drawing my own borders and creating my own title bar.  Obviously because of this, the regular little red "error icon" that appears when there are validation errors for an activity does not appear.

    Does anyone have any suggestions for how to access the validation errors?  I have my own Image I can show with a tooltip, but I'm not sure what event or method to tap into from within the ActivityDesigner control in order to show the validation message.

    Tuesday, August 24, 2010 7:05 PM

Answers

  • It's not a proper stable public API but you can use WPF binding against AttachedProperties set by validation service on the ModelItem. I just can't remember the name of the attached property. Every time it comes up I have to look it up in Reflector...

    here it is - in ValidationService.OnAttachedPropertiesServiceAvailable two properties are registered:

    "ValidationState" (Type: System.Activities.Presentation.Validation.ValidationState [enum])

    and

    "ValidationMessage" (Type: string)

    You can bind to them by e.g. {Binding Path=ModelItem.ValidationMessage}, you will probably want to add some appropriate converters etc.

    Tim

    • Marked as answer by Kofoed Wednesday, August 25, 2010 3:39 PM
    Wednesday, August 25, 2010 3:48 AM

All replies

  • You can get ValidationService out of EditingControl.Services and hook ValidationService.ValidationCompleted event.

    Wednesday, August 25, 2010 2:00 AM
  • It's not a proper stable public API but you can use WPF binding against AttachedProperties set by validation service on the ModelItem. I just can't remember the name of the attached property. Every time it comes up I have to look it up in Reflector...

    here it is - in ValidationService.OnAttachedPropertiesServiceAvailable two properties are registered:

    "ValidationState" (Type: System.Activities.Presentation.Validation.ValidationState [enum])

    and

    "ValidationMessage" (Type: string)

    You can bind to them by e.g. {Binding Path=ModelItem.ValidationMessage}, you will probably want to add some appropriate converters etc.

    Tim

    • Marked as answer by Kofoed Wednesday, August 25, 2010 3:39 PM
    Wednesday, August 25, 2010 3:48 AM
  • Excellent, thanks!
    Wednesday, August 25, 2010 3:39 PM