views:

53

answers:

1

Hello,

I often use and re-use usercontrols in my apps.

For example, if a user should enter an integer number, I have a usercontrol named "IntegerEditor", which has a label for the title, a textbox for the user input, and a label for the units (inches, seconds, etc...).

My user control already has a validation rule that I called "IntegerValidationRule", which control if the user input is an integer.

I have a style associated with that validation rule that change the control background and add the error message in a tool tip.

Sometimes, I use these kind of basic controls in my UI, but I want to add other validation rules, such as "The integer must be greater than 1023", with special error messages as "UDP Port under 1024 are reserved, please choose a higher number".

Do you know any way that I could add these validations rules somewhere else but that it would still trigger the style on my control? I thought about propagating the validation error down the visual tree, but found nothing great about that on the net.

Thank you for yours answers,

A.Jeanrichard

+1  A: 

Well... you could respond to routed "validation failed" events, but that'd be more difficult IMO than having an application-level ViewModel that's responsible for coordinating validation between different ViewModels.

Randolpho
Hi Randolpho,Thank you for your quick answer.I've never seen any MVVM example with a viewModel responsible for coordinating other viewModels. In fact, I've never seen any MVVM example which include the use of UserControls. Do you know any?That would help much.Regards, Antoine
Antoine Jeanrichard
Each user control is bound to a view model, yes? Your view models are allowed to talk to each other. Have some coordinating view model update the view model that's bound to the trigger.
Randolpho