6/27/2023 0 Comments Put content on passwordbox wpf((MyObject)DataContext).SecurePassword = MyPassword. this should trigger binding and therefore validation Private void MyPassword_Changed(object sender, RoutedEventArgs e) MyPassword.SetBinding(SecurePasswordProperty, passwordBinding) you can configure other binding stuff here PasswordBinding.ValidatesOnDataErrors = true Public static readonly DependencyProperty SecurePasswordProperty =ÄependencyProperty.RegisterAttached("SecurePassword", typeof(SecureString), typeof(MyWindow)) ÄataContext = myObject // created somewhereÄ«inding passwordBinding = new Binding(SecurePasswordProperty.Name) Then, the corresponding Window code like this will trigger PasswordBox binding: // add a custom DependencyProperty If (SecurePassword = null || SecurePassword.Length = 0)Īnd a Window Xaml with a PasswordBox like this: this is where I code my custom business rule If (memberName = "SecurePassword" || memberName = null) Private string Validate(string memberName) Let's suppose I have an MVVM object like this, with WPF validation using IDataErrorInfo: public class MyObject : INotifyPropertåhanged, IDataErrorInfo apparently, fantastic! I can bind my PasswordBox with its Password property, so then I can bind with my validation. Because its Password is not bindable due to security reasons, I tried to make a binding following this link (also explained here, for CodeProject users). For making validations I followed this link, that shows how to validate on TextBox. I'm trying to make a validation for a PasswordBox.
0 Comments
Leave a Reply. |