绑定 WPF 密码框 [英] Bind a WPF passwordbox

查看:28
本文介绍了绑定 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);
}

<小时>

更新

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆