C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
And: We then access the Password property on the PasswordBox. This returns a string, one that contains the original characters typed.
Example markup: XAML
<Window x:Class="WpfApplication23.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<PasswordBox HorizontalAlignment="Left"
Margin="10,10,0,0"
VerticalAlignment="Top"
Width="100"
PasswordChanged="PasswordBox_PasswordChanged"/>
</Grid>
</Window>
Example code: C#
using System.Windows;
using System.Windows.Controls;
namespace WpfApplication23
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void PasswordBox_PasswordChanged(object sender, RoutedEventArgs e)
{
// ... Display Password in Title.
// A bad design decision.
var box = sender as PasswordBox;
this.Title = "Password typed: " + box.Password;
}
}
}
So: I suggest leaving the PasswordChar as the default. The disc is a standard on web sites and program interfaces.
And: This would avoid the need to access the PasswordBox when the Button is clicked.
So: Password validation could thus be done without even touching the PasswordBox when the button is clicked.