ViewModel:
public class MyViewModel
{
[Required, StringLength(50)]
public String SomeProperty { ... }
}
XAML:
The Markup extension is definitely the way to go. I am creating a subclass of BindingDecoratorBase called Binding which has a model DataType dependency property. As MarkupExtensions are created during InitializeComponent() there is no way to determine the DataContext as it will not have been set yet.
Providing the model type permits reflective access to attributes defined on the model. This permits:
The markup looks like: Text="{PO:Binding DataType=model:modAccount, Path=SubAccount}"
Formatting, MaxLength, and Conversion rolled into one package with no need to change anything as the model classes change.