显示在某些事件passwordbox密码字符 [英] showing password characters on some event for passwordbox

查看:340
本文介绍了显示在某些事件passwordbox密码字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一款Windows Phone application.In,我要求用户登录。

I am developing a windows phone application.In that i ask the user to login.

在登录页面,用户必须输入密码。

On the login page the user has to enter password.

现在我想的是,我给用户该选择应显示密码的字符时复选框。

Now what I want is that i give user a check box which when selected should show the characters of the password.

我还没有看到密码箱的任何属性显示密码字符。

I have not seen any property on password box to show password characters.

请提出一些方法来做到这一点。

Please suggest some way to do it.

推荐答案

不要认为是可能的PasswordBox ...只是一个想法,但你可能会使用一个实现相同的结果隐藏的文本框,当用户点击该复选框,你只是隐藏PasswordBox并显示文本框;如果他再次点击,你再次打开自己的知名度状态,等等...

Don't think that is possible with PasswordBox... just a thought, but you might accomplish the same result using a hidden TextBox and when the user clicks the CheckBox, you just hide the PasswordBox and show the TextBox; if he clicks again, you switch their Visibility state again, and so on...

修改

和这里是如何

只需添加一个页面,更改的ContentPanel到StackPanel中并添加此XAML代码:

Just add a page, change the ContentPanel to a StackPanel and add this XAML code:

<PasswordBox x:Name="MyPasswordBox" Password="{Binding Text, Mode=TwoWay, ElementName=MyTextBox}"/>
<TextBox x:Name="MyTextBox" Text="{Binding Password, Mode=TwoWay, ElementName=MyPasswordBox}" Visibility="Collapsed" />
<CheckBox x:Name="ShowPasswordCharsCheckBox" Content="Show password" Checked="ShowPasswordCharsCheckBox_Checked" Unchecked="ShowPasswordCharsCheckBox_Unchecked" />



接下来,在页面代码,添加以下内容:

Next, on the page code, add the following:

private void ShowPasswordCharsCheckBox_Checked(object sender, RoutedEventArgs e)
{
    MyPasswordBox.Visibility = System.Windows.Visibility.Collapsed;
    MyTextBox.Visibility = System.Windows.Visibility.Visible;

    MyTextBox.Focus();
}

private void ShowPasswordCharsCheckBox_Unchecked(object sender, RoutedEventArgs e)
{
    MyPasswordBox.Visibility = System.Windows.Visibility.Visible;
    MyTextBox.Visibility = System.Windows.Visibility.Collapsed;

    MyPasswordBox.Focus();
}

这工作得很好,但有一些更多的工作,你完全可以做到这一点MVVM'ed!

This works fine, but with a few more work, you can do this fully MVVM'ed!

这篇关于显示在某些事件passwordbox密码字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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