简体   繁体   English

绑定WPF密码箱

[英]Bind a WPF passwordbox

I want to bind a Passwordbox in the XAML code. 我想在XAML代码中绑定密码箱。 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? 还有其他选择可以实现带有文本框的密码箱等吗?

The Password property is not a dependency property -- for security reasons. 出于安全原因, Password属性不是依赖项属性。 You can easily get the plain-text password, though. 不过,您可以轻松获得纯文本密码。

XAML: XAML:

<PasswordBox
    x:Name="passwordBox"
    PasswordChanged="OnPasswordChanged" />

Code-behind event handler: 代码隐藏事件处理程序:

private void OnPasswordChanged(
    object sender,
    RoutedEventArgs e)
{
    Debug.WriteLine(passwordBox.Password);
}

Updates 更新

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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