Building a Simple Windows Phone 7 application


In this article, we will build a simple windows phone application. We have seen in the earlier blog post on the installation of windows phone SDK.

We will see how to create a simple application which will save the contacts on a windows phone.


Let’s begin by choosing the Windows Phone Application project as shown below





By default the “MainPage.xaml” file is created, we will modify the application title and page title as in the StackPanel as shown below





<StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
      <TextBlock x:Name="ApplicationTitle" Text="Contact App" Style="{StaticResource PhoneTextNormalStyle}"/>
      <TextBlock x:Name="PageTitle" Text="My Contacts" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
StackPanel>

We will add the application icons add, delete and close button


We will add a Listbox which will display the contacts in the grid named “Content Panel”.
Lets create a simple contact class as shown below

    public class Contact
    {
        public string FirstName { get; set; }
        public string LastName { get; set; }
        public string ContactNumber { get; set; }
        public string ContactType { get; set; }
    }

We will bind the contact class property to the listbox’s text blocks as show below


To save the contacts we will use the “IsolatedStorageFile”, this is an isolated storage area to save the data in their own file system. To know more about that read here http://msdn.microsoft.com/en-us/library/system.io.isolatedstorage.isolatedstoragefile.aspx

We will add the code in the page to create a storage file.

IsolatedStorageFile ISFile = IsolatedStorageFile.GetUserStoreForApplication();
string strFile = "Contact.txt";

We will now create a page “AddContacts.xaml” which will be used to add contacts. We will add 4 textboxes to accept the contact details as shown below


We will add two application icon buttons, one for save and another for close as shown below


Now we will add the code for saving the contact for the “Save” button’s click event as shown below


For the close button, we can add a click event and add the below code to navigate to the Main page


In the Main Page (MainPage.xaml), we will add the below code to load the contacts on the list box control


The “AddContacts” screen will be seen as shown below



The Main Page UI will be seen as shown below which will display the contacts




Hope this was helpful. Please do drop your comments.

Comments

Popular posts from this blog

Jesus - God Thinks of you.

ASP.NET 4.0 Feature - URL Routing

Tips on JQuery Intellisense in VS 2008