简体   繁体   English

WPF 密码框在移动焦点时自动清除

[英]WPF PasswordBox automatically clears when move focus

I am building a new user form where there is a need for users to create a Password box.我正在构建一个新的用户表单,用户需要在其中创建一个密码框。

I am using a PasswordBox for this.我为此使用了PasswordBox However as soon as the user moves to the next box in the form (or selects create button) the password box clears.然而,一旦用户移动到表单中的下一个框(或选择创建按钮),密码框就会清除。

So the password property in the code behind is always an empty string.所以后面代码中的密码属性总是一个空字符串。

Is there any reason why this is occurring?发生这种情况有什么原因吗? I want to be able to use the data entered to create my users.我希望能够使用输入的数据来创建我的用户。

I have including the XAML below:我在下面包含了 XAML:

 <PasswordBox x:Name="Password1_passwordBox" Password="Password1" PasswordChar="X" HorizontalAlignment="Left" Height="25" Margin="138,201,0,0" VerticalAlignment="Top" Width="85"/>

Any help appreciated任何帮助表示赞赏

As it stands in the code given, the PasswordBox should work as you expect.就给出的代码而言, PasswordBox应该按您的预期工作。 There is something else clearing it out.还有其他事情可以清除它。 You should check the other logic in code-behind and any control templates, styles, etc that would be tied to the PasswordBox .您应该检查代码隐藏中的其他逻辑以及与PasswordBox相关联的任何控件模板、样式等。

Additionally, you should check for any errors that come up during execution.此外,您应该检查执行期间出现的任何错误。

您可能在后面的代码中更改了 Password1_passwordBox.password 属性或类似的内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM