Search This Blog

Friday, April 8, 2016

PasswordBox WPF Example

WPF > Controls  > PasswordBox 

Represents a control designed for entering and handling passwords.

Example



<Window x:Class="WpfApplication3.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="221" Width="372">
    <Grid Margin="0,0,101,23">
        <PasswordBox x:Name="txtPwd" HorizontalAlignment="Left" Margin="110,75,0,0" VerticalAlignment="Top" Width="120" />
        <TextBlock HorizontalAlignment="Left" Margin="55,47,0,0" TextWrapping="Wrap" Text="User" VerticalAlignment="Top"/>
        <TextBox HorizontalAlignment="Left" Height="23" Margin="110,47,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="120"/>
        <TextBlock HorizontalAlignment="Left" Margin="55,75,0,0" TextWrapping="Wrap" Text="Password" VerticalAlignment="Top" RenderTransformOrigin="0.75,2.312"/>
        <Button Content="Login" HorizontalAlignment="Left" Margin="155,116,0,0" VerticalAlignment="Top" Width="75" Click="Button_Click"/>
    </Grid>
</Window>

private void Button_Click(object sender, RoutedEventArgs e)
{
   if (txtPwd.Password == "pwd")
     MessageBox.Show("Login Ok");

}