Windows Phone Programming

INTRODUCTION:

With increasing shift from Desktop and Laptops to Mobile devices, the Microsoft also had to turn towards developing an Operating system. The smartphone operating system from Microsoft, introduced in 2010. Using the Metro touch interface first deployed on Microsoft’s Zune music player, Windows Phone is a vast departure from the previous Windows Mobile platform. Both Windows Mobile and the first versions of Windows Phone were based on the Windows CE operating system, but that changed in 2012. A major feature of Windows Phone is the built-in Windows support (Office documents can be edited), and messages from Facebook and Windows Live mail can be instantly viewed. In order to synchronize music, videos and photos, as well as update the OS, Windows Phone requires Zune software in the PC and connector software in the Mac.

1.1 Development Cycle of Windows Phone Operating System

The first Windows OS release was Windows Phone 7 in 2010. In 2011, Version 7.5, code named Mango, added app switching and refined Office, Bing and social network integration. The Tango 2012 update includes improved multitasking and text messaging and also runs in less powerful hardware, making Windows Phone available to a lower-end market. market. Introduced in late 2012, Windows Phone 8 replaces the Windows CE operating system with a phone version of Windows 8 in order to align product architectures, but not in the same way as its competitors.

Ref: (http://www.pcmag.com/encyclopedia_term/0,1237,t=Windows+phone&i=61785,00.asp)

1.2 Development of Applications for Windows Phone OS

For developing applications, a Software Development Kit (SDK) needs to be installed on computer. The Windows Phone Software Development Kit 7.1 provides with all of the tools that one need to develop applications and games for both Windows Phone 7.0 and Windows Phone 7.5 devices. The Windows Phone Software Development Kit 8.0 provides with the tools that one need to develop apps and games for Windows Phone 8 and Windows Phone 7.5. The Windows Phone SDK includes the following

  • Microsoft Visual Studio 2010 Express for Windows Phone
  • Windows Phone Emulator
  • Windows Phone SDK 7.1 Assemblies
  • Silverlight 4 SDK and DRT
  • Windows Phone SDK 7.1 Extensions for XNA Game Studio 4.0
  • Microsoft Expression Blend SDK for Windows Phone 7
  • Microsoft Expression Blend SDK for Windows Phone OS 7.1
  • WCF Data Services Client for Window Phone
  • Microsoft Advertising SDK for Windows Phone

1.3 Features of Windows Phone

a. User interface

b. Text input

c. Messaging

d. Web browser

e. Contacts

f. Email

Installation of Windows Phone SDK:

System Requirements

The following table lists system requirements for Windows Phone SDK 7.1.

Supported operating systems Windows Vista® with Service Pack 2 32-bit (x86) and 64-bit (x64) versions (all editions except Windows 7 Starter)

Windows 7 32-bit (x86) and 64-bit (x64) versions (all editions except Windows 7 Starter)

Hardware Installation requires 1.5 GB of free disk space on the system drive.

3 GB of RAM

Windows Phone Emulator Windows Phone Emulator requires a Microsoft DirectX® 10 or DirectX 11 graphics card with Windows Display Driver Model (WDDM) 1.1 driver and DDI 10 and later versions. Windows Phone Emulator requires GPU emulation to support certain scenarios such as profiling application performance, XNA® Framework applications, and displaying content in web browser controls. Windows Phone Emulator supports GPU peripheral emulation using the host GPU on computers that meet Windows Phone SDK 7.1.1 Update system requirements. On all other computers, the emulator reverts to software emulation, which is not supported. On Windows 7, you can verify that your computer supports the recommended configuration by running dxdiag in a Command Prompt window.

How to Install

Double click the autorun.exe located in the windows SDK folder. A confirmation dialog box will appear to ask permission about make changes in windows. Than a dialog box will appear which ask us to install the SDK like figure shown below:

Description: http://www.windowsphonegeek.com/upload/tips/image_thumb_4_1.png

The Windows Phone SDK includes the following

  • Windows Phone SDK 7.1 (RC)
  • Windows Phone Emulator (RC)
  • Windows Phone SDK 7.1 Assemblies (RC)
  • Silverlight 4 SDK and DRT
  • Windows Phone SDK 7.1 Extensions for XNA Game Studio 4.0
  • Microsoft Expression Blend SDK for Windows Phone 7
  • Microsoft Expression Blend SDK for Windows Phone OS 7.1
  • WCF Data Services Client for Window Phone
  • Microsoft Advertising SDK for Windows Phone

It will than restart computer automatically several times, when full installation is done a new window will appear, just press “Run the Product Now” button to launch Visual Studio 2010 express for windows phone. Alternatively you can open Visual Studio and start creating new projects.

Description: http://www.windowsphonegeek.com/upload/tips/image_12_1.png

Hello World:

After the successful installation, we can start writing our first application. Here SDK features Visual Studio 2010 Express for Windows Phone.

Start Visual Studio 2010 Express for Windows Phone and start a new project by clicking on “New Project” link or Main menu “File -> New -> Project”.

Description: C:\Users\manish\Desktop\ima]\Image_01.png

New project dialog is shown.
fig-02

Here in the panel features a list of installed project templates. Here we can see “Visual Basic”, expand it and select “Silverlight for Windows Phone”.
Now when we click on “Silverlight for Windows phone”, we will find a list of Windows phone Project Templates. Select Windows Phone Application and change the application name whatever we want, here in this case we are using helloworld. Now Click OK button and we will get a dialog box to choose the windows phone OS version, choose Windows phone OS 7.1 and click OK. We have created our Hello World project.

When our project is loaded, by default MainPage.xaml file is opened in editor. Editor is splitted in two sections with Windows Phone 7 device designer on the left and xaml code on the right. Notice that there are a few default controls added on the designer surface.

Description: C:\Users\manish\Desktop\ima]\Image_03.png

In the first program we are going to use a textbox and a button. To put the TextBlock and Button on the designer surface one by one we have to drag these controls from Toolbox to designer surface. Toolbox is located in the left of designer surface, which becomes visible by clicking on it.

test
We can change the button text using the property box, Property box may be viewed from view menu option. Find Content property end replace text “Button” with “Click Here” but the name of Button remain the same as earlier.

1

Initially we find TextBlock is written there in the TextBlock we can change this using the Property Box. Find Text Property remove all the text written there or we can add other text if we want to change the text appear there.

Description: C:\Users\manish\Desktop\ima]\Image_07.png

Now fit these controls according to our requirement on the designer surface.
Now our page should look similar to this.

2

Now write a simple code behind the Button to make Hello world appear on the TextBlock when we click That Button. To write that simple code double clicks on that button than we will find a page to write the code for that button. Initially when we double click on button we will find the code page like shown below:

Now write the code to appear “Hello World” in Private Sub Button1_Click which will look like the code shown below:

4
Now Save the document and hit F5 or Run button located on standard toolbar to start the application. Windows Phone Emulator starts loading and application is then executed inside it.

When application is started, we can now see our main page with the “Click Here” button. Click on the button and “Hello World” will be shown like the picture shown below. And that’s it, a simple Hello World application created on Windows Phone 7.

DEI Salary Calculator:

To start the project open Visual Studio 2010 express for windows phone and create a new project.

Be sure to select Visual Basic as the language, Silverlight for Windows Phone as the set of templates and Windows Phone application as the specific template. Also make sure you give your project a meaningful name. A default name given by the package.

We’ll be creating this as a Windows Phone 7.1 project.

A new project will open that may look something like the following:

Insert four TextBlock on the designer surface, one for page title and rest of the TextBlock for labeling the TextBox values. Place two TextBox and two Radio buttons on the designer surface. One TextBox will use to take Band Pay as input and we name it as TextBox1, another TextBox will use to get input of Grade Pay and is named as TextBox2. Radio button to choose either salary calculation on old pension scheme or new pension scheme basis.

After this page will look as shown below:

And the xaml code for this layout is as shown below:

MainPage.xaml

<phone:PhoneApplicationPage

x:Class=”PhoneApp4.MainPage”

xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/presentation”

xmlns:x=”http://schemas.microsoft.com/winfx/2006/xaml”

xmlns:phone=”clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone”

xmlns:shell=”clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone”

xmlns:d=”http://schemas.microsoft.com/expression/blend/2008″

xmlns:mc=”http://schemas.openxmlformats.org/markup-compatibility/2006″

mc:Ignorable=”d” d:DesignWidth=”480″ d:DesignHeight=”768″

FontFamily=”{StaticResource PhoneFontFamilyNormal}”

FontSize=”{StaticResource PhoneFontSizeNormal}”

Foreground=”{StaticResource PhoneForegroundBrush}”

SupportedOrientations=”Portrait” Orientation=”Portrait”

shell:SystemTray.IsVisible=”True”>

<!–LayoutRoot is the root grid where all page content is placed–>

<Grid x:Name=”LayoutRoot” Background=”#FF276C6C”>

<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=”PageTitle” Text=”DEI Salary” Margin=”9,-7,0,0″ Style=”{StaticResource PhoneTextTitle1Style}” FontStyle=”Italic” FontStretch=”UltraCondensed” FontSize=”50″ FontFamily=”Courier New” />

</StackPanel>

<!–ContentPanel – place additional content here–>

<Grid x:Name=”ContentPanel” Grid.Row=”1″ Margin=”12,0,12,0″ Background=”#FF276C6C” AllowDrop=”False”>

<TextBlock Height=”30″ HorizontalAlignment=”Left” Margin=”28,122,0,0″ Name=”TextBlock1″ Text=”Enter your Band Pay” VerticalAlignment=”Top” Width=”189″ />

<TextBox Height=”72″ HorizontalAlignment=”Left” Margin=”223,108,0,0″ Name=”TextBox1″ Text=”” VerticalAlignment=”Top” Width=”204″>

<TextBox.InputScope>

<InputScope/>

</TextBox.InputScope>

</TextBox>

<TextBlock Height=”30″ HorizontalAlignment=”Left” Margin=”28,199,0,0″ Name=”TextBlock2″ Text=”Enter your Grade Pay” VerticalAlignment=”Top” Width=”189″ />

<TextBox Height=”72″ HorizontalAlignment=”Left” Margin=”223,186,0,0″ Name=”TextBox2″ Text=”” VerticalAlignment=”Top” Width=”204″ />

 

<Button Content=”Submit” Height=”72″ HorizontalAlignment=”Left” Margin=”122,450,0,0″ Name=”Button1″ VerticalAlignment=”Top” Width=”176″ />

<RadioButton Content=”old scheme ” Height=”72″ HorizontalAlignment=”Left” Margin=”223,279,0,0″ Name=”RadioButton1″ VerticalAlignment=”Top” Width=”204″ />

<TextBlock Height=”63″ HorizontalAlignment=”Left” Margin=”28,322,0,0″ Name=”TextBlock3″ Text=”Select the scheme” VerticalAlignment=”Top” Width=”177″ />

<RadioButton Content=”New Pension” Height=”72″ HorizontalAlignment=”Left” Margin=”223,341,0,0″ Name=”RadioButton2″ VerticalAlignment=”Top” IsChecked=”True” />

</Grid>

</Grid>

 

<!–Sample code showing usage of ApplicationBar–>

<!–<phone:PhoneApplicationPage.ApplicationBar>

<shell:ApplicationBar IsVisible=”True” IsMenuEnabled=”True”>

<shell:ApplicationBarIconButton IconUri=”/Images/appbar_button1.png” Text=”Button 1″/>

<shell:ApplicationBarIconButton IconUri=”/Images/appbar_button2.png” Text=”Button 2″/>

<shell:ApplicationBar.MenuItems>

<shell:ApplicationBarMenuItem Text=”MenuItem 1″/>

<shell:ApplicationBarMenuItem Text=”MenuItem 2″/>

</shell:ApplicationBar.MenuItems>

</shell:ApplicationBar>

</phone:PhoneApplicationPage.ApplicationBar>–>

</phone:PhoneApplicationPage>

Now coming to the main coding part of the project. Double Click the Submit Button and than we will come to the MainPage.xaml.vb page. This page will include all the coding portion of the page named MainPage.xaml.

When we Double Click on Submit button we will find click event default code created by project itself which will look like the code shown below:

Now write the code to calculate salary particulars under this button click event and code what we use to calculate salary particular is shown below:

Private Sub Button1_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles Button1.Click

If TextBox1.Text = “” Then

MessageBox.Show(“please enter your band pay”, “Error”, MessageBoxButton.OK)

ElseIf TextBox2.Text = “” Then

MessageBox.Show(“please enter your Grade pay”, “Error”, MessageBoxButton.OK)

Else

band = Double.Parse(TextBox1.Text)

grade = Double.Parse(TextBox2.Text)

basic = Double.Parse(TextBox1.Text) + Double.Parse(TextBox2.Text)

da = basic * (72 / 100)

hra = basic * (20 / 100)

If scheme = “new” Then

tier1 = (basic + da) * 10 / 100

ElseIf scheme = “old” Then

tier1 = basic * (10 / 100)

End If

If TextBox2.Text = “1900” Then

ta = 680

ElseIf TextBox2.Text = “2000” Then

ta = 1376

ElseIf TextBox2.Text = “2800” Then

ta = 1376

ElseIf TextBox2.Text = “4200” Then

ta = 1376

ElseIf TextBox2.Text = “4600” Then

ta = 1376

ElseIf TextBox2.Text = “5400” Then

ta = 1376

End If

gross = basic + da + hra + ta

net = gross – tier1

NavigationService.Navigate(New Uri(“/Page1.xaml”, UriKind.Relative))

End If

End Sub

In the above code we are comparing scheme variable to two values which are “old” and “new” and to define old or new constant values we have to first create checked event on each of the radio button we placed on designer surface.

To create the checked event double click on radio button we will find the blank check event as shown below:

Now define scheme variable value as per requirement like we define old pension under RadioButton1 than we write a single line code as shown below:

Private Sub RadioButton1_Checked(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles RadioButton1.Checked

scheme = “old”

End Sub

Similarly write the checked event for another Radio button.

Private Sub RadioButton2_Checked(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles RadioButton2.Checked

scheme = “new”

End Sub

To initialize all the variables for the global use in this project add a module. To add this module follow the steps Project (menu) =>Add Module, this will add a Module1.vb page in our project. Initially we find a blank page, now initialize all our variables what we are using in this project here on this page and than this page will look like as shown as below

Now start to design a page1.xaml layout and this page will look as shown below:

The .xaml code for this page is as follows:

<phone:PhoneApplicationPage

x:Class=”PhoneApp4.Page1″

xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/presentation”

xmlns:x=”http://schemas.microsoft.com/winfx/2006/xaml”

xmlns:phone=”clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone”

xmlns:shell=”clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone”

xmlns:d=”http://schemas.microsoft.com/expression/blend/2008″

xmlns:mc=”http://schemas.openxmlformats.org/markup-compatibility/2006″

FontFamily=”{StaticResource PhoneFontFamilyNormal}”

FontSize=”{StaticResource PhoneFontSizeNormal}”

Foreground=”{StaticResource PhoneForegroundBrush}”

SupportedOrientations=”Portrait” Orientation=”Portrait”

mc:Ignorable=”d” d:DesignHeight=”768″ d:DesignWidth=”480″

shell:SystemTray.IsVisible=”True”>

<!–LayoutRoot is the root grid where all page content is placed–>

<Grid x:Name=”LayoutRoot” Background=”#FF276C6C”>

<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=”PageTitle” Text=”DEI Salary” Margin=”9,-7,0,0″ Style=”{StaticResource PhoneTextTitle1Style}” FontSize=”50″ FontFamily=”Courier New” FontStyle=”Italic” />

</StackPanel>

<!–ContentPanel – place additional content here–>

<Grid x:Name=”ContentPanel” Grid.Row=”1″ Margin=”12,0,12,0″ Background=”#FF276C6C”>

<TextBlock Height=”30″ Margin=”42,107,272,0″ Name=”TextBlock1″ Text=”Band Pay” VerticalAlignment=”Top” />

<TextBlock Height=”30″ HorizontalAlignment=”Left” Margin=”42,0,0,487″ Name=”TextBlock2″ Text=”Grade Pay” VerticalAlignment=”Bottom” />

<TextBlock Height=”30″ HorizontalAlignment=”Left” Margin=”42,213,0,0″ Name=”TextBlock3″ Text=”Basic” VerticalAlignment=”Top” />

<TextBlock Height=”30″ HorizontalAlignment=”Left” Margin=”42,268,0,0″ Name=”TextBlock4″ Text=”DA” VerticalAlignment=”Top” />

<TextBlock Height=”30″ HorizontalAlignment=”Left” Margin=”42,318,0,0″ Name=”TextBlock5″ Text=”HRA” VerticalAlignment=”Top” />

<TextBlock Height=”30″ HorizontalAlignment=”Left” Margin=”42,373,0,0″ Name=”TextBlock6″ Text=”TA” VerticalAlignment=”Top” />

<TextBlock Height=”30″ HorizontalAlignment=”Left” Margin=”42,427,0,0″ Name=”TextBlock7″ Text=”PF/TIER1″ VerticalAlignment=”Top” />

<TextBlock Height=”30″ HorizontalAlignment=”Left” Margin=”42,477,0,0″ Name=”TextBlock8″ Text=”Gross Pay” VerticalAlignment=”Top” />

<TextBlock Height=”30″ HorizontalAlignment=”Left” Margin=”42,530,0,0″ Name=”TextBlock9″ Text=”Net Pay” VerticalAlignment=”Top” />

<TextBlock Height=”30″ HorizontalAlignment=”Left” Margin=”212,156,0,0″ Name=”TextBlock11″ Text=”TextBlock” VerticalAlignment=”Top” Width=”212″ />

<TextBlock Height=”30″ HorizontalAlignment=”Left” Margin=”212,213,0,0″ Name=”TextBlock12″ Text=”TextBlock” VerticalAlignment=”Top” Width=”212″ />

<TextBlock Height=”30″ HorizontalAlignment=”Left” Margin=”212,268,0,0″ Name=”TextBlock13″ Text=”TextBlock” VerticalAlignment=”Top” Width=”212″ />

<TextBlock Height=”30″ HorizontalAlignment=”Left” Margin=”212,318,0,0″ Name=”TextBlock14″ Text=”TextBlock” VerticalAlignment=”Top” Width=”212″ />

<TextBlock Height=”30″ HorizontalAlignment=”Left” Margin=”212,373,0,0″ Name=”TextBlock15″ Text=”TextBlock” VerticalAlignment=”Top” Width=”212″ />

<TextBlock Height=”30″ HorizontalAlignment=”Left” Margin=”212,427,0,0″ Name=”TextBlock16″ Text=”TextBlock” VerticalAlignment=”Top” Width=”212″ />

<TextBlock Height=”30″ HorizontalAlignment=”Left” Margin=”212,477,0,0″ Name=”TextBlock17″ Text=”TextBlock” VerticalAlignment=”Top” Width=”212″ />

<TextBlock Height=”30″ HorizontalAlignment=”Left” Margin=”212,530,0,0″ Name=”TextBlock18″ Text=”TextBlock” VerticalAlignment=”Top” Width=”212″ />

<TextBlock Height=”30″ HorizontalAlignment=”Left” Margin=”9,28,0,0″ Name=”TextBlock19″ Text=”Your salary Particulars are as follows” VerticalAlignment=”Top” Width=”415″ />

<TextBlock Height=”30″ HorizontalAlignment=”Left” Margin=”212,107,0,0″ Name=”TextBlock10″ Text=”TextBlock” VerticalAlignment=”Top” Width=”212″ />

</Grid>

</Grid>

 

<!–Sample code showing usage of ApplicationBar–>

<!–<phone:PhoneApplicationPage.ApplicationBar>

<shell:ApplicationBar IsVisible=”True” IsMenuEnabled=”True”>

<shell:ApplicationBarIconButton IconUri=”/Images/appbar_button1.png” Text=”Button 1″/>

<shell:ApplicationBarIconButton IconUri=”/Images/appbar_button2.png” Text=”Button 2″/>

<shell:ApplicationBar.MenuItems>

<shell:ApplicationBarMenuItem Text=”MenuItem 1″/>

<shell:ApplicationBarMenuItem Text=”MenuItem 2″/>

</shell:ApplicationBar.MenuItems>

</shell:ApplicationBar>

</phone:PhoneApplicationPage.ApplicationBar>–>

</phone:PhoneApplicationPage>

To display all the calculated values on the next page i.e., Page1.xml we have to put all the values in Textblock and to do this open Page1.xaml.vb page and add following code:

Partial Public Class Page1

Inherits PhoneApplicationPage

Public Sub New()

InitializeComponent()

End Sub

Private Sub PhoneApplicationPage_Loaded(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles MyBase.Loaded

TextBlock10.Text = band

TextBlock11.Text = grade

TextBlock12.Text = basic

TextBlock13.Text = da

TextBlock14.Text = hra

TextBlock15.Text = ta

TextBlock16.Text = tier1

TextBlock17.Text = gross

TextBlock18.Text = net

End Sub

End Class

Application is ready press F5 or run button located on standard toolbar to execute this project and the initial screen of the project will look as follows:

And the output screen of the project will look like as shown below in the emulator:

Simple Calculator:

To make the Simple calculator start the visual studio 2010 for windows phone. After that start the new project and than we will find the screen shown below:

Choose the silverlight for windows phone option from the visual Basic menu and Select Windows phone Application from the installed templates located on the center of the screen. Give appropriate name of the application, here in this case we gave calculator and than click ok to create the project after that a dialog box will prompt to ask select the windows platform, for this application choose Windows phone OS7.1 and than click OK.

After this we will find the screen shown below:

Now design our designer surface according to our requirement and the designer surface of our application shown below:

First putting a textbox for display input and output both and different buttons for numbers and operators. We have to edit the button text property for each as shown above.

And the XAML code for this graphical user interface is shown below:

<phone:PhoneApplicationPage

x:Class=”PhoneApp2.MainPage”

xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/presentation”

xmlns:x=”http://schemas.microsoft.com/winfx/2006/xaml”

xmlns:phone=”clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone”

xmlns:shell=”clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone”

xmlns:d=”http://schemas.microsoft.com/expression/blend/2008″

xmlns:mc=”http://schemas.openxmlformats.org/markup-compatibility/2006″

mc:Ignorable=”d” FontFamily=”{StaticResource PhoneFontFamilyNormal}”

FontSize=”{StaticResource PhoneFontSizeNormal}”

Foreground=”{StaticResource PhoneForegroundBrush}”

SupportedOrientations=”Portrait” Orientation=”Portrait”

shell:SystemTray.IsVisible=”True” d:DesignHeight=”768″ d:DesignWidth=”480″>

<!–LayoutRoot is the root grid where all page content is placed–>

<Grid x:Name=”LayoutRoot” Background=”#FF257979″>

<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=”PageTitle” Text=”Calculator” Margin=”9,-7,0,0″ Style=”{StaticResource PhoneTextTitle1Style}”/>

</StackPanel>

<!–ContentPanel – place additional content here–>

<Grid x:Name=”ContentPanel” Grid.Row=”1″ Margin=”12,0,12,0″>

<Button Content=”9″ Height=”72″ HorizontalAlignment=”Right” Margin=”0,189,196,0″ Name=”Button1″ VerticalAlignment=”Top” Width=”77″ />

<Button Content=”8″ Height=”72″ HorizontalAlignment=”Left” Margin=”100,189,0,0″ Name=”Button2″ VerticalAlignment=”Top” Width=”77″ />

<Button Content=”7″ Height=”72″ HorizontalAlignment=”Left” Margin=”17,189,0,0″ Name=”Button3″ VerticalAlignment=”Top” Width=”77″ />

<Button Content=”6″ Height=”72″ HorizontalAlignment=”Left” Margin=”183,257,0,0″ Name=”Button4″ VerticalAlignment=”Top” Width=”77″ />

<Button Content=”5″ Height=”72″ HorizontalAlignment=”Right” Margin=”0,257,279,0″ Name=”Button5″ VerticalAlignment=”Top” Width=”77″ />

<Button Content=”4″ Height=”72″ HorizontalAlignment=”Left” Margin=”17,257,0,0″ Name=”Button6″ VerticalAlignment=”Top” Width=”77″ />

<Button Content=”3″ Height=”72″ HorizontalAlignment=”Left” Margin=”183,321,0,0″ Name=”Button7″ VerticalAlignment=”Top” Width=”77″ />

<Button Content=”2″ Height=”72″ HorizontalAlignment=”Left” Margin=”100,321,0,0″ Name=”Button8″ VerticalAlignment=”Top” Width=”77″ />

<Button Content=”1″ Height=”72″ HorizontalAlignment=”Left” Margin=”17,321,0,0″ Name=”Button9″ VerticalAlignment=”Top” Width=”77″ />

<Button Content=”.” Height=”72″ HorizontalAlignment=”Left” Margin=”183,382,0,0″ Name=”Button10″ VerticalAlignment=”Top” Width=”77″ />

<Button Content=”0″ Height=”72″ HorizontalAlignment=”Left” Margin=”17,382,0,0″ Name=”Button11″ VerticalAlignment=”Top” Width=”160″ />

<TextBox Height=”72″ HorizontalAlignment=”Left” Margin=”0,54,0,0″ Name=”TextBox1″ Text=”” VerticalAlignment=”Top” Width=”460″ />

<Button Content=”/” Height=”72″ HorizontalAlignment=”Left” Margin=”266,189,0,0″ Name=”Button12″ VerticalAlignment=”Top” Width=”77″ />

<Button Content=”*” Height=”72″ Margin=”266,257,113,0″ Name=”Button13″ VerticalAlignment=”Top” />

<Button Content=”-” Height=”72″ HorizontalAlignment=”Left” Margin=”266,321,0,0″ Name=”Button14″ VerticalAlignment=”Top” Width=”77″ />

<Button Content=”+” Height=”72″ HorizontalAlignment=”Left” Margin=”266,382,0,0″ Name=”Button15″ VerticalAlignment=”Top” Width=”77″ />

<Button Content=”c” Height=”72″ HorizontalAlignment=”Left” Margin=”349,189,0,0″ Name=”Button16″ VerticalAlignment=”Top” Width=”77″ />

<Button Content=”1/x” Height=”72″ HorizontalAlignment=”Left” Margin=”349,257,0,0″ Name=”Button17″ VerticalAlignment=”Top” Width=”77″ FontSize=”20″ />

<Button Content=”=” Height=”133″ HorizontalAlignment=”Left” Margin=”349,321,0,0″ Name=”Button18″ VerticalAlignment=”Top” Width=”77″ />

<Grid.Background>

<LinearGradientBrush EndPoint=”1,0.5″ StartPoint=”0,0.5″>

<GradientStop Color=”Black” Offset=”0″ />

<GradientStop Color=”#FF257979″ Offset=”1″ />

</LinearGradientBrush>

</Grid.Background>

</Grid>

</Grid>

<!–Sample code showing usage of ApplicationBar–>

<!–<phone:PhoneApplicationPage.ApplicationBar>

<shell:ApplicationBar IsVisible=”True” IsMenuEnabled=”True”>

<shell:ApplicationBarIconButton IconUri=”/Images/appbar_button1.png” Text=”Button 1″/>

<shell:ApplicationBarIconButton IconUri=”/Images/appbar_button2.png” Text=”Button 2″/>

<shell:ApplicationBar.MenuItems>

<shell:ApplicationBarMenuItem Text=”MenuItem 1″/>

<shell:ApplicationBarMenuItem Text=”MenuItem 2″/>

</shell:ApplicationBar.MenuItems>

</shell:ApplicationBar>

</phone:PhoneApplicationPage.ApplicationBar>–>

</phone:PhoneApplicationPage>

Now our graphical user interface part is completed. After that start the coding part of our application. To start the coding of our application open the page named MainPage.xaml.vb under the MainPage.xaml.

And the code behind all the buttons is shown below:

Partial Public Class MainPage

Inherits PhoneApplicationPage

‘ Constructor

Public Sub New()

InitializeComponent()

End Sub

Private dblValue1 As Double

Private dblValue2 As Double

Private dblTemp As Double

Private blnDecimalPoint As Boolean

Private blnInputStatus As Boolean

Private strCalculate As String

Private Sub Button11_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles Button11.Click

If blnInputStatus Then

If TextBox1.Text.Length >= 1 AndAlso TextBox1.Text <> “0” Then

TextBox1.Text = TextBox1.Text & “” & 0

ElseIf blnDecimalPoint Then

TextBox1.Text = TextBox1.Text & “” & 0

End If

End If

End Sub

Private Sub Button9_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles Button9.Click

If (blnInputStatus AndAlso TextBox1.Text <> “0”) Or blnDecimalPoint Then

TextBox1.Text = TextBox1.Text & “” & 1

Else

TextBox1.Text = 1

blnInputStatus = True

End If

End Sub

Private Sub Button8_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles Button8.Click

If (blnInputStatus AndAlso TextBox1.Text <> “0”) Or blnDecimalPoint Then

TextBox1.Text = TextBox1.Text & “” & 2

Else

TextBox1.Text = 2

blnInputStatus = True

End If

End Sub

Private Sub Button7_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles Button7.Click

If (blnInputStatus AndAlso TextBox1.Text <> “0”) Or blnDecimalPoint Then

TextBox1.Text = TextBox1.Text & “” & 3

Else

TextBox1.Text = 3

blnInputStatus = True

End If

End Sub

Private Sub Button6_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles Button6.Click

If (blnInputStatus AndAlso TextBox1.Text <> “0”) Or blnDecimalPoint Then

TextBox1.Text = TextBox1.Text & “” & 4

Else

TextBox1.Text = 4

blnInputStatus = True

End If

End Sub

Private Sub Button5_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles Button5.Click

If (blnInputStatus AndAlso TextBox1.Text <> “0”) Or blnDecimalPoint Then

TextBox1.Text = TextBox1.Text & “” & 5

Else

TextBox1.Text = 5

blnInputStatus = True

End If

End Sub

Private Sub Button4_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles Button4.Click

If (blnInputStatus AndAlso TextBox1.Text <> “0”) Or blnDecimalPoint Then

TextBox1.Text = TextBox1.Text & “” & 6

Else

TextBox1.Text = 6

blnInputStatus = True

End If

End Sub

Private Sub Button3_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles Button3.Click

If (blnInputStatus AndAlso TextBox1.Text <> “0”) Or blnDecimalPoint Then

TextBox1.Text = TextBox1.Text & “” & 7

Else

TextBox1.Text = 7

blnInputStatus = True

End If

End Sub

Private Sub Button2_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles Button2.Click

If (blnInputStatus AndAlso TextBox1.Text <> “0”) Or blnDecimalPoint Then

TextBox1.Text = TextBox1.Text & “” & 8

Else

TextBox1.Text = 8

blnInputStatus = True

End If

End Sub

Private Sub Button1_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles Button1.Click

If (blnInputStatus AndAlso TextBox1.Text <> “0”) Or blnDecimalPoint Then

TextBox1.Text = TextBox1.Text & “” & 9

Else

TextBox1.Text = 9

blnInputStatus = True

End If

End Sub

Private Sub Button10_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles Button10.Click

If (TextBox1.Text.Length < 1) Then

TextBox1.Text = “0.”

Else

TextBox1.Text = TextBox1.Text & “” & “.”

End If

End Sub

Private Sub Button15_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles Button15.Click

If TextBox1.Text.Length <> 0 Then

If strCalculate = String.Empty Then

dblValue1 = CType(TextBox1.Text, Double)

TextBox1.Text = “0”

Else

CalculateTotals()

End If

strCalculate = “Add”

blnDecimalPoint = False

End If

End Sub

Private Sub Button18_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles Button18.Click

If TextBox1.Text.Length <> 0 Then

CalculateTotals()

strCalculate = String.Empty

blnDecimalPoint = False

End If

End Sub

Private Sub CalculateTotals()

dblValue2 = CType(TextBox1.Text, Double)

Select Case strCalculate

Case (“Add”)

dblValue1 += dblValue2

Case (“Subtract”)

dblValue1 -= dblValue2

Case (“Multiply”)

dblValue1 *= dblValue2

Case (“Divide”)

If dblValue2 = 0 Then

MessageBox.Show(“You cannot divide by 0!”, “Warning”, MessageBoxButton.OK)

Exit Sub

End If

dblValue1 /= dblValue2

Case (“Exponential”)

dblValue1 ^= dblValue2

End Select

TextBox1.Text = CType(dblValue1, String)

blnInputStatus = False

End Sub

Private Sub Button14_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles Button14.Click

If TextBox1.Text.Length <> 0 Then

If strCalculate = String.Empty Then

dblValue1 = CType(TextBox1.Text, Double)

TextBox1.Text = “0”

Else

CalculateTotals()

End If

strCalculate = “Subtract”

blnDecimalPoint = False

End If

End Sub

Private Sub Button13_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles Button13.Click

If TextBox1.Text.Length <> 0 Then

If strCalculate = String.Empty Then

dblValue1 = CType(TextBox1.Text, Double)

TextBox1.Text = “0”

Else

CalculateTotals()

End If

strCalculate = “Multiply”

blnDecimalPoint = False

End If

End Sub

Private Sub Button12_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles Button12.Click

If TextBox1.Text.Length <> 0 Then

If strCalculate = String.Empty Then

dblValue1 = CType(TextBox1.Text, Double)

TextBox1.Text = “0”

Else

CalculateTotals()

End If

strCalculate = “Divide”

blnDecimalPoint = False

End If

End Sub

Private Sub Button16_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles Button16.Click

TextBox1.Text = “”

End Sub

Private Sub Button17_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles Button17.Click

Dim x As Double

dblValue1 = CType(TextBox1.Text, Double)

x = 1 / dblValue1

TextBox1.Text = CType(x, String)

End Sub

End Class

This is all our coding part. Now run the application to get the output and output will be shown as below:

Leave a Reply

Your email address will not be published. Required fields are marked *