I see this as having (at least) 2 advantages: This means we would need to ensure these stay in sync.Īnother approach could be to wrap the PasswordBox inside of a custom control (e.g. And since ControlTemplates cannot be extended/modified (but only overridden) in a style, we would effectively create a copy of the default PasswordBox style and add in the reveal button (and TextBox for editing the revealed password). We would need to replicate these 4 in a "reveal flavor". What nags me a bit about this approach is that we have 4 different PasswordBox styles today: default, floating-hint, filled, and outlined (the three latter are derived styles). Sorry about the long response below I agree to the opt-in part of this. I don't know if it would be within the MDIX purview to add a non-password "password box" ( UnsecurePasswordBox maybe?) that explicitly makes the choice not to use the SecureString scheme that PasswordBox uses and be more MVVM friendly. This "hack" lets me using a single binding and its 100% MVVM compatible. In their Home app to setup the Wifi network, they mask it by default but don't require any authentication to unmask the password. I really don't think for most of my needs I really need to visually hide the password, but that seems to be the common interface Google uses. character and that seems to do what I want.A password font is one that replaces all codepoints with a My latest "hack" to do what I want with as little effort as possible is to use a single textbox and swap between a password and standard font. (As a side note, Dotnet even recommends against using SecureString since it doesn't do anything except implement IDisposable on anything but Framework). Like mentioned whether that is secure or not is another discussion. And generally, PasswordBox (at least in my experience of it) breaks the MVVM paradigm and generally makes my life more difficult for some vague notion of "security". As for validation, that should "just work" with regular binding validation once there is a simple string attached property to bind to.įor my specific use case, we rarely need a proper SecureString.But having this property allows people to change it, or toggle it based on revealed state if that is desired. For now, the icon can simply default to the standard "eye" (like in the screenshots above). I would add properties PasswordBoxAssist class with several attached properties, a boolean indicating if we are in a revealed state or not, and one for the reveal icon ( PackIconKind enum).It should be something that consumers have to opt-in for, rather than the default. I would create a separate style for this.I would put the attached property within a new PasswordBoxAssist class. Because the normal password is not a dependency property, registering for events is needed to manually manage synchronization between them. I really like how MahApps did it by using a behavior to sync between the plain string and SecureString properties.A few details on what I would expect for the implementation. But it may pay off with more and more password boxes.I think it is reasonable to implement this within the library. Whether it has saved me lines of code, I'm not sure. Public PassableProperty Password2Property Private readonly PassableProperty m_password2Property Public PassableProperty Password1Property Private readonly PassableProperty m_password1Property New Propert圜hangedEventArgs(sPropertyName)) Private void RaisePropert圜hanged(string sPropertyName) Public event Propert圜hangedEventHandler Propert圜hanged M_password2Property = new PassableProperty( M_password1Property = new PassableProperty( Public class MyViewModel : INotifyPropert圜hanged Public PassableProperty(Func getter, Action setter) Private void PasswordBox_Loaded(object sender, RoutedEventArgs e) Var property = passwordBox.Tag as PassableProperty If ((passwordBox != null) & (passwordBox.Tag != null)) Private void PasswordBox_PasswordChanged(object sender, RoutedEventArgs e) I've just been working on some code that involves multiple password boxes in one view, and I didn't want to end up wiring up lots of event handlers to cater for keeping the view and viewmodel in sync.
0 Comments
Leave a Reply. |