This article is going to explain how to use Password control in Windows 7 phone development. Let’s see a brief demonstration on it.
Getting started:
1. Open Visual Studio
2. Create new Silverlight Windows 7 Phone Development Project
3. Enter your project Name
4. Click on button ‘Ok’
Now drag and drop Password control in ‘MainPage.xaml’ design interface and set some properties of Password control.
Now write down the following to code to build up above layout.
Code of MainPage.xaml:
<!--LayoutRoot is the root grid where all page content is placed-->
<Grid x:Name="LayoutRoot" Background="Transparent">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<!--TitlePanel contains the name of the application and page title-->
<StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
<TextBlock x:Name="ApplicationTitle" Text="My Application" Style="{StaticResource PhoneTextNormalStyle}"/>
<TextBlock x:Name="PageTitle" Text="PasswordControl Demo" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}" FontSize="40" />
</StackPanel>
<!--ContentPanel - place additional content here-->
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<TextBlock Height="48" HorizontalAlignment="Left" Margin="30,68,0,0" Name="lblUsername" Text="UserName" VerticalAlignment="Top" Width="171" FontSize="32" />
<TextBlock Height="56" HorizontalAlignment="Left" Margin="30,170,0,0" Name="lblPassword" Text="Password" VerticalAlignment="Top" Width="171" FontSize="32" />
<TextBox Height="72" HorizontalAlignment="Left" Margin="180,58,0,0" Name="txtUsername" Text="" VerticalAlignment="Top" Width="238" />
<PasswordBox Height="72" HorizontalAlignment="Left" Margin="180,158,0,0" Name="txtPassword" VerticalAlignment="Top" Width="238" />
<Button Content="Login" Height="90" HorizontalAlignment="Left" Margin="180,290,0,0" Name="btnLogin" VerticalAlignment="Top" Width="180" Click="btnLogin_Click" />
</Grid>z
</Grid>
Code of MainPage.xaml.cs:
using System.Windows;
using Microsoft.Phone.Controls;
namespace passwordDemo
{
public partial class MainPage : PhoneApplicationPage
{
// Constructor
public MainPage()
{
InitializeComponent();
}
private void btnLogin_Click(objectsender, RoutedEventArgse)
{
if (txtUsername.Text.Equals(string.Empty) || txtPassword.Password.Equals(string.Empty))
MessageBox.Show("Please fill all enteries!");
else
{
if (txtUsername.Text.Equals("arunSingh") && txtPassword.Password.Equals("arun@123"))
MessageBox.Show("login successfully");
else
MessageBox.Show("login failed!");
}
}
}
}
Now execute your application.
Now click on button ‘Login’.
This is the complete description of Password control in Windows Phone 7 Development. I hope you will enjoy it. Thanks for reading this article.
Leave Comment