绑定 WPF 密码框
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/40981169/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Bind a WPF passwordbox
提问by NoIdea123
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.
我想在 XAML 代码中绑定一个密码框。现在我发现不可能绑定它,因为你没有任何依赖属性。
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?
就我而言,我的应用程序不需要任何安全性。我只是不想向用户显示明文。有没有其他选择来实现一种带有文本框等的密码框?
回答by Petter Hesselberg
The Passwordproperty is not a dependency property -- for security reasons. You can easily get the plain-text password, though.
Password出于安全原因,该属性不是依赖属性。不过,您可以轻松获得纯文本密码。
XAML:
XAML:
<PasswordBox
x:Name="passwordBox"
PasswordChanged="OnPasswordChanged" />
Code-behind event handler:
代码隐藏事件处理程序:
private void OnPasswordChanged(
object sender,
RoutedEventArgs e)
{
Debug.WriteLine(passwordBox.Password);
}

