7INDOWS 0HONE 2ECIPES ! 0ROBLEM 3OLUTION !PPROACH
■■■ &ABIO #LAUDIO &ERRACCHIATI %MANUELE 'AROFALO
7INDOWS 0HONE 2ECIPES #OPYRIGHT Ú BY &ABIO #LAUDIO &ERRACCHIATI AND %MANUELE 'AROFALO !LL RIGHTS RESERVED .O PART OF THIS WORK MAY BE REPRODUCED OR TRANSMITTED IN ANY FORM OR BY ANY MEANS ELECTRONIC OR MECHANICAL INCLUDING PHOTOCOPYING RECORDING OR BY ANY INFORMATION STORAGE OR RETRIEVAL SYSTEM WITHOUT THE PRIOR WRITTEN PERMISSION OF THE COPYRIGHT OWNER AND THE PUBLISHER )3". PBK )3". ELECTRONIC 4RADEMARKED NAMES LOGOS AND IMAGES MAY APPEAR IN THIS BOOK 2ATHER THAN USE A TRADEMARK SYMBOL WITH EVERY OCCURRENCE OF A TRADEMARKED NAME LOGO OR IMAGE WE USE THE NAMES LOGOS AND IMAGES ONLY IN AN EDITORIAL FASHION AND TO THE BENEFIT OF THE TRADEMARK OWNER WITH NO INTENTION OF INFRINGEMENT OF THE TRADEMARK 4HE USE IN THIS PUBLICATION OF TRADE NAMES TRADEMARKS SERVICE MARKS AND SIMILAR TERMS EVEN IF THEY ARE NOT IDENTIFIED AS SUCH IS NOT TO BE TAKEN AS AN EXPRESSION OF OPINION AS TO WHETHER OR NOT THEY ARE SUBJECT TO PROPRIETARY RIGHTS 0RESIDENT AND 0UBLISHER 0AUL -ANNING ,EAD %DITOR %WAN "UCKINGHAM 4ECHNICAL 2EVIEWER 3IMONA .ASETTI %DITORIAL "OARD 3TEVE !NGLIN -ARK "ECKNER %WAN "UCKINGHAM 'ARY #ORNELL *ONATHAN 'ENNICK *ONATHAN (ASSELL -ICHELLE ,OWMAN *AMES -ARKHAM -ATTHEW -OODIE *EFF /LSON *EFFREY 0EPPER &RANK 0OHLMANN $OUGLAS 0UNDICK "EN 2ENOW #LARKE $OMINIC 3HAKESHAFT -ATT 7ADE 4OM 7ELSH #OORDINATING %DITOR *ESSICA "ELANGER #OPY %DITOR 3HARON 7ILKEY 0RODUCTION 3UPPORT 0ATRICK #UNNINGHAM )NDEXER *ULIE 'RADY #OVER $ESIGNER !NNA )SHCHENKO $ISTRIBUTED TO THE BOOK TRADE WORLDWIDE BY 3PRINGER 3CIENCE"USINESS -EDIA ,,# 3PRING 3TREET TH &LOOR .EW 9ORK .9 0HONE 302).'%2 FAX E MAIL
[email protected] OR VISIT www.springeronline.com &OR INFORMATION ON TRANSLATIONS PLEASE E MAIL
[email protected] OR VISIT www.apress.com !PRESS AND FRIENDS OF %$ BOOKS MAY BE PURCHASED IN BULK FOR ACADEMIC CORPORATE OR PROMOTIONAL USE E"OOK VERSIONS AND LICENSES ARE ALSO AVAILABLE FOR MOST TITLES &OR MORE INFORMATION REFERENCE OUR 3PECIAL "ULK 3ALESE"OOK ,ICENSING WEB PAGE AT www.apress.com/bulk-sales 4HE INFORMATION IN THIS BOOK IS DISTRIBUTED ON AN hAS ISv BASIS WITHOUT WARRANTY !LTHOUGH EVERY PRECAUTION HAS BEEN TAKEN IN THE PREPARATION OF THIS WORK NEITHER THE AUTHORS NOR !PRESS SHALL HAVE ANY LIABILITY TO ANY PERSON OR ENTITY WITH RESPECT TO ANY LOSS OR DAMAGE CAUSED OR ALLEGED TO BE CAUSED DIRECTLY OR INDIRECTLY BY THE INFORMATION CONTAINED IN THIS WORK 4HE SOURCE CODE FOR THIS BOOK IS AVAILABLE TO READERS AT www.apress.com 9OU WILL NEED TO ANSWER QUESTIONS PERTAINING TO THIS BOOK IN ORDER TO SUCCESSFULLY DOWNLOAD THE CODE
Contents !BOUT THE !UTHORS XVII !BOUT THE 4ECHNICAL 2EVIEWER XVIII !CKNOWLEDGMENTS XIX !BOUT 4HIS "OOK XX ■#HAPTER )NTRODUCTION TO 7INDOWS 0HONE !PPLICATION $EVELOPMENT %XAMINING 7INDOWS 0HONE 0ROBLEM 3OLUTION
5NDERSTANDING THE $EVELOPMENT 4OOLS 0ROBLEM 3OLUTION (OW )T 7ORKS
#REATING A 3IMPLE 3ILVERLIGHT 7INDOWS 0HONE !PPLICATION 0ROBLEM 3OLUTION (OW )T 7ORKS 5SAGE
#REATING A 3IMPLE 8.! 7INDOWS 0HONE !PPLICATION 0ROBLEM 3OLUTION (OW )T 7ORKS 5SAGE
V
$EPLOYING THE !PPLICATION TO THE 7INDOWS 0HONE %MULATOR 0ROBLEM 3OLUTION 5SAGE
$EPLOYING THE 7INDOWS 0HONE !PPLICATION ON THE $EVICE 0ROBLEM 3OLUTION (OW )T 7ORKS 5SAGE
3ENDING A 7INDOWS 0HONE !PPLICATION TO THE -ARKETPLACE 0ROBLEM 3OLUTION (OW )T 7ORKS
#REATING A 4RIAL 7INDOWS 0HONE !PPLICATION 0ROBLEM 3OLUTION (OW )T 7ORKS 5SAGE
■#HAPTER 7INDOWS 0HONE %XECUTION -ODEL .AVIGATING "ETWEEN 0AGES 0ROBLEM 3OLUTION (OW )T 7ORKS 4HE #ODE 5SAGE
0ASSING $ATA 4HROUGH 0AGES 0ROBLEM 3OLUTION
VI
(OW )T 7ORKS ......................................................................................................................................... 4HE #ODE................................................................................................................................................ 5SAGE ...................................................................................................................................................
.AVIGATING "ETWEEN 0AGES BY 5SING 'LOBAL !PPLICATION 6ARIABLES ......................... 0ROBLEM ................................................................................................................................................. 3OLUTION ................................................................................................................................................. (OW )T 7ORKS ......................................................................................................................................... 4HE #ODE................................................................................................................................................ 5SAGE ...................................................................................................................................................
.AVIGATING "ETWEEN 0AGES WITH 3TATE .................................................................... 0ROBLEM ................................................................................................................................................. 3OLUTION ................................................................................................................................................. (OW )T 7ORKS ......................................................................................................................................... 4HE #ODE................................................................................................................................................ 5SAGE ...................................................................................................................................................
-ANAGING 4OMBSTONING IN 7INDOWS 0HONE 3ILVERLIGHT !PPLICATIONS ................... 0ROBLEM ................................................................................................................................................. 3OLUTION ................................................................................................................................................. (OW )T 7ORKS ......................................................................................................................................... 4HE #ODE................................................................................................................................................ 5SAGE ...................................................................................................................................................
-ANAGING 4OMBSTONING IN 7INDOWS 0HONE 8.! !PPLICATIONS ............................ 0ROBLEM ................................................................................................................................................. 3OLUTION ................................................................................................................................................. (OW )T 7ORKS ......................................................................................................................................... 4HE #ODE................................................................................................................................................ 5SAGE ...................................................................................................................................................
VII
-ANAGING /BSCURED AND 5NOBSCURED %VENTS 0ROBLEM 3OLUTION (OW )T 7ORKS 4HE #ODE 5SAGE
■#HAPTER 5SER )NTERFACE #REATING AN !NIMATED 3PLASH 3CREEN 0ROBLEM 3OLUTION (OW )T 7ORKS 4HE #ODE 5SAGE
5SING THE !PPLICATION"AR #ONTROL 0ROBLEM 3OLUTION (OW )T 7ORKS 4HE #ODE 5SAGE
$ETECTING #HANGES IN THE 4HEME 4EMPLATE 0ROBLEM 3OLUTION (OW )T 7ORKS 4HE #ODE 5SAGE
#USTOMIZING THE 3OFT )NPUT 0ANEL +EYBOARD TO !CCEPT /NLY .UMBERS 0ROBLEM 3OLUTION (OW )T 7ORKS
VIII
4HE #ODE 5SAGE
5SING THE 7INDOWS 0HONE 0REDEFINED 3TYLES 0ROBLEM 3OLUTION (OW )T 7ORKS 4HE #ODE 5SAGE
,OCALIZING 9OUR !PPLICATION 0ROBLEM 3OLUTION (OW )T 7ORKS 4HE #ODE 5SAGE
5SING 0ANORAMA AND 0IVOT #ONTROLS 0ROBLEM 3OLUTION (OW )T 7ORKS 4HE #ODE 5SAGE
3PICING 5P THE 5SER )NTERFACE WITH THE 3ILVERLIGHT 4OOLKIT 0ROBLEM 3OLUTION (OW )T 7ORKS 4HE #ODE 5SAGE
5SING ,AUNCHERS AND #HOOSERS 0ROBLEM 3OLUTION
IX
(OW )T 7ORKS 4HE #ODE 5SAGE
■#HAPTER 5SER )NTERFACE 7ITH %XPRESSION "LEND 'ETTING 2EADY FOR ,IGHT AND $ARK 0ROBLEM 3OLUTION (OW )T 7ORKS 4HE #ODE 5SAGE
#HANGING THE 3KIN OF 9OUR !PP 0ROBLEM 3OLUTION (OW )T 7ORKS 5SAGE
#REATING 3OME #OOL !NIMATION 0ROBLEM 3OLUTION (OW )T 7ORKS 4HE #ODE 5SAGE
#USTOMIZING A #ONTROL 0ROBLEM 3OLUTION (OW )T 7ORKS 4HE #ODE 5SAGE
X
■#HAPTER 'ESTURES -ANAGING 'ESTURES IN A 3ILVERLIGHT 7INDOWS 0HONE !PPLICATION 0ROBLEM 3OLUTION (OW )T 7ORKS 4HE #ODE 5SAGE
!DDING 'ESTURES -ANAGEMENT TO #LICK LESS 3ILVERLIGHT #ONTROLS 0ROBLEM 3OLUTION (OW )T 7ORKS 4HE #ODE 5SAGE
(ANDLING 'ESTURES IN A 'RAPHICAL #ONTEXT 3UCH AS A 'AME -ENU 0ROBLEM 3OLUTION (OW )T 7ORKS 4HE #ODE 5SAGE
-ANAGING 'ESTURES FROM THE 3ILVERLIGHT FOR 7INDOWS 0HONE 4OOLKIT 0ROBLEM 3OLUTION (OW )T 7ORKS 5SAGE
■#HAPTER 3ENSORS 2ESETTING A FORM BY SHAKING THE PHONE 0ROBLEM 3OLUTION
XI
(OW )T 7ORKS 4HE #ODE 5SAGE
#REATING A 3EISMOGRAPH 0ROBLEM 3OLUTION (OW )T 7ORKS 4HE #ODE 5SAGE
)NDICATING THE 5SERS 0OSITION 0ROBLEM 3OLUTION (OW )T 7ORKS 4HE #ODE 5SAGE
$ISPLAYING 3UNSET AND 3UNRISE 0ROBLEM 3OLUTION (OW )T 7ORKS 4HE #ODE 5SAGE
)NDICATING THE 5SERS 0OSITION VIA #OORDINATES 0ROBLEM 3OLUTION (OW )T 7ORKS 4HE #ODE 5SAGE
XII
5SING THE 2ADIO 0ROBLEM 3OLUTION (OW )T 7ORKS 4HE #ODE 5SAGE
■#HAPTER -EDIA -ANAGEMENT 4AKING A 0HOTO FROM 9OUR 0HONE #AMERA 0ROBLEM 3OLUTION (OW )T 7ORKS 4HE #ODE 5SAGE
0ICKING A 0HOTO FROM 9OUR -EDIA ,IBRARY 0ROBLEM 3OLUTION (OW )T 7ORKS 4HE #ODE 5SAGE
5SING -EDIA 0LAYER TO 3HUFFLE 3ONGS IN 9OUR -EDIA ,IBRARY 0ROBLEM 3OLUTION (OW )T 7ORKS 4HE #ODE 5SAGE
5SING THE -ICROPHONE IN THE &UNNY 2EPEATER !PPLICATION 0ROBLEM 3OLUTION (OW )T 7ORKS
XIII
4HE #ODE 5SAGE
5SING THE -EDIA%LEMENT #ONTROL TO 0LAY "OTH -USIC AND 6IDEO 0ROBLEM 3OLUTION (OW )T 7ORKS 4HE #ODE 5SAGE
!DDING )NTEGRATION WITH THE -USIC 6IDEOS (UB 0ROBLEM 3OLUTION (OW )T 7ORKS 4HE #ODE 5SAGE
■#HAPTER )SOLATED 3TORAGE 3AVING A &ILE IN )SOLATED 3TORAGE AND ,OADING )T 0ROBLEM 3OLUTION (OW )T 7ORKS 4HE #ODE 5SAGE
3AVING 3ERIALIZED $ATA 0ROBLEM 3OLUTION (OW )T 7ORKS 4HE #ODE 5SAGE
XIV
-ODIFYING 3ETTINGS OF 9OUR !PPLICATION 0ROBLEM 3OLUTION (OW )T 7ORKS 4HE #ODE 5SAGE
3AVING A 0HOTO IN )SOLATED 3TORAGE 0ROBLEM 3OLUTION (OW )T 7ORKS 4HE #ODE 5SAGE
■#HAPTER )N THE #LOUD )NTERACTING WITH 7#& 0ROBLEM 3OLUTION (OW )T 7ORKS 4HE #ODE 5SAGE
#REATING A &EED 2EADER 0ROBLEM 3OLUTION (OW )T 7ORKS 4HE #ODE 5SAGE
#REATING A 'OOGLE !0)n"ASED 4RANSLATOR 0ROBLEM 3OLUTION (OW )T 7ORKS
XV
The Code............................................................................................................................................... 299 Usage.................................................................................................................................................... 302
9-4. Pushing Your Notification ....................................................................................... 302 Problem ................................................................................................................................................ 302 Solution ................................................................................................................................................ 303 How It Works ........................................................................................................................................ 303 The Code............................................................................................................................................... 307 Usage.................................................................................................................................................... 315
■Chapter 10: Testing Windows Phone Applications .............................................. 317 10-1. Implementing MVVM on Windows Phone by Using MVVMLight ........................... 318 Problem ................................................................................................................................................ 318 Solution ................................................................................................................................................ 318 How It Works ........................................................................................................................................ 318 The Code............................................................................................................................................... 320 Usage.................................................................................................................................................... 329
10-2. Using MVVM and Performing Unit Testing............................................................ 330 Problem ................................................................................................................................................ 330 Solution ................................................................................................................................................ 330 How It Works ........................................................................................................................................ 330 The Code............................................................................................................................................... 330 Usage.................................................................................................................................................... 333
Index ....................................................................................................................... 335
xvi
About the Authors ■&ABIO #LAUDIO &ERRACCHIATI IS A PROLIFIC WRITER AND TECHNICAL REVIEWER ON CUTTING EDGE TECHNOLOGIES (E HAS CONTRIBUTED TO MANY BOOKS ON .%4 # 6ISUAL "ASIC 31, 3ERVER 3ILVERLIGHT AND !30.%4 (E IS A .%4 -ICROSOFT #ERTIFIED 3OLUTION $EVELOPER -#3$ AND LIVES IN 2OME )TALY (E IS EMPLOYED BY "RAIN &ORCE ■%MANUELE 'AROFALO WAS BORN AT 4ORRE DEL 'RECO .APLES )TALY AND NOW LIVES IN 2OME (E IS AN ACTIVE MEMBER OF THE $OT.ET#AMPANIA COMMUNITY AND WORKS WITH 7INDOWS 0RESENTATION &OUNDATION 70& 3ILVERLIGHT 7INDOWS #OMMUNICATION &OUNDATION 7#& AND ,ANGUAGE )NTEGRATED 1UERY ,).1 AS PRINCIPAL TECHNOLOGIES
XVII
About the Technical Reviewer ■3IMONA .ASETTI IS AN EXPERT -ICROSOFT $YNAMICS #2- AND -ICROSOFT 31, 3ERVER "USINESS )NTELLIGENCE CONSULTANT 3HE GRADUATED WITH A MATHEMATICS DEGREE AND WORKS AT !GIC 4ECHNOLOGY www.agic.it IN 2OME )TALY WHERE SHE CREATES VERTICAL SOLUTIONS AND REPORTS FOR THE COMPANYS CLIENTS
XVIII
Acknowledgments &IRST OF ALL )gD LIKE TO THANK %WAN "UCKINGHAM $URING THESE YEARS WE HAD WORKING EXPERINCES TOGETHER AND HE HAS BEEN ALWAYS PATIENT KIND AND HELPFUL )gD ALSO LIKE TO THANK %MANUELE FOR THE GREAT JOB HE DID WORKING WITH ME TO COMPLETE THIS BOOK -OREOVER THE !PRESS GUYS EACH OF YOU HAVE BEEN GREAT 3O THANKS TO *ESSICA "ELANGER $OMINIC 3HAKESHAFT #HRISTINE 2ICKETTS AND 3HARON 7ILKEY &INALLY MY WIFE 3IMONA FOR HER EFFORTS ESPECIALLY TRYING TO QUIET MY DAUGHTERgS SCREAMS WHILE ) WAS WRITING THE BOOK 7AIT THANKS TO 6gS AUTHORS THEY DISTRACT ME WITH VERY COOL EPISODES &ABIO #LAUDIO &ERRACCHIATI 4HANKS TO !LESSANDRA FOR HER PATIENCE DURING THE WRITING OF THIS BOOK TO &ABIO FOR THE OPPORTUNITY TO WRITE THIS BOOK TO %WAN *ESSICA 3HARON AND ALL THE STAFF OF !PRESS FOR THEIR SUPPORT AND TO -ICHELE !PONTE AND ALL THE $OT.ET#AMPANIA COMMUNITY FOR THE MOTIVATION TO STUDY NEW TECHNOLOGIES WITH THE SPIRIT OF KNOWLEDGE SHARING %MANUELE 'AROFALO
XIX
About This Book !RE YOU INTERESTED IN 7INDOWS 0HONE CONFIGURATION AND DEVELOPMENT ,EARN TO BUILD CONFIGURE AND DISTRIBUTE YOUR APPLICATIONS THROUGH A WIDE VARIETY OF STEP BY STEP RECIPES 4HIS BOOK CONTAINS EXTENSIVE CODE SAMPLES AND DETAILED WALK THROUGHS
XX
Contents at a Glance About the Author .................................................................................................... xvii About the Technical Reviewer ............................................................................... xviii Acknowledgments ................................................................................................... xix About This Book........................................................................................................ xx ■Chapter 1: Introduction to Windows Phone 7 Application Development ................. 1 ■Chapter 2: Windows Phone 7 Execution Model .................................................... 33 ■Chapter 3: User Interface....................................................................................... 73 ■Chapter 4: User Interface With Expression Blend ............................................... 145 ■Chapter 5: Gestures ............................................................................................. 167 ■Chapter 6: Sensors .............................................................................................. 189 ■Chapter 7: Media Management............................................................................ 219 ■Chapter 8: Isolated Storage ................................................................................. 261 ■Chapter 9: In the Cloud ........................................................................................ 285 ■Chapter 10: Testing Windows Phone Applications .............................................. 317 Index ....................................................................................................................... 335
iv
CHAPTER 1 ■■■
Introduction to Windows Phone 7 Application Development 4HIS CHAPTER INTRODUCES 7INDOWS 0HONE INCLUDING ITS DEVICE HARDWARE CHARACTERISTICS AND SOFTWARE DEVELOPMENT TOOLS !FTER THIS INTRODUCTION YOU WILL LEARN HOW TO CREATE SIMPLE APPLICATIONS AND HOW TO DEPLOY THEM &INALLY YOU ARE GOING TO LOOK AT THE APPLICATIONS DISTRIBUTION VIA 7INDOWS 0HONE -ARKETPLACE 4HE RECIPES IN THIS CHAPTER DESCRIBE HOW TO DO THE FOLLOWING v
%XAMINE 7INDOWS 0HONE HARDWARE
v
%XAMINE 7INDOWS 0HONE DEVELOPMENT TOOLS
v
AND #REATE A SIMPLE 7INDOWS 0HONE 3ILVERLIGHT AND 8.! APPLICATION
v
AND $EPLOY A 7INDOWS 0HONE APPLICATION ON BOTH THE EMULATOR AND DEVICE
v
0UT A 7INDOWS 0HONE APPLICATION INTO 7INDOWS 0HONE -ARKETPLACE
v
#REATE A 7INDOWS 0HONE TRIAL APPLICATION
%XAMINING 7INDOWS 0HONE 0ROBLEM 9OU HAVE JUST BOUGHT YOUR NEW 7INDOWS 0HONE DEVICE AND WOULD LIKE TO START DEVELOPING APPLICATIONS 9OU NEED TO KNOW THE DEVICES HARDWARE CHARACTERISTICS SUCH AS SCREEN RESOLUTION AND MEMORY CAPABILITYBUT ALSO WHICH SENSORS AND SERVICES IT PROVIDES &INALLY YOU NEED TO UNDERSTAND WHAT THE 7INDOWS 0HONE OPERATING SYSTEM PROVIDES IN ORDER TO INTEGRATE YOUR APPLICATION IN THE BEST WAY
3OLUTION )F YOU HAVE 7INDOWS -OBILE DEVELOPMENT EXPERIENCE PLEASE ERASE IT *OKING ASIDE -ICROSOFT HAS PROVIDED A BRAND NEW OPERATING SYSTEM FOR ITS NEW SMARTPHONE 7INDOWS 0HONE 4HIS OPERATING
SYSTEM HAS BEEN WRITTEN FROM SCRATCH IN ORDER TO REACHAND SOMETIME GO BEYONDOTHER OPERATING SYSTEMS FUNCTIONALITIES 4O MAKE AN OPERATING SYSTEM THAT IS RELIABLE AND FAST AND HAS HIGH PERFORMANCE -ICROSOFT HAS DICTATED HARDWARE REQUIREMENTS 3O EVERY 7INDOWS 0HONE nCOMPATIBLE PHONE ON THE MARKET RIGHT NOW AND IN THE FUTURE HAS OR WILL HAVE AT LEAST MINIMUM COMMON HARDWARE CHARACTERISTICS &OR US AS DEVELOPERS THIS IS GREAT NEWS BECAUSE WE CAN WRITE CODE HAVING SOME CERTAINTY OF WHAT THE SMARTPHONE PROVIDES 4HE 7INDOWS 0HONE DEVICE PROVIDES A SCREEN RESOLUTION OF ¾ PIXELS IN PORTRAIT ORIENTATION )N THE FUTURE MOBILE VENDORS PLAN TO RELEASE SMARTPHONES WITH SMALLER SCREENS HAVING A RESOLUTION OF ¾ PIXELS (AVING THIS IN MIND YOU CAN CREATE A GAME AND DRAW YOUR SPRITES KNOWING THAT YOUR GAME WILL BE PLAYED ON A SCREEN WITH THAT RESOLUTIONSO NO SCALE OPERATIONS SCREEN TEXT ADAPTATION AND SO FORTH WILL BE NECESSARY "UT EVEN FOR CLASSIC APPLICATIONS SHOWING FOR EXAMPLE TEXT BOXES AND BUTTONS THIS RESOLUTION IS USEFUL FOR DRAWING RICH USER INTERFACES %VERY PHONE PROVIDES THREE HARDWARE BUTTONS USUALLY AT THE BOTTOM OF THE SCREEN AS SHOWN IN &IGURE 4HEY ARE THE "ACK BUTTON THE 3TART BUTTON AND THE 3EARCH BUTTON 4HE LEFTMOST BUTTON IS USED TO GO BACK TO THE PREVIOUS APPLICATION JUST LIKE THE "ACK BUTTON ON AN )NTERNET BROWSER 4HE MIDDLE BUTTON IS USED TO CLOSE THE CURRENT APPLICATION AND TO SHOW THE 3TART MENU SO THAT THE USER CAN OPEN ANOTHER APPLICATION 4HE RIGHTMOST BUTTON IS USED TO ACCESS THE START SCREEN AND START A SEARCH FOR EXAMPLE A SEARCH INTO THE PHONE CONTENT FOR CONTACTS OR A SEARCH ON THE "ING SITE
&IGURE !N IMAGE OF A GENERIC 7INDOWS 0HONE DEVICE
&ROM A DEVELOPERS POINT OF VIEW IT IS IMPORTANT TO UNDERSTAND THE IMPACT THAT THESE BUTTONS HAVE ON AN APPLICATION 7HEN EACH BUTTON IS PRESSED THE RUNNING APPLICATION IS EITHER DEACTIVATED OR KILLED ! DEVELOPER HAS TO PROVIDE CODE THAT RESPONDS TO THOSE EVENTS PERHAPS SAVING DATA IN ISOLATED STORAGE AN APPLICATIONS DISK DEDICATED STORAGE 4O REDISPLAY THE APPLICATION PERHAPS AFTER THE USER PUSHES THE "ACK BUTTON CODE HAS TO HAVE BEEN WRITTEN IN ORDER TO RE CREATE THE SAME SITUATION PRESENT BEFORE THE DEACTIVATION 9OU CAN SEE MORE ON THIS IN #HAPTER 7INDOWS 0HONE DEVICES HAVE A 3OFT )NPUT 0ANEL 3)0 THAT ENABLES USERS TO WRITE TEXT INTO TEXT BOXES ! HARDWARE KEYBOARD IS OPTIONAL )N BOTH CASES THE APPLICATION WILL RECEIVE TEXT INPUT IN THE SAME MANNER 4HE SAME IS TRUE FOR KEY PRESSURE EVENTS 4HE 3)0 IS SHOWN AUTOMATICALLY BY 7INDOWS 0HONE WHEN TEXT INPUT IS REQUIRED BY THE USER )N &IGURE YOU CAN SEE THE 7INDOWS 0HONE STARTING PAGE AND ITS NEW -ETRO USER INTERFACE -ICROSOFT DESIGNERS WITH USERS FEEDBACK HAVE PREFERRED TO PUT THE ACCENT ON CONTENT AND INFORMATION INSTEAD OF EYE CATCHING GRAPHICS 3O THE SCREEN IS POPULATED WITH SOMETHING SIMILAR TO EITHER METRO OR AIRPORT BANNERS %VERY SQUARE AND RECTANGLE IS CALLED A LIVE TILE AND GIVES ACCESS TO THE HUB %ACH LIVE TILE IS UPDATED IN REAL TIME WITH INFORMATION TAKEN FROM THE HUB 4HE HUB IS A SORT OF AGGREGATOR TO GROUP SIMILAR INFORMATION SUCH AS GROUP PHOTOS TAKEN FROM THE WEB FROM THE PHONE ITSELF AND FROM SOCIAL NETWORKS &OR EXAMPLE THE /FFICE TILE WILL SHOW COUNTER INDICATING THE NUMBER OF INCOMING E MAIL WHEN A NEW E MAIL ARRIVES 3O THE HUB CONTAINS AN AGGREGATION OF INFORMATION THAT IS BOTH LOCAL ON THE PHONE AND REMOTE ON THE CLOUD AND FROM THE )NTERNET &OR EXAMPLE THE 0ICTURES HUB CONTAINS PHOTOS TAKEN FROM THE INTERNAL CAMERA AND FROM SOCIAL NETWORKS SUCH AS &ACEBOOK 4HERE ARE SIX HUBS PROVIDED WITH 7INDOWS 0HONE v
0EOPLE
v
/FFICE
v
0ICTURES
v
-USIC AND 6IDEOS
v
-ARKETPLACE
v
'AMES
"Y THE WAY THE PHONE IS COMPLETELY CUSTOMIZABLE SO YOU CAN REMOVE LIVE TILES ADD YOUR PREFERRED ONES MOVE TILES AND SO ON 5SERS CAN CHOOSE BETWEEN TWO GRAPHICS THEMES DARK OR LIGHT %ACH PRESENTS A DIFFERENT BACKGROUND COLOR BLACK AND WHITE RESPECTIVELY WHICH IS IMPORTANT TO BE AWARE OF AS YOU DRAW YOUR ICONS BUTTONS AND IMAGES FOR AN APPLICATION 4HE USER CAN INTERACT WITH 7INDOWS 0HONE BY USING ITS MULTI TOUCH SCREEN 5SING YOUR FINGERS TO PERFORM VARIOUS GESTURES SUCH AS TAPS YOU CAN MOVE THE TILES ZOOM IN AND ZOOM OUT ON TEXT AND PICTURES AND SO ON %VERY VENDOR THAT PRODUCES 7INDOWS 0HONE DEVICES MUST PROVIDE AT LEAST A FOUR POINT MULTI TOUCH CAPACITIVE SCREEN SO THAT YOU CAN USE AT LEAST FOUR FINGERS ON THE TOUCH SCREEN 4HE 7INDOWS 0HONE DEVICE SHIPS WITH -" OR MORE OF 2!- AND WITH '" OR MORE OF FLASH STORAGE 4HE #05 IS AN !2-V WITH AT LEAST '(Z OF FREQUENCY &INALLY THE 7INDOWS 0HONE DEVICE PROVIDES SENSORS AND SERVICES TO BRING THE USER EXPERIENCE TO THE NEXT LEVEL (ERE IS A LIST OF THE MOST IMPORTANT ONES ! '03 4HIS SENSOR IS THE !SSISTED 'LOBAL 0OSITIONING 3YSTEM )T ENABLES USERS TO RETRIEVE THEIR POSITION IN THE WORLD IN TERMS OF LONGITUDE AND LATITUDE COORDINATES TAKEN FROM BOTH SATELLITE SERVICES AND CELL SITE TRIANGULATION 4HE LATTER IS LESS ACCURATE BECAUSE IT REPRESENTS THE NEAREST RADIO NETWORK FROM THE PHONE POSITION BUT IT IS USEFUL WHEN SATELLITE SIGNALS ARE LOW OR ABSENT
!CCELEROMETER 4HIS SENSOR ENABLES PROGRAMS TO UNDERSTAND WHEN THE PHONE HAS BEEN MOVEDFOR EXAMPLE EITHER BECAUSE THE USER HAS TAKEN IT FROM THE DESK TO RESPOND TO A CALL OR WORSE THE PHONE IS FALLING FROM THE USERS HANDS 7I &I 4HIS SENSOR ENABLES THE PHONE TO CONNECT TO A 7I &I SPOT FOR AN )NTERNET CONNECTION #AMERA 4HIS SENSOR ENABLES USERS TO TAKE PHOTOS AND VIDEOS THROUGH A MEGAPIXEL OR MORE CAMERA WITH FLASH /FFICE 4HIS SERVICE IS NOT SO ADVERTISED BUT EVERY PHONE HAS A VERY USABLE AND POWERFUL VERSION OF -ICROSOFT /FFICE WITH ITS COMMON APPLICATIONS SUCH AS 7ORD %XCEL /UTLOOK AND 0OWER0OINT ,OCATION 4HANKS TO THIS SERVICE A USER CAN BE LOCATED AND THAT USERS POSITION CAN BE REPRESENTED VIA "ING -APS 0USH .OTIFICATIONS 4HIS IS A GREAT SERVICE THAT PREVENTS PHONE TO POLLING INFORMATION FROM THE )NTERNET 4HE PHONE WAITS TO RECEIVE NOTIFICATIONS FROM PROGRAMS THAT LIVE OUTSIDE THE PHONE AVOIDING TO CONTINUALLY GOING TO SEARCH FOR NEW INFORMATIONS $EVELOPERS CAN USE ALL THESE SENSORS AND SERVICES TOGETHER TO CREATE INNOVATIVE APPLICATIONS AND SELL THEM ON 7INDOWS 0HONE -ARKETPLACE 4HEY DO NOT HAVE TO WORRY ABOUT HARDWARE DIFFERENCES FOR EXAMPLE WHETHER A CERTAIN CELL MODEL HAS THE ACCELEROMETER BECAUSE EVERY 7INDOWS 0HONE HAS THE SAME MINIMUM FEATURES
5NDERSTANDING THE $EVELOPMENT 4OOLS 0ROBLEM 9OU WANT TO START DEVELOPING FOR 7INDOWS 0HONE 9OU WANT TO KNOW WHICH TOOLS AND WHICH LANGUAGES YOU HAVE TO USE TO MAKE AN APPLICATION
3OLUTION 9OU HAVE TO DOWNLOAD THE -ICROSOFT 7INDOWS 0HONE $EVELOPER 4OOLS
(OW )T 7ORKS 7E STARTED 2ECIPE SAYING THAT IF YOU HAVE 7INDOWS -OBILE DEVELOPMENT EXPERIENCE IT IS BETTER TO ERASE IT 4HIS IS A JOKE OF COURSE BUT IT IS NOT COMPLETELY FALSE )N 7INDOWS 0HONE DEVELOPMENT YOU DONT HAVE THE FREEDOM TO CREATE LOW LEVEL APPLICATIONS WITH # OR # LANGUAGES 5SING .%4 IS THE ONLY WAY ALLOWED BY -ICROSOFT TO DEVELOP YOUR APPLICATIONS FOR 7INDOWS 0HONE %VEN IF YOU FIND A WAY TO GO AROUND THIS LIMITATIONLETS SAY BY INJECTING SOME )NTERMEDIATE ,ANGUAGE ), CODE AT RUNTIMEYOU STILL HAVE TO REMEMBER THAT EVERY APPLICATION WILL BE DISTRIBUTED BY 7INDOWS 0HONE -ARKETPLACE !ND OF COURSE BEFORE USERS CAN FIND YOUR APPLICATION ON -ARKETPLACE THAT APPLICATION HAS TO GO THROUGH DIFFERENT APPROVAL STEPS AND YOU CAN BE SURE THAT ANY NON .%4 APPLICATION WOULD NOT PASS THE CERTIFICATION PROCESS
9OU CAN CREATE TWO KINDS OF APPLICATIONS 3ILVERLIGHT FOR 7INDOWS 0HONE AND 8.! FOR 7INDOWS 0HONE 4HE FORMER USES A CUSTOM 3ILVERLIGHT VERSION IN WHICH -ICROSOFT HAS ADDED SOME SPECIFIC FEATURES 4HE LATTER USES 8.! LIBRARIES AND IS TARGETED AT CREATING VIDEOGAMES 9OU CAN COMBINE BOTH TECHNOLOGIES IN YOUR APPLICATION WITH THE ONLY LIMITATION BEING THE USER INTERFACE YOU CANT DRAW CONTROLS BY USING 3ILVERLIGHT AND USE 8.! TO DRAW SPRITES AT THE SAME TIME /N THE OTHER HAND YOU CAN USE 3ILVERLIGHT FOR THE USER INTERFACE AND 8.! LIBRARIES TO PROVIDE FULL ACCESS TO MEDIA STORAGE ON THE PHONE TO CAPTURE AUDIO AND MORE # IS ACTUALLY THE ONLY LANGUAGE THAT HAS FULL SUPPORT ON BOTH 3ILVERLIGHT AND 8.! TECHNOLOGIES !T THE TIME OF THIS WRITING WITH 6ISUAL "ASIC YOU CAN DEVELOP ONLY 3ILVERLIGHT APPLICATIONS 4O START DEVELOPING YOU FIRST HAVE TO DOWNLOAD THE 7INDOWS 0HONE $EVELOPER 4OOLS FROM Wcc_)V^\XRa^b^UcR^\Uf[X]Z.;X]Z83, '($$# 4HIS SETUP INCLUDES 6ISUAL 3TUDIO %XPRESS FOR 7INDOWS 0HONE 7INDOWS 0HONE %MULATOR 3ILVERLIGHT 4OOLS 8.! AND -ICROSOFT %XPRESSION "LENDFOR 7INDOWS 0HONE )F YOU ALREADY HAVE 6ISUAL 3TUDIO INSTALLED ON YOUR MACHINE THE SETUP WILL INSTALL ONLY THE NECESSARY FILES AND YOU WILL SEE NEW PROJECT TEMPLATES THE NEXT TIME YOU START THE DEVELOPMENT TOOL
■ .OTE !T THE TIME OF THIS WRITING 6ISUAL 3TUDIO %XPRESS DOESNT SUPPORT 6ISUAL "ASIC 9OU MUST HAVE 6ISUAL 3TUDIO 0ROFESSIONAL OR 3UPERIOR TO USE 6ISUAL "ASIC 9OU CAN ALWAYS DOWNLOAD A 6ISUAL 3TUDIO TRIAL VERSION
,ETS SEE THE NECESSARY STEPS TO INSTALL THE -ICROSOFT 7INDOWS 0HONE $EVELOPER 4OOLS
,AUNCH THE INSTALLER e\NfTQTgT AFTER HAVING DOWNLOADED IT
!CCEPT THE LICENSE AGREEMENT
/PTIONALLY CHOOSE THE #USTOMIZED INSTALLATION SO YOU CAN SELECT A FOLDER IN WHICH TO INSTALL THE TOOLS
7AIT FOR THE INSTALLER TO DOWNLOAD ALL THE NECESSARY FILES FROM THE )NTERNET 4HE NUMBER OF FILES DOWNLOADED DEPENDS ON WHAT THE INSTALLER FINDS ALREADY IN YOUR OPERATING SYSTEM
)F YOU HAVE TO INSTALL THE DEVELOPER TOOLS ON MACHINES NOT CONNECTED TO THE )NTERNET YOU CAN USE THE )3/ VERSION FROM Wcc_)V^\XRa^b^UcR^\ Uf[X]Z.;X]Z8S,! (!&
4HE NEXT STEP IS TO DOWNLOAD THE 7INDOWS 0HONE $EVELOPER 4OOLS /CTOBER UPDATE WHICH INCLUDES SOME UPDATES SUCH AS THE 7INDOWS 0HONE #ONNECTION 4OOL SOME CHANGES TO "ING -APS FOR THE 7INDOWS 0HONE 3ILVERLIGHT CONTROL AND A TOOL TO DETECT PHONE CAPABILITIES "Y THE WAY SINCE THINGS ARE MOVING SO FAST IN THE 7INDOWS 0HONE PANORAMA -ICROSOFTS !PP (UB SITE AT Wcc_)RaTPcT \bS]R^\T]DB SHOULD BE THE STARTING POINT FOR EVERY DEVELOPER
#REATING A 3IMPLE 3ILVERLIGHT 7INDOWS 0HONE !PPLICATION 0ROBLEM 9OU HAVE TO CREATE A 7INDOWS 0HONE APPLICATION BY USING 3ILVERLIGHT
3OLUTION 5SE 6ISUAL 3TUDIO EITHER THE %XPRESS 0ROFESSIONAL OR 3UPERIOR EDITION 5SE THE 7INDOWS 0HONE !PPLICATION PROJECT TEMPLATE
(OW )T 7ORKS !FTER OPENING 6ISUAL 3TUDIO YOU HAVE TO CREATE A NEW PROJECT &ROM THE &ILE MENU CHOOSE .EW )TEM ➤ 0ROJECT ITEM OR PRESS #TRL3HIFT. &IGURE SHOWS THE DIALOG BOX THAT APPEARS AFTER LAUNCHING THE .EW 0ROJECT COMMAND
&IGURE 6ISUAL 3TUDIO .EW 0ROJECT DIALOG BOX
&ROM THE )NSTALLED 4EMPLATES ON THE LEFT SELECT 3ILVERLIGHT FOR 7INDOWS 0HONE 4HERE ARE FIVE PROJECT TEMPLATES PROVIDED BY 6ISUAL 3TUDIO v
7INDOWS 0HONE !PPLICATION CREATES A SKELETON CODE FOR A GENERIC PHONE APPLICATION NO CONTROLS OR OTHER STUFF ARE ADDED
v
7INDOWS 0HONE $ATABOUND !PPLICATION CREATES A 7INDOWS 0HONE APPLICATION ADDING ,IST AND .AVIGATION CONTROLS
v
7INDOWS 0HONE #LASS ,IBRARY CREATES A SKELETON CODE FOR AN EXTERNAL ASSEMBLY SPECIFIC TO 7INDOWS 0HONE
v
7INDOWS 0HONE 0ANORAMA !PPLICATION CREATES AN APPLICATION INCLUDING THE 0ANORAMA CONTROL SEE MORE ON THAT IN #HAPTER 2ECIPE
v
7INDOWS 0HONE 0IVOT !PPLICATION CREATES AN APPLICATION INCLUDING THE 0IVOT CONTROL SEE MORE ON THAT IN #HAPTER 2ECIPE
3ELECT THE 7INDOWS 0HONE !PPLICATION PROJECT TEMPLATE AND TYPE BX\_[TBX[eTa[XVWc0__[XRPcX^] IN THE PROJECTS .AME TEXT BOX #HOOSE A ,OCATION WHERE TO SAVE THE PROJECT AND THEN CLICK THE /+ BUTTON 7AIT WHILE 6ISUAL 3TUDIO WRITES EVERY FILE AND FOLDER AND AFTER A FEW SECONDS YOU SHOULD HAVE a3TUPd[c+4gTaRXbTBTccX]Vb-* l
T[bT j TgTaRXbT , ]Tf 4gTaRXbTBTccX]Vb* TgTaRXbTXS , 6dXS=Tf6dXS* l TgTaRXbT3TbRaX_cX^] , cgc3TbRaX_cX^]CTgc* TgTaRXbT=P\T , cgc=P\TCTgc* TgTaRXbT3daPcX^] , X]c?PabTcgc3daPcX^]CTgc* XU Q=Tf 0__[XRPcX^]2daaT]c Pb 0__4gTaRXbTb0SSTgTaRXbT* 2[TP]* l T[bT ]0RcXePcTS AND >]3TPRcXePcTS EVENT HANDLERS PROVIDED BY THE 6P\T CLASS
(OW )T 7ORKS %VERYTHING YOU STUDIED IN THE PREVIOUS RECIPES ON TOMBSTONING INCLUDING BcPcT COLLECTION IS VALID FOR 8.! GAMES TOO 4HE BIG DIFFERENCE IS THE EVENTS RAISED WHEN THE APPLICATION IS TOMBSTONED !N 8.! GAME RESPONDS TO THE >]0RcXePcTS EVENT WHEN THE APPLICATION IS EITHER RUN OR RESUMED FROM TOMBSTONING 4HE GAME RESPONDS TO THE >]3TPRcXePcTS EVENT WHEN THE APPLICATION IS EITHER TOMBSTONED OR CLOSED
■ .OTE 4HE 6P\T CLASS PROVIDES THE >]4gXcX]V EVENT HANDLER WHICH IS USED TO KNOW WHEN THE APPLICATION IS GOING TO BE CLOSED 4HE >]3TPRcXePcTS EVENT WILL BE CALLED AFTER >]4gXcX]V AS WELL 3O IN THE >]3TPRcXePcTS EVENT HANDLER THERE IS NO IMMEDIATE WAY TO KNOW WHETHER THE APPLICATION IS GOING TO BE CLOSED OR IT HAS BEEN TOMBSTONED
7HEN THE GAME IS TOMBSTONED THE APPLICATION STORES GAME SETTINGS IN THE BcPcT DICTIONARY 7HEN THE APPLICATION IS RESUMED FROM TOMBSTONING IT LOADS THE GAME SETTINGS AND SHOWS A BITMAP REPRESENTING THE GAME IN PAUSE MODE .OW IF THE USER TAPS THE SCREEN THE GAME RESTARTS
4HE #ODE 4O DEMONSTRATE TOMBSTONING MANAGEMENT IN AN 8.! APPLICATION WE HAVE CREATED A BOUNCING BALL GAME THAT IS PAUSED IF THE TOMBSTONE OCCURS 4HE GAME PROVIDES A PAUSE MODE SCREENSHOT THAT IS SHOWN AFTER THE GAME IS RESUMED FROM TOMBSTONING 4HE 6P\TBTccX]Vb CLASS CONTAINS THREE PROPERTIES TO STORE THE BALL LOCATION THE BALL VELOCITY AND A "OOLEAN INDICATING WHETHER THE GAME IS IN PAUSE MODE ITS VALUE IS cadT OR NOT ITS VALUE IS UP[bT _dQ[XR R[Pbb 6P\TBTccX]Vb j _dQ[XR Q^^[ ?PdbTS j VTc* bTc* l _dQ[XR ETRc^a! ;^RPcX^] j VTc* bTc* l _dQ[XR ETRc^a! ET[^RXch j VTc* bTc* l _dQ[XR 6P\TBTccX]Vb j ?PdbTS , UP[bT* ;^RPcX^] , ETRc^a!ITa^* ET[^RXch , ]Tf ETRc^a! U l
U*
l
4HE 6P\TBTccX]Vb]3TPRcXePcTS EVENT HANDLERS )N THE FORMER EVENT HANDLER THE ;^PS STATIC METHOD FROM THE 6P\TBTccX]Vb]0RcXePcTS^QYTRc bT]STa 4eT]c0aVb PaVb j bTccX]Vb , 6P\TBTccX]Vb]0RcXePcTSbT]STa PaVb* l
_a^cTRcTS ^eTaaXST e^XS >]3TPRcXePcTS^QYTRc bT]STa 4eT]c0aVb PaVb j bTccX]Vb?PdbTS , cadT* bTccX]Vb;^RPcX^] , b_aXcT;^RPcX^]* bTccX]VbET[^RXch , b_aXcTET[^RXch* 6P\TBTccX]Vb]3TPRcXePcTSbT]STa PaVb* l 4HE D_SPcT METHOD IS THE CORE OF THE GAME WHERE ALL THE LOGIC IS CALCULATED SPRITE POSITIONS ARE UPDATED AND IN THIS CASE THE PAUSE MODE IS CHECKED 7HEN THE GAME IS IN PAUSE MODE THE BALL POSITION IS NOT CHANGED AND THE BALL TEXTURE IS REPLACED WITH THE 'AME 0AUSED BITMAP 4HEN THE CODE WAITS FOR GESTURE EVENTSSPECIFICALLY FOR A TAP ON THE SCREENAND WHEN IT OCCURS THE ?PdbTS PROPERTY IS SET TO UP[bT AND THE GAME RESTARTS SEE MORE ON GESTURES IN #HAPTER _a^cTRcTS ^eTaaXST e^XS D_SPcT6P\TCX\T VP\TCX\T j 0[[^fb cWT VP\T c^ TgXc XU 6P\T?PS6TcBcPcT?[PhTa8]STg>]T1dcc^]b1PRZ ,, 1dcc^]BcPcT?aTbbTS cWXb4gXc* C>3>) 0SS h^da d_SPcT [^VXR WTaT XU bTccX]Vb?PdbTS ,, UP[bT j b_aXcT;^RPcX^] , b_aXcT;^RPcX^] b_aXcTET[^RXch* b_aXcTCTgcdaT , QP[[CTgcdaT* l T[bT j b_aXcT;^RPcX^] , ETRc^a!ITa^* b_aXcTCTgcdaT , _PdbTBRaTT]* fWX[T C^dRW?P]T[8b6TbcdaT0ePX[PQ[T j 6TbcdaTBP\_[T Vb , C^dRW?P]T[ATPS6TbcdaT* bfXcRW Vb6TbcdaTCh_T j RPbT 6TbcdaTCh_TCP_) bTccX]Vb?PdbTS , UP[bT* b_aXcT;^RPcX^] , bTccX]Vb;^RPcX^]* b_aXcTET[^RXch , bTccX]VbET[^RXch* b_aXcTCTgcdaT , QP[[CTgcdaT* QaTPZ* l l l
5SAGE &ROM 6ISUAL 3TUDIO SELECT 7INDOWS 0HONE %MULATOR AS THE OUTPUT TARGET AND RUN THE APPLICATION !FTER FEW SECONDS THE EMULATOR WILL SHOW A BOUNCING BALL MOVING ON THE SCREEN SEE &IGURE
&IGURE 4HE G=0C^\Qbc^]X]V APPLICATION RUNS SHOWING A BOUNCING BALL 0RESS THE HARDWARE 3TART BUTTON CAUSING TOMBSTONING .OW PRESS THE HARDWARE "ACK BUTTON SO THAT THE GAME IS RESUMED 4HE APPLICATION SHOWS THE 'AME 0AUSED BITMAP AND WAITS FOR A TAP ON THE SCREEN SEE &IGURE
&IGURE 4HE GAME IS IN PAUSE MODE
-ANAGING /BSCURED AND 5NOBSCURED %VENTS 0ROBLEM 9OU NEED TO CREATE AN APPLICATION THAT CONTINUES TO RUN EITHER WHEN THE 7INDOWS 0HONE OPERATING SYSTEM LOCKS THE PHONE SCREEN OR YOU RECEIVE A PHONE CALL $URING THOSE EVENTS YOU HAVE TO POWER OFF SOME BATTERY CONSUMING RESOURCES 4HEN WHEN THE SCREEN IS UNLOCKED OR THE PHONE CALL ENDS YOU HAVE TO TURN THOSE RESOURCES ON AGAIN
3OLUTION 9OU HAVE TO USE THE 0__[XRPcX^]8S[T3TcTRcX^]QbRdaTS AND D]^QbRdaTS EVENT HANDLERS DEFINED IN THE ?W^]T0__[XRPcX^]5aP\T CLASS
(OW )T 7ORKS 0__[XRPcX^]8S[T3TcTRcX^]a0SSaTbb
3PECIFIES E MAIL NAMES AND ADDRESSES BECAUSE SOME SHORTCUT KEYS SUCH AS THE AT CHARACTER AND THE COM KEY WILL BE ADDED TO THE MAIN KEYBOARD
2daaT]Rh0\^d]c
3PECIFIES CURRENCY AMOUNT VALUES
#ONTINUED
Value
Description
3PcT
)NSERTS A CALENDAR DATE
a?W^]T=d\QTa
3PECIFIES THE DESTINATION ADDRESS OF A 3HORT -ESSAGE 3ERVICE 3-3 TEXT MESSAGE
?Pbbf^aS
3PECIFIES PASSWORD TEXT
CTgc
4HE STANDARD 3)0 LAYOUT FOR INSERTING TEXT
Da[
3PECIFIES AN )NTERNET ADDRESS
9OU CAN USE A COMBINATION OF THE 8]_dcBR^_T ATTRIBUTE AND THE :Th3^f] EVENT HANDLER TO CUSTOMIZE THE 3)0 BEHAVIOR 4HIS RECIPE CREATES A 3)0 LAYOUT THAT ACCEPTS ONLY NUMERIC DIGITS 9OU WILL CUSTOMIZED THE TEXT BOX WITH THE CT[T_W^]T=d\QTa 3)0 LAYOUT AND DISABLE THE INPUT OF NON NUMERIC KEYS
4HE #ODE 4O DEMONSTRATE THIS RECIPE YOU HAVE TO OPEN THE &3ad\ PROJECT FROM THE COMPANION CODE BY USING 6ISUAL 3TUDIO AND THEN FOCUS ON THE %XERCISES PAGE )T CONTAINS SOME DATA DESCRIBING THE EXERCISE SUCH AS THE EXERCISES NAME AND DURATION )T IS THE $URATION TEXT BOX THAT HAS TO BE NUMERIC AND ACCEPT ONLY NUMERIC DIGITS )N THE 4gTaRXbTgP\[ FILE YOU DEFINE THE TEXT BOX FIELDS THAT COMPOSE THE INPUT FORM TO SPECIFY AN EXERCISE .OTE THAT THE $URATION TEXT BOX FIELD HAS THE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BY THE :Th3^f] EVENT HANDLER CONTAINS THE :Th PROPERTY THAT REPRESENTS THE PRESSED KEY 9OU CAN USE THIS PROPERTY TO CHECK THAT THE PRESSED KEY IS NOT THE SPACE KEY OR OTHER NON NUMERIC KEY SUCH AS OR )N THIS CASE YOU CAN SET THE 7P]S[TS PROPERTY TO cadT SO THAT THE KEY IS ACCEPTED BY THE $URATION TEXT BOX /THERWISE YOU HAVE TO SET THE 7P]S[TS PROPERTY VALUE TO UP[bT SO THAT THE KEY IS NOT ACCEPTED _aXePcT e^XS cgc3daPcX^]N:Th3^f]^QYTRc bT]STa :Th4eT]c0aVb T j XU T:Th , :ThB_PRT T:Th , :Th3' T:Th , :Th3" T:Th , :ThD]Z]^f] T7P]S[TS , UP[bT* T[bT T7P]S[TS , cadT* l
5SAGE 0RESS #TRL& FROM 6ISUAL 3TUDIO SO THAT THE APPLICATION IS DEPLOYED TO EITHER THE 7INDOWS 0HONE %MULATOR OR THE 7INDOWS 0HONE DEVICE 4HE APPLICATION STARTS 3ELECT THE 4RAINING MENU ITEM FROM THE MAIN PAGE AND THEN SELECT THE !DD APPLICATION BAR BUTTON TO ADD A NEW EXERCISE 4HE %XERCISE PAGE LOADS AND YOU WILL SEE THE TEXT BOXES SHOWN IN &IGURE
&IGURE 4HE %XERCISE PAGE WITH THE $URATION NUMERIC FIELD .OW TAP THE $URATION TEXT BOX AND THE CT[T_W^]T=d\QTa LAYOUT OF THE 3OFT )NPUT 0ANEL VIRTUAL KEYBOARD APPEARS SEE &IGURE
&IGURE 4HE CUSTOMIZED CT[T_W^]T=d\QTa VIRTUAL KEYBOARD 4RY TO PRESS NUMERIC AND NON NUMERIC KEYS AND YOU WILL SEE THAT ONLY THE FORMER ARE ALLOWED
5SING THE 7INDOWS 0HONE 0REDEFINED 3TYLES 0ROBLEM 9OU NEED TO DEVELOP A 7INDOWS 0HONE APPLICATION THAT PROVIDES A DYNAMIC USER INTERFACE THAT CHANGES BASED ON THE USERS CHOICES OF THEME AND FONT
3OLUTION 9OU CAN USE THE 7INDOWS 0HONE PREDEFINED STYLES SO THAT YOU ARE SURE YOUR USER INTERFACE WILL CHANGE FONTS AND COLORS ACCORDING TO YOUR USERS SETTING CHANGES
(OW )T 7ORKS 7HEN YOU DEFINE THE USER INTERFACE OF YOUR 3ILVERLIGHT FOR 7INDOWS 0HONE APPLICATION IT IS VERY COMMON TO ADD TEXT BLOCKS TEXT BOXES LINKS AND SO FORTH 9OU CAN SPECIFY THEIR DIMENSIONS COLORS AND POSITIONS BUT YOU NEED TO PAY ATTENTION TO THE CHANGES MADE BY THE USER IN THE 3ETTINGS SYSTEM PAGE SEE &IGURE
&IGURE 4HE EMULATORS 3ETTINGS PAGE &OR EXAMPLE BY SELECTING THE 4HEME MENU ITEM THE USER CAN CHANGE THE 0HONE !CCENT COLOR )F YOUR USER INTERFACE PROVIDES LINKS TO OTHER PAGES OR EXTERNAL WEB PAGES THIS COLOR SHOULD BE USED TO SPECIFY THIS INFORMATION "Y USING THOSE PREDEFINED STYLES YOU CAN BE SURE THAT YOUR LINKS COLOR WILL CHANGE TO THE NEW USER SELECTION AUTOMATICALLY
■ .OTE 4HE FULL LIST OF PREDEFINED STYLES IS AVAILABLE AT THE -3$. OFFICIAL PAGE Wcc_)\bS]\XRa^b^UcR^\ T]db[XQaPahUU&%($$!e,EB(!Pb_g
!S YOU SAW IN 2ECIPE THE 7INDOWS 0HONE THEME IS A SET OF RESOURCES SUCH AS BACKGROUND COLORS AND PHONE ACCENT COLOR USED TO CUSTOMIZE THE PHONES LOOK "Y USING THE PREDEFINED RESOURCE DICTIONARY PROVIDED BY THE PHONE YOU CAN BE SURE TO MAINTAIN THE CONSISTENCY AND COMPATIBILITY OF YOUR APPLICATION -OREOVER YOU CAN BE PRETTY SURE THAT YOUR APPLICATION WILL PASS -ARKETPLACE APPROVAL 7HEN YOU NEED TO USE YOUR OWN COLORS FONTS AND SO FORTH YOU CAN OVERRIDE THE STATIC RESOURCE IN YOUR APPLICATION /BVIOUSLY THIS CHANGE WILL BE APPLIED ONLY TO YOUR APPLICATION AND NOT TO THE ENTIRE PHONE SYSTEM 9OU CAN SPECIFY THE STATIC RESOURCE EITHER IN AN 8!-, FILE OR IN A CODE FILE )N THE FORMER YOU CAN USE THE jBcPcXRATb^daRTl MARKUP EXTENSION TOGETHER WITH THE STATIC RESOURCE NAME 4HIS STATIC RESOURCE WILL BE ADDED TO YOUR APPLICATION WHEN IT STARTS )N THE LATTER CASE YOU CAN USE THE ATb^daRTb PROPERTY FROM THE 0__[XRPcX^] CLASS SPECIFYING THE STATIC RESOURCE NAME AS SEEN IN 2ECIPE
4HE #ODE 4O DEMONSTRATE THIS RECIPE YOU WILL CREATE THE ?aT3TUX]TSBhbcT\Bch[Tb3T\^ 3ILVERLIGHT FOR 7INDOWS 0HONE APPLICATION )T USES THE ?Xe^c CONTROL WHICH YOU CAN LEARN MORE ABOUT IN 2ECIPE TO SEPARATE APPLICATION CONTENT IN DIFFERENT CATEGORIES SUCH AS "RUSHES 4EXT "OXES &ONTS AND 4EXT 3TYLES 4HE APPLICATION IS SIMPLY A VISUAL REFERENCE TO THE STATIC RESOURCE STYLES PROVIDED BY THE PHONE SO THE CODE IS PRETTY SIMPLE ALL DEFINED IN THE aXT]cPcX^],ETacXRP[ <PaVX], &+BcPRZ?P]T[ >aXT]cPcX^],7^aXi^]cP[ <PaVX],$$+ATRcP]V[T FXScW, 7TXVWc, 5X[[,jBcPcXRATb^daRT ?W^]T0RRT]c1adbWl +CTgc1[^RZ <PaVX],$ CTgc,?W^]T0RRT]c1adbW 5^]cBXiT,jBcPcXRATb^daRT ?W^]T5^]cBXiT=^a\P[l +BcPRZ?P]T[+BcPRZ?P]T[ >aXT]cPcX^],7^aXi^]cP[ <PaVX],$$+ATRcP]V[T FXScW, 7TXVWc, 5X[[,jBcPcXRATb^daRT ?W^]T5^aTVa^d]S1adbWl +CTgc1[^RZ <PaVX],$ CTgc,?W^]T5^aTVa^d]S1adbW 5^]cBXiT,jBcPcXR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