The Problem SolverWIndows Workflow Foundation
HomeShow ChangesEditPrintRecent ChangesSubscriptionsLost and FoundFind ReferencesRename



20-5-2008 14:29:51

List all versions

Validating Activity Metadata

There are several options for validating properties on a custom activity.

Besides the possibility of using an ActivityValidator as described here we can also use the ValidationOptionAttribute. Now the ValidationOptionAttribute isn't useful all the time and only for a limited set of properties.

First of all the limited set of properties. This will only work for dependency properties defined with DependencyPropertyOptions.Metadata. This makes them metadata and they cannot be changed at runtime, only design time.

The second is the limitation in that is can only enforce a required field. No specific values or even an error tekst.

So using this is a little weird to. With the ValidationOptionAttribute being an attribite the first thing that comes to mind is decorating the property with it. Well that doesn't seem to do anything [].

public string MyMetadataProperty
        return ((string)(base.GetValue(ValidatedActivity.MyMetadataPropertyProperty)));
        base.SetValue(ValidatedActivity.MyMetadataPropertyProperty, value);

No in fact what you need to do is add it to the DependencyProperty constructor like this:

public staticDependencyPropertyMyMetadataPropertyProperty = 
        newAttribute[] { newValidationOptionAttribute ValidationOption.Required) }));

Not very inuitive at all.

I guess the only benefit of this is not having to include a ActivityValidator but as far as I am concerned this is not a big benefit.

Wiki Usage

This wiki site is supposed to be a shared resource. As a shared resource everyone is encouraged to add new content or modify existing content!

Enjoy the WF wiki.

Recent Topics