简体   繁体   中英

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. 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:

 <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. 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 .

Additionally, you should check for any errors that come up during execution.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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