Thursday, March 3, 2011

WPF PasswordBox: How do I warn a user that Caps Lock is enabled?

Does anyone know how to implement the standard bubble message that warns users whenever Caps Lock is enabled and a password control has focus? Is this built into the .NET framework or do I need to write my own class to do this?

Thanks.

From stackoverflow
  • If you use a MaskedTextBox and specify a passwordChar the .NET framework will automatically do this for you

    vg1890 : I believe MaskedTextBox is a WinForms control - I'm using WPF. I'd like to be able to continue using the PasswordBox because of its built-in security.
  • You could add a handler function to the PasswordChanged event handler and test for the value of the CapsLock key in that function. If found to be on, you could pop-up a message from there.

    vg1890 : This will do the trick! To detect CapsLock in the event handler, just check the boolean value of: Keyboard.IsKeyToggled(Key.CapsLock)

0 comments:

Post a Comment