views:

31

answers:

2

Is there some best practice or some recommended way how to validate forms in Silverlight? Right now I have to doall validation in endless nested if else structures and it just doesn't seem like a very reusable and maintainable way of doing this.

If I want to show error messages next to each form element I also have to create an empty text block next to each element which will hold the error in case the field is invalid.

+1  A: 

I would recommand you the Silverlight toolkit, which provides easy to use dataform and entity validation mecanisms.

there are samples describing how to use it, quite a lot of blog posts and a whole (and rather interesting) MSDN magazine article

the dataform is available in the namespace xmlns:dataform="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data.DataForm.Toolkit"

clearly, you need to reference the adequat assemblies in your project (for example System.Windows.Controls.Data.DataForm.Toolkit -pfiou-)

The samples provide code samples, bottom right of the samples browser there is a button which enables code view.

Maupertuis
Hmm, I have installed the toolkit but I cannot see any of its controls in Visual Studio.
Richard Knop
Hmmm When I use VS for interface design, I stay away from the graphical designer, which I find rather performance impaired :p. the dataform is available here xmlns:dataform="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data.DataForm.Toolkit"
Maupertuis
What do you use for design? I am Silverlight newbie, sorry if it's a dumb question.
Richard Knop
I use Blend or I edit the xaml by hand, depending on the graphical complexity of what I am doing. You won't create complex styles and templates in VS, Blend is the tool for this task. But VS can be easier when you do code related things (and you know XAML well enough to know what you are doing). DataForm design is really easy with Blend. it's more tedious in VS.
Maupertuis
Ok. I will get the Blend. Lucky me (I'm still a student), I can get it for free.
Richard Knop
A: 

@Richard Knop

Have a look at FluentValidation on CodePlex! It`s really comfortable to use, extend and works great with Silverlight!

cordellcp3