set a flag to indicate that we're updating the password Private static void HandlePasswordChanged(object sender, RoutedEventArgs e) start listening to its PasswordChanged event when the BindPassword attached property is set on a PasswordBox, Private static void OnBindPasswordChanged(DependencyObject dp, DependencyPropert圜hangedEventArgs e) avoid recursive updating by ignoring the box's changed eventīox.PasswordChanged -= HandlePasswordChanged īox.PasswordChanged += HandlePasswordChanged and when the BindPassword attached property has been set to true only handle this event when the property is attached to a PasswordBox Private static void OnBoundPasswordChanged(DependencyObject d, DependencyPropert圜hangedEventArgs e) Private static readonly DependencyProperty UpdatingPassword =ĭependencyProperty.RegisterAttached("UpdatingPassword", typeof(bool), typeof(PasswordBoxAssistant), new PropertyMetadata(false)) "BindPassword", typeof(bool), typeof(PasswordBoxAssistant), new PropertyMetadata(false, OnBindPasswordChanged)) Public static readonly DependencyProperty BindPassword = DependencyProperty.RegisterAttached( Public static readonly DependencyProperty BoundPassword =ĭependencyProperty.RegisterAttached("BoundPassword", typeof(string), typeof(PasswordBoxAssistant), new PropertyMetadata(string.Empty, OnBoundPasswordChanged)) Result = new ValidationResult(false, this.ErrorMessage) InputString.Length > this.MaximumLength)) String inputString = (value ? string.Empty).ToString() ValidationResult result = new ValidationResult(true, null) Public override ValidationResult Validate(object value, Public class StringRangeValidationRule : ValidationRule Private void Save_CanExecute(object sender, CanExecuteRoutedEventArgs e)īe = (TextBox.TextProperty) īe = (PasswordBoxAssistant.BoundPassword) Private void Save_Executed(object sender, ExecutedRoutedEventArgs e) If (e.Action = ValidationErrorEventAction.Added) Private void Validation_Error(object sender, ValidationErrorEventArgs e) / Interaction logic for MainWindow.xaml I am not able validate Password and Confirm Password match condition. I am using ValidationRule because it will not update source in case of error. Password and Confirm password should match. Password should not be empty - To validate this i am using custom ValidationRule Name should not be empty - To validate this i am using custom ValidationRule What is want is - Enable save button only if all controls have valid value I have a WPF form which has following controls.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |