问题
I want to bind a Passwordbox in the XAML code. Now I found out that it isn´t possible to bind it because you haven´t any dependency property.
For my case I don´t need any security in my Application. I just don´t want to display clear text to the user. Is there any other option to realize a kind of passwordbox with a textbox or so on?
回答1:
The Password
property is not a dependency property -- for security reasons. You can easily get the plain-text password, though.
XAML:
<PasswordBox
x:Name="passwordBox"
PasswordChanged="OnPasswordChanged" />
Code-behind event handler:
private void OnPasswordChanged(
object sender,
RoutedEventArgs e)
{
Debug.WriteLine(passwordBox.Password);
}
Updates
- Samuel Jack describes how to bind to a PasswordBox using attached properties
- A discussion on security risk
来源:https://stackoverflow.com/questions/40981169/bind-a-wpf-passwordbox