Displaying passwords on any event for a password

I am developing a Windows phone app. In this I ask the user to log in.

On the login page, the user must enter a password.

Now I want me to give the user a checkbox that should show the password characters when selected.

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

Please suggest some way to do this.

+3


source to share


3 answers


Don't think it's possible with a PasswordBox ... just a thought, but you can 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 it clicks again, you toggle your visibility state again and so on ...

Edit

And that's how it is!

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



<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, add the following to the page code:

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();
}

      

This works great, but with a few more work, you can make it completely MVVM'ed!

+19


source


with the default password, it is not possible to implement the desired function.



you can find more information here: http://social.msdn.microsoft.com/Forums/en/wpf/thread/98d0d4d4-1463-481f-b8b1-711119a6ba99

+1


source


You can create your own control that inherits from the textbox, but after each character, you replace it with a *, storing the true value in a private variable on the page. Using a checkbox, you can toggle whether the value in the text box shows a true value or a * value.

This is not a neat solution or best practice, but I think it is an alternative if you are willing to live with it.

0


source







All Articles