views:

46

answers:

1

How should one handle validation in WPF 4 when there is no binding? Most of the validation doco I am reading seems to be for controls that have bindings.

For example, just a main windows with some text boxes that a user would fill out, and then a button someone would then click on. One could do it manually I guess but wouldn't' there be a WPF approach for this?

(any short code examples would be appreciated)

A: 

I think the most WPF solution would be to create a ViewModel you could bind to, then doing the validation there For example if its a change of password form with an additional "confirm password" field, this won't bind directly to a "user" model with just one password field. So instead create a viewModel with 2 fields "password1" and "password2", databind to these two properties and add representation-specific validation here.

Tom Carver
so apply in a sense the MVC pattern concept to WPF in a sense? but in a sense isn't this kinda creating more plumbing code? Doesn't the XAML mark-up effectively create C# like code behind the scenes that would be a model for the data being captured? (just ramping up on WPF and trying to make sense of things)
Greg