Tip Calculator Hands On Lab for Windows Phone



Similar documents
Windows Presentation Foundation (WPF) User Interfaces

How to start creating a VoIP solution with Ozeki VoIP SIP SDK

To Begin Customize Office

A SharePoint Developer Introduction. Hands-On Lab. Lab Manual SPCHOL306 Using Silverlight with the Client Object Model VB

REDUCING YOUR MICROSOFT OUTLOOK MAILBOX SIZE

Microsoft Visual Studio 2010 Instructions For C Programs

Microsoft Expression Web

Knowledgebase Article

Using Microsoft Visual Studio API Reference

Microsoft Silverlight 4 Step by Step

Introduction to Building Windows Store Apps with Windows Azure Mobile Services

College of Arts & Sciences Degree Works Template Management User Guide for Advisors

Managing Contacts in Outlook

Document Revision Date: August 14, Create a New Data Protection Policy in the Symantec.cloud Management Portal

Choosing your Preferred Colours in Windows

Hands-On Lab. Building a Data-Driven Master/Detail Business Form using Visual Studio Lab version: Last updated: 12/10/2010.

ecw Weekly Users Tip: My Settings: Template-Friendly Settings & My Favorites: Templates

ComponentOne. FilePicker for Silverlight

Hands-On Lab. Client Workflow. Lab version: Last updated: 2/23/2011

Appendix A How to create a data-sharing lab

A SharePoint Developer Introduction. Hands-On Lab. Lab Manual HOL8 Using Silverlight with the Client Object Model C#

Microsoft Office 365 Portal

Using Microsoft Access

Maximizing the Use of Slide Masters to Make Global Changes in PowerPoint

Microsoft Virtual Labs. Building Windows Presentation Foundation Applications - C# - Part 1

Search help. More on Office.com: images templates

Project Management: Intermediate Microsoft Project 2010

WHAT S NEW IN MS EXCEL 2013

Windows Movie Maker 2012

FrontPage 2003: Forms

Walkthrough: Creating and Using an ASP.NET Web Service in Visual Web Developer

Time Matters for Microsoft Outlook. Technology Preview User Guide

USING WINDOWS MOVIE MAKER TO CREATE THE MOMENT BEHIND THE PHOTO STORY PART 1

Hands-On Lab. Building Applications in Silverlight 4 Module 8: Advanced OOB and MEF. Event Administrator Dashboard

MICROSOFT OUTLOOK 2011 SEND AND RESPOND TO S

About the Tutorial. Audience. Prerequisites. Copyright & Disclaimer. Windows 10 Apps Development

ITCS QUICK REFERENCE GUIDE: EXPRESSION WEB SITE

Chapter 20: Workflow

Using WebEx Player. Playing a recording. Installing WebEx Player. System requirements for listening to audio in a recording

Migrating to Excel 2010 from Excel Excel - Microsoft Office 1 of 1

Combination Chart Extensible Visualizations. Product: IBM Cognos Business Intelligence Area of Interest: Reporting

Introduction to the BackgroundWorker Component in WPF

Export Server Object Extension and Export Task Install guide. (V1.1) Author: Domenico Ciavarella ( )

GOOGLE DOCS APPLICATION WORK WITH GOOGLE DOCUMENTS

Working with SQL Server Integration Services

Greetings Card. Projects 1

MICROSOFT OUTLOOK 2011 ORGANIZE MESSAGES

MICROSOFT ACCESS 2007 BOOK 2

Produced by Flinders University Centre for Educational ICT. PivotTables Excel 2010

TUTORIAL 4 Building a Navigation Bar with Fireworks

Overview. Table of Contents. isupport Incident Management

5 Airport. Chapter 5: Airport 49. Right-click on Data Connections, then select Add Connection.

Publishing with Adobe Presenter 10 (Detailed)

A Step by Step Guide for Building an Ozeki VoIP SIP Softphone

ComponentOne. Windows for WPF

Step One. Step Two. Step Three USING EXPORTED DATA IN MICROSOFT ACCESS (LAST REVISED: 12/10/2013)

Basics. a. Click the arrow to the right of the Options button, and then click Bcc.

1. Create SQL Database in Visual Studio

Creating a Distribution List from an Excel Spreadsheet

Windows Phone 8 Guide for iphone Application Developers

BID2WIN Workshop. Advanced Report Writing

WPF Viewer for Reporting Services 2008/2012 Getting Started

Sage Accountants Business Cloud EasyEditor Quick Start Guide

PRELIMINARY Interfacing to C++

Microsoft Outlook 2003 Quick How-to Guide

Using the Cute Rich-Text Editor

Chapter 3 ADDRESS BOOK, CONTACTS, AND DISTRIBUTION LISTS

STEP BY STEP to Build the Application 1. Start a. Open a MvvmLight (WPF4) application and name it MvvmControlChange.

CA Service Desk Manager (SDM) r12.1 SDM Advanced Functionality and Reporting

Outlook Quick Steps & Rules

Creating Mailing Lables in IBM Cognos 8 Report Studio

KPN SMS mail. Send SMS as fast as !

Make Voice Calls and Share Documents using Skype*

MS Excel. Handout: Level 2. elearning Department. Copyright 2016 CMS e-learning Department. All Rights Reserved. Page 1 of 11

INTERCALL ONLINE Administrator Invoices User Guide

Designing for Windows Phone

AODA Mouse Pointer Visibility

Sample Table. Columns. Column 1 Column 2 Column 3 Row 1 Cell 1 Cell 2 Cell 3 Row 2 Cell 4 Cell 5 Cell 6 Row 3 Cell 7 Cell 8 Cell 9.

Animating in Inventor Studio the basics

Sales Person Commission

Microsoft Office Access 2007 which I refer to as Access throughout this book

RightFax FaxUtil. Quick reference guide to getting started. Note: This document applies to OpenText RightFax version 10.0

Intellect Platform - The Workflow Engine Basic HelpDesk Troubleticket System - A102

QUICK START GUIDE

PaymentNet Federal Card Solutions Cardholder FAQs

Acrobat PDF Forms - Part 2

ITS Training Class Charts and PivotTables Using Excel 2007

Lync 2013 FAQ s. How do I keep my Lync conversation window on top of all the other windows on my computer, so I can see it while I work?

Creating and Using Links and Bookmarks in PDF Documents

Microsoft Office Publisher 2010

How to test and debug an ASP.NET application

MICROSOFT EXCEL 2011 MANAGE WORKBOOKS

Transcription:

Tip Calculator Hands On Lab for Windows Phone In this exercise we will be creating a simple tip calculator for Windows Phone 7. Open Visual Studio (you can get it as part of the Windows Phone SDK) and create a new project. Be sure to select Visual C# 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. I chose TipDemo in this case. We ll be creating this as a Windows Phone 7.1 project. A new project will open that may look something like the following:

If it looks differently you can open the Properties Windows from the view menu and the toolbox is probably just not pinned open. From left to right we have the Toolbox (which I have pinned open) that shows us controls that we can use to create our user interface, the design window where we create out by dragging controls to it, the code window that shows the XAML (Silverlight code) that represents the UI controls, and the Solution Explorer and properties window. The properties window will allow us to set attributes for our UI controls. There first objects we will change are the Application Title and Page Name. We will do this by selecting each of these objects on the design form and changing the text property as follows.

Now we can start our user interface. We will use Text Blocks to display labels and data that we set in our code. We will use a Textbox to input the amount of the restaurant bill. We are going to create the following objects on our screen: Object Type Name Other Property settings Text Block textblock1 Text Meal Charge Text attributes to taste Textbox txttab Text - <empty> Slider slider1 Minimum 0 Maximum 35 Value - 15 Text Block textblock3 Text Tip % Text Block txttipp Text - <empty> Text Block txttip Text - <empty> Text Block txttotal Text - <empty> Text Block txtsplit Text - <empty> Text Block textblock5 Text Split Among Image UpSplit Image DownSplit Text Block txthowmany Text - <empty> Your design screen should look something like this:

Now we want to add some images to the image objects. First we add some images to our project. I used an up arrow and a down arrow image like these. From the Project Menu I selected Add Existing Object and browsed to where I had saved the Image files and added them to me. The show up in the Solution Explorer as follows: Now that these images are associated with out project we can add them to the image boxes we have on the screen. We will do this from the source property in the property box. Selecting the Source property will give us a dialog box like this:

We ll now associated the images with the associated up and down image box. Our User Interface is now essentially completed. Although we may want to think about adding more labels to make things a bit more clear for the user. Now it is time for some code though. We now open MainPage.xaml.cs from the Solution Explorer so that we can add some code. The first thing we need to do is declare some variables. public partial class MainPage : PhoneApplicationPage // Constructor int tippercentage; int splitamong; double totip; double total, basetab; double mysplit; Inside the Constructor function itself we will set some initial values. Note that there are named objects in this code to set some of the text values for objects that are part of our user interface. public MainPage() InitializeComponent(); tippercentage = 15; slider1.value = tippercentage; txttipp.text = tippercentage.tostring() + "%"; splitamong = 1; txthowmany.text = splitamong.tostring();

We need to do some calculations. We need to calculate the tip amount from the selected percentage. We need to create a new total amount to pay by adding the original bill amount to the tip amount. Lastly we need to calculate how to split the bill among one or more people. We will create a general purpose calculation function that we can call from many places in the program if we wish. private void docalcs() try basetab = double.parse(txttab.text); totip = tippercentage / 100.0 * basetab; txttip.text = totip.tostring("$###,##0.00"); total = basetab + totip; txttotal.text = total.tostring("$###,##0.00"); mysplit = total / splitamong; txtsplit.text = mysplit.tostring("$###,##0.00"); catch We will also create a method that can be called in response to tapping on various objects which will call there helper method. private void Calculate(object sender, GestureEventArgs e) docalcs(); Next we want to respond to changes in the tip amount. We want to display a new tip percentage as the slider is moved and then calculate a new tip amount based on that percentage. Note that we call the helper calculation routine from this routine. private void TipPer(object sender, RoutedPropertyChangedEventArgs<double> e) try tippercentage = (Int16)slider1.Value; txttipp.text = tippercentage.tostring() + "%"; docalcs(); catch Lastly we want to deal with the splitting on that tab among more than one person. We want methods that respond to taps on the up and down arrows. A tap should increase or decrease the number of people to split the tab among. Note that we don t want there to be less than one person.

private void DownSplit_Tap(object sender, GestureEventArgs e) if (splitamong > 1) splitamong = splitamong - 1; txthowmany.text = splitamong.tostring(); docalcs(); private void UpSplit_Tap(object sender, GestureEventArgs e) splitamong = splitamong + 1; txthowmany.text = splitamong.tostring(); docalcs(); Now we need to associate these methods with specific events. We will return to the ManPage.xaml tab to do this. Click on the UpArrow image to select it. On the Properties window select the Events tab. Selecting the Tap event will bring up a dropdown list that will include UpSplit_Tap which you will select. The same steps are followed to select DownSplit_Tap to respond to a tap on the down arrow. For the Slider bar we will select TipPer to respond to the ValueChanged event.

We will want the Calculate method to be called in response to taps on any one of several textblocks such as the Total box. We can now run our program on the Windows Phone Emulator (or on an actual device if we have a developer unlocked phone available.)

This isn t really the keyboard we want since we are just going to be entering numbers. We could have the user select the number keypad but it makes more sense to have the numeric keypad open by default. So let s fix that. We will do that by specifing InputScope. In the property window select the InputScope property and set it to InputScope. Now we need to take a look at the XAML code in the design code window. We ll find some code that looks like this: <TextBlock Height="33" HorizontalAlignment="Left" Margin="46,37,0,0" Name="textBlock1" Text="Meal Charge" VerticalAlignment="Top" Width="146" /> <TextBox Height="72" HorizontalAlignment="Left" Margin="269,20,0,0" Name="txtTab" Text="" VerticalAlignment="Top" Width="181" TextAlignment="Right"> <TextBox.InputScope> <InputScope /> </TextBox.InputScope> </TextBox> In the middle of this code we will specify that we want the CurrencyAmount keyboard as follows. <TextBox.InputScope> <InputScope> <InputScopeName NameValue="CurrencyAmount" /> </InputScope > Now when we run the program we get the numeric keypad.