![]() The TextBoxRegex Property allows text validation using a regular expression or using built in validation types. +true = 1 but true shouldn't be considered as "numeric").These extensions have been moved to a different class and refactored with breaking changes, please refer to docs page for the TextBo圎xtensions type. Some time ago I had to implement an IsNumeric function, to find out if a variable contained a numeric value, regardless of its type, it could be a String containing a numeric value (I had to consider also exponential notation, etc.), a Number object, virtually anything could be passed to that function, I couldn't make any type assumptions, taking care of type coercion (eg. I am curious if there is a proper, XAML only way using validation rules, IDataErrorInfo, or some other means to have a binding between the controls without having to hook into the events and manually answer is pretty close, but it will fail in the following cases: // Whitespace strings: I have to manually update the binding, because the event fires before the binding is updated. P2Box.GetBindingExpression(PasswordBoxAssistant.BoundPassword).UpdateSource() OK, so it turns out I mistyped the event handler in the xaml, and the solution actually works: private void PasswordChanged(object sender, RoutedEventArgs e)ī1 = ((PasswordBox)sender).Password I would like have a xaml-only solution, but code behind is perfectly acceptable. This solves the validation problem, but the caret in the passwordbox is always at the very beginning, ruining any data entered. I have tried hopping in during the PasswordChanged event, creating a new PasswordData, and reassigning the binding. Ret = "Password cannot be null or empty." I have a custom class which inherits IDataErrorInfo to allow for validation between the two controls – the binding is a PasswordData object, and the password boxes are set to PasswordData.P1 and PasswordData.P2: public class PasswordData : IDataErrorInfo Or, perhaps it just doesn't work for the attached properties – the code below didn't do anything: P2Box.GetBindingExpression(PasswordBoxAssistant.BoundPassword).UpdateSource() Because of this, I can't find a way to access it in code-behind (since PasswordBox.Password is not a dependency property by itself) in the manner expressed in this solution. My password boxes use the attached property outlined here to allow binding to the password. 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. For example, if the first password is entered as "password", and the user enters "password" into the second box, the validation passes and the button is enabled. My problem is that the user can alter the password in the first box, and it won't force the second password box to re-validate. Validation is used to confirm that both passwords match – if they do, a button is enabled to allow the user to proceed: 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.
0 Comments
Leave a Reply. |