1
Answer

Difficulty using the PasswordBox in my WPF project in .Net 10

In my new project, which I'm developing with WPF in .NET 10,

I'm having trouble using the PasswordBox in a user authentication window.

In my code, I've used the PasswordBox's KeyDown and PreviewKeyDown events.

Normally, when a user enters their password and presses Enter, if the password is correct, DialogResult is set to true and the Close() method is called.

And it's at this point that the program stops, when DialogResult is set to true.

The program crashes without returning an error message.

However, in a previous project I developed with WPF in .NET Framework,

I didn't encounter this problem. Despite my research, I haven't found a solution.

The good news is that when the validation button is clicked after entering the password, the window closes without any problem. Pressing Enter when the PasswordBox has focus causes a problem.

Please, I need to understand how to fix this bug.

Answers (1)