G
Guest
Scenario:
I have a custom activity that has a DependencyProperty. The property type is
a complex object (just an object with some properties, nothing fancy). When I
drag my custom activity onto a workflow I want to ensure the property is
bound to a field in the workflow.
Solution:
I’ve created a custom ActivityValidator to validate the activity. This works
fine for the other DependencyProperty’s that are simple types (e.g. strings).
Problem
My custom validator wont seem to work for the DependencyProperty that
contains a complex object.
Hers my custom validator
public class UpdatePaymentActivityValidator : ActivityValidator
{
public override ValidationErrorCollection Validate(ValidationManager
manager, object obj)
{
UpdatePaymentActivity updatePaymentActivity = obj as UpdatePaymentActivity;
ValidationErrorCollection validationErrors = new ValidationErrorCollection();
if (updatePaymentActivity == null)
{
throw new InvalidOperationException("Parameter obj is not of type : " +
typeof(UpdatePaymentActivity).ToString());
}
Activity parent = updatePaymentActivity.Parent;
if (parent != null)
{
// this validates OK
if (String.IsNullOrEmpty(updatePaymentActivity.Message))
{
validationErrors.Add(new ValidationError("Property Message is not set.", 1));
}
// this next line always fails because Payment is always null.
// Payment is a DependencyProperty on the activity and is a complex object
if (updatePaymentActivity.Payment == null)
{
validationErrors.Add(new ValidationError("Property Payment is not set.", 1));
}
}
return validationErrors;
}
}
The comment in the code indicates the like that always returns null. I can
understand that the value for Payment is going to be null, its not set until
runtime... but how do I check that its bound in the designer to a field in
the workflow? Perhaps by directly accessing something on the static
DependencyProperty of the activity?? Or do I have to create a validator for
the workflow that checks it? What am I missing here?
I have a custom activity that has a DependencyProperty. The property type is
a complex object (just an object with some properties, nothing fancy). When I
drag my custom activity onto a workflow I want to ensure the property is
bound to a field in the workflow.
Solution:
I’ve created a custom ActivityValidator to validate the activity. This works
fine for the other DependencyProperty’s that are simple types (e.g. strings).
Problem
My custom validator wont seem to work for the DependencyProperty that
contains a complex object.
Hers my custom validator
public class UpdatePaymentActivityValidator : ActivityValidator
{
public override ValidationErrorCollection Validate(ValidationManager
manager, object obj)
{
UpdatePaymentActivity updatePaymentActivity = obj as UpdatePaymentActivity;
ValidationErrorCollection validationErrors = new ValidationErrorCollection();
if (updatePaymentActivity == null)
{
throw new InvalidOperationException("Parameter obj is not of type : " +
typeof(UpdatePaymentActivity).ToString());
}
Activity parent = updatePaymentActivity.Parent;
if (parent != null)
{
// this validates OK
if (String.IsNullOrEmpty(updatePaymentActivity.Message))
{
validationErrors.Add(new ValidationError("Property Message is not set.", 1));
}
// this next line always fails because Payment is always null.
// Payment is a DependencyProperty on the activity and is a complex object
if (updatePaymentActivity.Payment == null)
{
validationErrors.Add(new ValidationError("Property Payment is not set.", 1));
}
}
return validationErrors;
}
}
The comment in the code indicates the like that always returns null. I can
understand that the value for Payment is going to be null, its not set until
runtime... but how do I check that its bound in the designer to a field in
the workflow? Perhaps by directly accessing something on the static
DependencyProperty of the activity?? Or do I have to create a validator for
the workflow that checks it? What am I missing here?