views:

83

answers:

1

Hi,

I'm a complete beginner at WPF.

I've made a usercontrol "labeledTextbox" that holds a label, a textbox and a textblock for errormessages.

When the user hits the submit button, I call SomeValidationMethod() to validate the user input. When one of the textboxes contain invalid data, I pass the errormessage to the corresponding usercontrol which in his turn shows it to the user.

I come from the webworld where the page gets refreshed every postback which means you only have to worry about setting the errormessages when an error occured. But in WPF, you also have to clear the errormessages when the error was corrected.

I'm looking for a way in WPF to somehow clear all errormessages on the page. Then I can call SomeClearAllErrorsMethod() at the top of my SomeValidationMethod().

So I guess I need the following:

  • A way to get the collection of labeledTextbox usercontrols on the page
  • A way to iterate the collection so I can set the ErrorMessage property to null for each labeledTextbox usercontrol

But, I'm also wondering if there is a more elegant, best-practice way of doing what I'm trying to accomplish.

Thanks for all info

+1  A: 

Oh dear, you're doing this in a very un-WPF way (though not atypical for someone who's learning WPF so don't feel bad) - any time you end up write an "UpdateXXXX" function where you're fiddling with controls' properties, it usually means you should be using Data Binding instead. In your specific case, you probably want to check out WPF Validation (http://www.codeproject.com/KB/WPF/wpfvalidation.aspx).

Paul Betts
hehe.. thanks for the link
Thomas Stock