绑定 WPF 密码框 [英] Bind a WPF passwordbox
本文介绍了绑定 WPF 密码框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在 XAML 代码中绑定一个密码框.现在我发现无法绑定它,因为您没有任何依赖属性.
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?
推荐答案
Password
属性不是依赖属性——出于安全原因.不过,您可以轻松获得纯文本密码.
The Password
property is not a dependency property -- for security reasons. You can easily get the plain-text password, though.
<PasswordBox
x:Name="passwordBox"
PasswordChanged="OnPasswordChanged" />
代码隐藏事件处理程序:
private void OnPasswordChanged(
object sender,
RoutedEventArgs e)
{
Debug.WriteLine(passwordBox.Password);
}
<小时>
更新
- Samuel Jack 描述了如何绑定到
PasswordBox
使用附加属性 - 关于安全风险的讨论
- Samuel Jack describes how to bind to a
PasswordBox
using attached properties - A discussion on security risk
Updates
这篇关于绑定 WPF 密码框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文