Validating multiple controls
I would like have a xaml-only solution, but code behind is perfectly acceptable. I am curious if there is a proper, XAML only way using validation rules, IData Error Info, or some other means to have a binding between the controls without having to hook into the events and manually update.
For more complex validation, it is often necessary to push your validation into the View Model, or even the Model in many cases. Here's a link to an excellent article on the subject: may be helpful.
If the user then changes the original password box to "PASSWORD", both boxes stay validated - the original because there are no constraints on a nonempty password, the second because nothing has forced the validation to update.
My password boxes use the attached property outlined here to allow binding to the password.
Controls 'Loops through array of controls If Type Of control Is Text Box Then If control.
I have a form with two password fields - one where the user enters the password, and another where the user has to re-enter that password to confirm.
This is only a simple example and you could take it further by looking at the rest of the control name say txt String Address which would allow you to give more friendly error messages specific to the correct field. Focus() Return False End If End If Next Else If Type Of cnt Is Text Box Then 'check if it should be string If cnt. Starts With("txt String") Then 'check if its valid value If cnt. Text) Then 'if not show error and exit sub Message Box.
Private Function Check Control Validation(By Val cnt As Control) As Boolean Try If Type Of cnt Is Group Box or Type Of cnt Is Panel Then For Each control As Control In cnt. Show("Please enter Numeric Values for Phone Numbers") cnt.
However, I want it, if sign up is clicked, only signup fields get validated and if login is clicked on login fields get validated. Other validator controls belonging to other validation group won’t execute.I see a lot of posts where Data Annotations are used in your model classes.When you bind the model to the context in WPF you may notice validation fires off prior to any data not being entered.Blogging, solving problems at various forums, helping people, keeps him busy entire day.Visit his Blog: Code Wala Area of Expertise : C#, ASP.