Simple question about Validation

Aug 5, 2011 at 3:06 AM

I'd like to know how to validate (basically a "business rule like" validation type) "out of sequence", I mean outside ValidateFields or ValidateBusinessRules inside my ViewModel.

For example. inside a DataWindow that contains, let's say some kind of data collection where I want to add some objects that must satisfy some preconditions to be added.

Hoy to implement this kind of validations?

I appreciate your help on this topic.

Best Regards.

Aug 5, 2011 at 7:24 AM

depends on a lot of factors. for example,

1) do the models implement the validation? 

2) are you using wpf or silverlight?

3) is the validation on the server?


what we normally do is to validate fields and simple business rules on the model (which are automatically taken over by catel into the vm if you are using the ViewModelToModelAttribute). if that is all ok, we submit the entity to the repository service (which can be the dal, or RIA services, or...). if that returns an error, we simply show that to the user. I think that's the best thing to do, but if you have any other ideas, I would love to hear them.

Aug 5, 2011 at 1:40 PM

Thank you very muche Geert for your answer.

I think that sometimes I work so much time that I stop thinking for a moment before asking something properly :)

But I was thinking about mi question and I like to share my thoughts with you if you allow me...

The typical scenario is something like this...

Let's say we have a DataWindow to send a shopping order... but we want to validate two different things at two different times... for example.

I want to validate that a User put enough information about himself... (for example his address or whatever... ) When you press OK ValidateFields and ValidateBusinessRules are called and that's perfect for this.

But... a moment before that I like to validate something BEFORE adding an item to the shopping cart...

I have two options here... (because I don't want to validate the user's address yet... perhaps we didn't event allow him to enter it...)

. Call a different validation function (I don't like this idea because I have tested and setting a bussines rule  error from the model does not seem to update the InfoBar Control, and it's bad for design consideretions also).

. The second approach ( I like this .. but I'd like your opinion about... ) is either to use a ValidationFields (ValidationBusinessRules) method based on states, so that different validations are made according to the current state. Or, use some kind of dynamic validator inside the functions, for example a dictionary where every key is a state and every entry is a validation rule, and reference it inside the proper functions.. something like:


void ValidateFields()




You know the idea...

I appreciate some feedback from you. Thanks again for your support

Aug 6, 2011 at 11:16 PM

You either have to validate this manually or you can use the Authentication implementation. It allows you to hook custom authentication for commands into Catel to check whether a specific command is allowed. If that is not what you are looking for, you will have to call you custom validator before showing the dialog.

Aug 8, 2011 at 7:08 PM

Is there a way in Catel to ignore a validation, or to be more accurate not to validate a property/control under certain circumstances?

For example.. I have two TextBox controls in my app but I don't want validations to get fired when loosing the focus. I want to delay the validation process until a command is invoked.

Any suggestion?

Thanks for your support...

Aug 8, 2011 at 8:12 PM

In that case, you will need to set the binding update to explicit and update it when the command is executed. Another option is to hold the button state (which *should* represent a state, but let's assume IsButtonClicked (a bad example, you don't want to hold button click states in your vm, but still)).

If the command is executed, set the IsButtonClicked to true. In your validation, only set the field error if IsButtonClicked is true.