![]() Item.PasswordChanged += (sender, eArg) =>īehavior. If (!behavior.isRoutedEventHandlerAssign) If (item.Password != e.NewValue as string) PasswordBox item = behavior.AssociatedObject as PasswordBox PasswordBoxBehavior behavior = depObj as PasswordBoxBehavior ![]() Static void OnTextChanged(DependencyObject depObj, DependencyPropert圜hangedEventArgs e) Public static readonly DependencyProperty TextProperty =ĭependencyProperty.Register("Text", typeof(string), typeof(PasswordBoxBehavior), new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnTextChanged)) This enables animation, styling, binding, etc. Using a DependencyProperty as the backing store for Text. PasswordBoxBehavior.cs public class PasswordBoxBehavior : Behavior You can have this behavior for PasswordBox to enable binding in MVVM. Is there any alternative (besides something like the PasswordBox Helper that injects binding of course - i'd rather not go that path as there might be a reason i haven't considered for MS to choose not to make it bindable even to a SecureString)? Since PasswordBox.Password isn't bindable, I can only choose to always show it empty or always show a fixed number of '*' (by setting a default Password that doesn't actually represent the real password). So I want to show an empty PasswordBox on the first run but if there's a password set already, when the user returns I want to show X number of '*' (to give indication that there is a password in place. Since this data is saved to disk for future use (in a pasword protected SQL Server CE database file), while on first run there is no password set, if the user comes back and needs to edit the SQL connection for some reason, then there could be a password kept from the previous configuration (unless he used Windows Authentication rather than SQL User Authentication) In that form i'm using a PasswordBox to get the SQL Server user password. ![]() The thing is that you can access the password entered by the user using the Password property, but it’s not a dependency property, and MVVM purists don’t like the fact that they can’t bind it to their ViewModel. The only problem here is that PasswordBox.Password is not a dependency property, and you can't use it in a trigger. I have a XAML form (C#/WPF) where users will configure a database access. In WPF circles, the PasswordBox control has generated quite a bit of discussion. WPF Watermark PasswordBox from Watermark TextBox 29,016 Solution 1 The general approach is the same: write a custom control style, and show the watermark whenever the password box is empty. I'm wondering if this is at all possible with all the security involved with the PasswordBox control:
0 Comments
Leave a Reply. |