This content was uploaded by our users and we assume good faith they have the permission to share this book. If you own the copyright to this book and it is wrongfully on our website, we offer a simple DMCA procedure to remove your content from our site. Start by pressing the button below!
3>) 0SS h^da X]XcXP[XiPcX^] [^VXR WTaT QPbT8]XcXP[XiT* l 4HE NEXT METHOD THAT IS CALLED BY THE 8.! FRAMEWORK IS ;^PS2^]cT]c )N THIS METHOD YOU HAVE TO LOAD THE CONTENT PREVIOUSLY ADDED TO THE 2^]cT]c PROJECT IN THE SOLUTION 9OU CAN ADD IMAGES SOUNDS SPRITES $ MODELS AND ALL YOUR GAME RESOURCES _a^cTRcTS ^eTaaXST e^XS ;^PS2^]cT]c j 2aTPcT P ]Tf B_aXcT1PcRW fWXRW RP] QT dbTS c^ SaPf cTgcdaTb b_aXcT1PcRW , ]Tf B_aXcT1PcRW6aP_WXRb3TeXRT* C>3>) dbT cWXb2^]cT]c c^ [^PS h^da VP\T R^]cT]c WTaT l &INALLY THE 8.! GAME FRAMEWORK ENTERS INTO A LOOP IN WHICH TWO METHODS ARE AUTOMATICALLY CALLED ONE BY ONEFIRST THE D_SPcT METHOD AND THEN THE 3aPf METHOD )N THE D_SPcT METHOD YOU HAVE TO ADD THE CODE THAT MANAGES THE GAMES LOGIC THE SPRITES MOVEMENT A COLLISION ALGORITHM AND SO ON 4HE 3aPf METHOD IS WHERE YOU DRAW THE GAME OBJECTS AND YOU HAVE TO BE FASTER TO DO IT 9OUR GAME CODE SHOULDNT UPDATE AND CHECK OBJECTS IN THE 3aPf METHOD _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 QPbTD_SPcTVP\TCX\T* l _a^cTRcTS ^eTaaXST e^XS 3aPf6P\TCX\T VP\TCX\T j 6aP_WXRb3TeXRT2[TPa2^[^a2^a]U[^fTa1[dT* C>3>) 0SS h^da SaPfX]V R^ST WTaT QPbT3aPfVP\TCX\T* l 4HERE IS ANOTHER METHOD DEFINED IN THE CODE THAT IS USED TO UNLOAD THE CONTENT WHEN THE GAME IS CLOSED _a^cTRcTS ^eTaaXST e^XS D][^PS2^]cT]c j C>3>) D][^PS P]h ]^] 2^]cT]c
3>) dbT cWXb2^]cT]c c^ [^PS h^da VP\T R^]cT]c WTaT U^]c , cWXb2^]cT]c;^PS+B_aXcT5^]c-5^]c* l +bd\\Pah CWXb Xb RP[[TS fWT] cWT VP\T bW^d[S SaPf XcbT[U +bd\\Pah +_PaP\ ]P\T,VP\TCX\T-?a^eXSTb P b]P_bW^c ^U cX\X]V eP[dTb+_PaP\_a^cTRcTS ^eTaaXST e^XS 3aPf6P\TCX\T VP\TCX\T j 6aP_WXRb3TeXRT2[TPa2^[^a2^a]U[^fTa1[dT* ]0RcXePcTS AND >]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 ]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 eTaWP]V AND THE ?W^]T0RRT]c1adbW AS Bca^ZT COLOR TO FIT JUST THE SIZE OF THE BORDER 1dcc^]1PRZVa^d]S LIKE A UNIQUE ELEMENT +ATRcP]V[T <PaVX],jBcPcXRATb^daRT?W^]TC^dRWCPaVTc>eTaWP]Vl Bca^ZT,jBcPcXRATb^daRT?W^]T0RRT]c1adbWl +1^aSTa g)=P\T,1dcc^]1PRZVa^d]S .OW YOU HAVE THE CONTROLS THAT YOU NEED AND YOU CAN PROCEED WITH THE CREATION OF THE STORYBOARD
XU XbCaXP[ j b_aXcT1PcRW1TVX]* b_aXcT1PcRW3aPfBcaX]VU^]c CWT 0__[XRPcX^] Xb X] CaXP[ <^ST ]Tf ETRc^a! 2^[^a1[PRZ* b_aXcT1PcRW4]S* l QPbT3aPfVP\TCX\T* l _a^cTRcTS ^eTaaXST e^XS >]4gXcX]V^QYTRc bT]STa 4eT]c0aVb PaVb j 6dXSTBW^f<PaZTc_[PRT?[PhTa8]STg>]T* QPbT>]4gXcX]VbT]STa PaVb* l l l 7RITING TEXT IN THE BX[eTa[XVWcCaXP[0__[XRPcX^] APPLICATION IS EASIER THAN 8.! APPLICATION 4HE [Q
+CXc[T?P]T[ R^]cPX]b cWT ]P\T ^U cWT P__[XRPcX^] P]S _PVT cXc[T+BcPRZ?P]T[ g)=P\T,CXc[T?P]T[ 6aXSA^f, <PaVX], ! &!'+CTgc1[^RZ g)=P\T,0__[XRPcX^]CXc[T CTgc,
2^ST c^ TgTRdcT fWT] cWT P__[XRPcX^] Xb R[^bX]V TV dbTa WXc 1PRZ CWXb R^ST fX[[ ]^c TgTRdcT fWT] cWT P__[XRPcX^] Xb STPRcXePcTS _aXePcT e^XS 0__[XRPcX^]N2[^bX]V^QYTRc bT]STa 2[^bX]V4eT]c0aVb T j 6dXSTBW^f<PaZTc_[PRT?[PhTa8]STg>]T* l
5SAGE 7HEN BOTH APPLICATIONS RUN THEY CHECK FOR TRIAL MODE AND THEN PRINT THE APPROPRIATE MESSAGE ON THE SCREEN 7HEN BOTH APPLICATIONS CLOSE THEY SHOW A MESSAGE ASKING USERS TO BUY THE APPLICATION )N &IGURE YOU CAN SEE BOTH EXAMPLES OUTPUT /N THE LEFT IS THE 8.! APPLICATION IN THE MIDDLE IS THE COMMON SCREENSHOT ASKING TO BUY THE APPLICATION AND FINALLY ON THE RIGHT IS THE 3ILVERLIGHT APPLICATION
&IGURE G=0CaXP[0__[XRPcX^] AND BX[eTa[XVWcCaXP[0__[XRPcX^] OUTPUTS
CHAPTER 2 ■■■
Windows Phone 7 Execution Model )N THIS CHAPTER YOU ARE GOING TO EXAMINE THE 7INDOWS 0HONE EXECUTION MODEL &IRST YOU WILL EXAMINE THE NAVIGATION OF PAGES IN A 7INDOWS 0HONE APPLICATION 4HEN YOU WILL FOCUS YOUR ATTENTION ON HOW THE 7INDOWS 0HONE OPERATING SYSTEM MANAGES RUNNING APPLICATIONS 4HE RECIPES IN THIS CHAPTER DESCRIBE HOW TO DO THE FOLLOWING v
.AVIGATE THE 7INDOWS 0HONE APPLICATIONS PAGES
v
0ASS PARAMETERS THROUGH PAGES
v
5SE GLOBAL DEFINED VARIABLES
v
5SE THE 3TATE DICTIONARY TO STORE THE APPLICATIONS GLOBAL VARIABLES
v
-ANAGE TOMBSTONING
v
-ANAGE TOMBSTONING IN 8.!
v
-ANAGE >QbRdaTS AND D]^QbRdaTS EVENTS
.AVIGATING "ETWEEN 0AGES 0ROBLEM 9OU HAVE A 7INDOWS 0HONE 3ILVERLIGHT APPLICATION WITH MORE THAN ONE PAGE AND YOU NEED TO NAVIGATE THROUGH THE PAGES
3OLUTION 9OU HAVE TO USE THE =PeXVPcX^]BTaeXRT CLASS SEE &IGURE TO SEE ITS CLASS DIAGRAM AND OPTIONALLY THE >]=PeXVPcTSC^ AND >]=PeXVPcTS5a^\ EVENT HANDLERS SEE 2ECIPE FOR MORE ON THIS
(OW )T 7ORKS 4HE 7INDOWS 0HONE 3ILVERLIGHT APPLICATION IS BASED ON PAGES AND A FRAME 4HE LATTER IS THE TOP LEVEL CONTAINER THAT PROVIDES FEATURES SUCH AS PAGE ORIENTATION AND RESERVES SPACE FOR THE PAGES RENDERING AND STATUS BAR 4HE &RAME CONTAINS ONE OR MORE PAGES AND PROVIDES THE NAVIGATION SERVICE TO GO THROUGH THE PAGES ! PAGE IS A CONTAINER FOR 3ILVERLIGHT CONTROLS THAT IS RENDERED IN A SPACE RESERVED BY THE FRAME 4HE PAGE OPTIONALLY PROVIDES THE APPLICATION BAR SEE #HAPTER WHICH IS USED TO PROVIDE A PAGE MENU AND A TOOLBAR 4HE ?W^]T0__[XRPcX^]?PVT CLASS PROVIDES DEVELOPERS EVERYTHING NEEDED TO MANAGE A PAGE /N THE OTHER HAND THE ?W^]T0__[XRPcX^]5aP\T CLASS REPRESENTS THE FRAME
&IGURE 4HE .AVIGATION3ERVICE CLASS DIAGRAM
4HE =PeXVPcX^]BTaeXRTb PROPERTY OF THE ?W^]T0__[XRPcX^]2[Pbb CLASS ENABLES DEVELOPERS TO ACCESS THE FRAMES NAVIGATION SERVICE AND USE THE =PeXVPcT METHOD 4HIS METHOD HAS ONE PARAMETER WHICH IS THE DaX OBJECT CONTAINING THE 52, OF THE TARGET PAGE 4HIS DaX CONSTRUCTOR HAS TWO PARAMETERS THE FORMER IS THE STRING CONTAINING THE 52, OF THE PAGE AND THE LATTER IS THE DaX:X]S ENUMERATION WHERE YOU CAN SET WHETHER THE 52, IS RELATIVE OR ABSOLUTE _dQ[XR Q^^[ =PeXVPcT DaX b^daRT !NOTHER USEFUL METHOD PROVIDED BY THE =PeXVPcX^]BTaeXRTb CLASS IS 6^1PRZ 4HIS METHOD SIMULATES THE HARDWARE "ACK BUTTON PRESS IN GOING ONE PAGE BACK 9OU CAN USE THE 2P]6^1PRZ PROPERTY TO RETRIEVE A "OOLEAN VALUE INDICATING WHETHER YOU CAN GO BACK TO THE PREVIOUS PAGE cadT OR NOT UP[bT _dQ[XR e^XS 6^1PRZ _dQ[XR Q^^[ 2P]6^1PRZ j VTc* l
■ .OTE 4HE =PeXVPcX^]BTaeXRTb CLASS PROVIDES THE 6^5^afPaS METHOD TOO BUT BECAUSE THERE IS NO FORWARD NAVIGATION IN A 7INDOWS 0HONE APPLICATION THIS METHOD ALWAYS RETURNS AN EXCEPTION
4HE #ODE 4O DEMONSTRATE SIMPLE NAVIGATION BETWEEN TWO PAGES WE HAVE CREATED THE =PeXVPcX]V0__ 3ILVERLIGHT APPLICATION 3TART 6ISUAL 3TUDIO AND CHOOSE .EW 0ROJECT FROM THE 3TART PAGE AND THEN SELECT THE 7INDOWS 0HONE !PPLICATION TEMPLATE )N THE .AME TEXT BOX OF THE .EW 0ROJECT DIALOG BOX TYPE=PeXVPcX]V0__ SEE &IGURE
&IGURE #REATING THE =PeXVPcX]V0__ APPLICATION &ROM THE 3OLUTION %XPLORER WINDOW RIGHT CLICK THE =PeXVPcX]V0__ PROJECT NAME AND CHOOSE !DD .EW )TEM &ROM THE !DD .EW )TEM DIALOG BOX SELECT THE 3ILVERLIGHT FOR 7INDOWS 0HONE TEMPLATE FROM THE )NSTALLED 4EMPLATES LIST 4HEN SELECT 7INDOWS 0HONE 0ORTRAIT 0AGE .AME THE PAGE ?PVT!gP\[ AND THEN CLICK /+ SEE &IGURE
&IGURE !DDING A NEW PAGE TO THE PROJECT /N BOTH PAGES YOU HAVE TO ADD A HYPERLINK BUTTON )N THE
)N THE
■ .OTE 9OU COULD USE THE =PeXVPcT METHOD IN THE ?PVT! EVENT HANDLER TO POINTING TO
5SAGE )N 6ISUAL 3TUDIO MAKE SURE YOUR TARGET IS 7INDOWS 0HONE %MULATOR AND THEN PRESS #TRL& 4HE EMULATOR WILL START BRIEFLY SHOWING THE SPLASH SCREEN AND THEN THE MAIN PAGE #LICK THE HYPERLINK BUTTON TO ACCESS THE SECOND PAGE .OW CLICK EITHER THE HYPERLINK BUTTON OR THE HARDWARE "ACK BUTTON AND YOU WILL RETURN TO THE MAIN PAGE
■ .OTE )F YOU USE =PeXVPcT INSTEAD OF 6^1PRZ TO RETURN TO THE MAIN PAGE AND THEN PRESS THE HARDWARE "ACK BUTTON THE APPLICATION WILL NOT EXIT AS YOU MAY EXPECT BUT WILL SHOW?PVT! AGAIN 4HATS BECAUSE EACH TIME YOU CALL THE =PeXVPcT METHOD A BRAND NEW PAGE IS CREATED AND LOADED AND THE REPLACED PAGE IS PUT ON THE PAGE STACK 0RESSING THE HARDWARE "ACK BUTTON OF THE 7INDOWS 0HONE DEVICE GOES AWAY FROM THE CURRENT PAGE AND POPS THE OLD PAGE OFF THE STACK
0ASSING $ATA 4HROUGH 0AGES 0ROBLEM 9OU NEED TO PASS DATA FROM ONE PAGE TO ANOTHER
3OLUTION 9OU CAN USE THE @dTahBcaX]V COLLECTION PROVIDED BY THE =PeXVPcX^]2^]cTgc PROPERTY FROM THE ?W^]T0__[XRPcX^]?PVT CLASS
(OW )T 7ORKS 4HE SOURCE PAGE THAT HAS TO PASS PARAMETERS TO THE DESTINATION PAGE CAN USE THE 52, PARAMETERS SYNTAX ?PVTgP\[._PaP\ ,eP[dT_PaP\!,eP[dT
■ .OTE !CCORDING TO THE OFFICIAL DOCUMENTATION AT Wcc_)\bS]\XRa^b^UcR^\T]db[XQaPah i%R!i#(!e,EB($Pb_g YOU WILL RECEIVE AN EXCEPTION WHEN THE LENGTH OF THE @dTahBcaX]V PARAMETER EXCEEDS CHARACTERS
!FTER THE PAGE NAME THE PARAMETERS DEFINITION STARTS WITH A QUESTION MARK AND INCLUDES A SERIES OF KEYVALUE PAIRS SEPARATED BY THE AMPERSAND CHARACTER 4O RETRIEVE THE PARAMETERS VALUES IN THE DESTINATION PAGE YOU HAVE TO USE THE @dTahBcaX]V COLLECTION PROVIDED BY THE =PeXVPcX^]2^]cTgc PROPERTY OF THE ?W^]T0__[XRPcX^]?PVT CLASS
4HE #ODE 4O DEMONSTRATE NAVIGATION BETWEEN PAGES WITH THE EXCHANGE OF PARAMETERS YOU HAVE TO CREATE A NEW 7INDOWS 0HONE 3ILVERLIGHT APPLICATION AND CALL IT =PeXVPcX]VFXc?PaP\b0__ !S YOU DID IN 2ECIPE ADD A NEW PAGE AND CALL IT ?PVT!gP\[ )N
+7h_Ta[X]Z1dcc^] 2^]cT]c,>_cX^] ! 2[XRZ,7h_Ta[X]Z1dcc^]N2[XRZ CPQ8]STg,! +7h_Ta[X]Z1dcc^] 2^]cT]c,>_cX^] " 2[XRZ,7h_Ta[X]Z1dcc^]N2[XRZ CPQ8]STg," +BcPRZ?P]T[+6aXS)N THE CODE OF THE 2[XRZ EVENT HANDLER YOU CAN CALL THE =PeXVPcT METHOD PASSING THE PARAMETER THAT REPRESENTS THE INDEX OF THE PRESSED Wh_Ta[X]Z BUTTON _aXePcT e^XS 7h_Ta[X]Z1dcc^]N2[XRZ^QYTRc bT]STa A^dcTS4eT]c0aVb T j 7h_Ta[X]Z1dcc^] WQ , bT]STa Pb 7h_Ta[X]Z1dcc^]* bcaX]V da[ , bcaX]V5^a\Pc?PVT!gP\[.83,jl WQCPQ8]STg* cWXb=PeXVPcX^]BTaeXRT=PeXVPcT]Tf DaXda[ DaX:X]SAT[PcXeT* l 4HE SENDER OBJECT PASSED TO THE 2[XRZ EVENT HANDLER REPRESENTS THE HYPERLINK BUTTON THAT RAISED THE EVENT 9OU CAN CAST IT TO A 7h_Ta[X]Z1dcc^] OBJECT SO YOU CAN USE ITS CPQ8]STg PROPERTY AND PASS IT TO THE ?PVT! PAGE )N THE ?PVT!gP\[ FILE YOU ADD A CTgc1[^RZ CONTROL THAT WILL SHOW A MESSAGE INDICATING WHICH BUTTON HAS BEEN PRESSED IN THE
5^]c5P\X[h,jBcPcXRATb^daRT ?W^]T5^]c5P\X[h=^a\P[l 5^]cBXiT,jBcPcXRATb^daRT ?W^]T5^]cBXiT=^a\P[l 5^aTVa^d]S,jBcPcXRATb^daRT ?W^]T5^aTVa^d]S1adbWl Bd__^acTS>aXT]cPcX^]b,?^acaPXc >aXT]cPcX^],?^acaPXc \R)8V]^aPQ[T,S S)3TbXV]7TXVWc,&%' S)3TbXV]FXScW,#' bWT[[)BhbcT\CaPh8bEXbXQ[T,CadT ;^PSTS,?W^]T0__[XRPcX^]?PVTN;^PSTS
5SAGE &ROM 6ISUAL 3TUDIO MAKE SURE YOUR TARGET IS 7INDOWS 0HONE %MULATOR AND PRESS #TRL& 4HE EMULATOR WILL START BRIEFLY SHOWING THE SPLASH SCREEN AND THEN THE MAIN PAGE SEE &IGURE
&IGURE 4HE SOURCE PAGE OF THE =PeXVPcX]VFXcW?PaP\b0__ APPLICATION
3ELECT ONE OPTION OF YOUR CHOICE AND THE APPLICATION WILL SHOW THE ?PVT! PAGE WITH A MESSAGE TELLING WHICH OPTION YOU SELECTED &OR EXAMPLE IN OUR CASE WE CLICKED /PTION &IGURE SHOWS THE RELATED MESSAGE
&IGURE 4HE SECOND PAGE SHOWS THE INDEX OF THE CLICKED HYPERLINK BUTTON
.AVIGATING "ETWEEN 0AGES BY 5SING 'LOBAL !PPLICATION 6ARIABLES 0ROBLEM 9OU HAVE TO NAVIGATE BETWEEN PAGES SHARING DATA ACROSS THEM 9OU WANT TO AVOID USING A QUERY STRING BECAUSE YOUR APPLICATION HAS A LOT OF PAGES AND YOU NEED A SMART WAY TO SHARE DATA BETWEEN PAGES
3OLUTION 9OU CAN ADD A PUBLIC PROPERTY TO THE 0__ CLASS AND RETRIEVE ITS VALUE BY USING THE 2daaT]c STATIC PROPERTY PROVIDED BY THE 0__[XRPcX^] CLASS
(OW )T 7ORKS 4HE 7INDOWS 0HONE 3ILVERLIGHT APPLICATION ALWAYS PROVIDES A CLASS DERIVING FROM THE 0__[XRPcX^] CLASS THE 0__ CLASS 4HIS CLASS REPRESENTS THE RUNNING APPLICATION ITSELF WITH A REFERENCE TO THE ROOT FRAME AND PAGES 3EE 2ECIPE FOR MORE DETAILS $EFINING A PROPERTY IN THE 0__ CLASS ENSURES THAT THE PROPERTY IS VISIBLE TO ALL PAGES !T ANY TIME AND FROM ANY PAGE YOU CAN USE THE 2daaT]c STATIC PROPERTY FROM THE 0__[XRPcX^] CLASS TO RETRIEVE A REFERENCE TO THE CURRENT 0__ OBJECT "Y USING THE INSTANCE OF THIS OBJECT YOU CAN EASILY EITHER RETRIEVE THE PROPERTY VALUE OR SET IT
4HE #ODE #REATE A NEW 7INDOWS 0HONE 3ILVERLIGHT APPLICATION CALLED =PeXVPcX]VFXcW6[^QP[EPaXPQ[T0__ FROM 6ISUAL 3TUDIO !DD TWO NEW PAGES CALLED ?PVT!gP\[ AND ?PVT"gP\[BY CHOOSING 0ROJECT !DD .EW )TEM )N THE 0__gP\[Rb FILE WE ADDED A "OOLEAN PROPERTY THAT REPRESENTS THE USERS CHOICE TO HAVE ALL RED PAGES IN THE APPLICATION _dQ[XR _PacXP[ R[Pbb 0__ ) 0__[XRPcX^] j +bd\\Pah ?a^eXSTb TPbh PRRTbb c^ cWT a^^c UaP\T ^U cWT ?W^]T 0__[XRPcX^] +bd\\Pah +aTcda]b-CWT a^^c UaP\T ^U cWT ?W^]T 0__[XRPcX^]+aTcda]b_dQ[XR ?W^]T0__[XRPcX^]5aP\T A^^c5aP\T j VTc* _aXePcT bTc* l _dQ[XR Q^^[ ATS?PVTb j VTc* bTc* l
+bd\\Pah 2^]bcadRc^a U^a cWT 0__[XRPcX^] ^QYTRc +bd\\Pah_dQ[XR 0__ j )N THE
_aXePcT e^XS WQC^?PVT"N2[XRZ^QYTRc bT]STa A^dcTS4eT]c0aVb T j cWXb=PeXVPcX^]BTaeXRT=PeXVPcT]Tf DaX?PVT"gP\[ DaX:X]SAT[PcXeT* l )N ?PVT!gP\[ AND ?PVT"gP\[ WE ADDED THE ;^PSTS EVENT HANDLER )N THE RELATED CODE WE RETRIEVED THE ATS?PVTb "OOLEAN PROPERTY SETTING THE PAGES BACKGROUND COLOR ACCORDINGLY _aXePcT e^XS ?W^]T0__[XRPcX^]?PVTN;^PSTS^QYTRc bT]STa A^dcTS4eT]c0aVb T j 0__ P , 0__[XRPcX^]2daaT]c Pb 0__* XU PATS?PVTb ,, cadT 2^]cT]c?P]T[1PRZVa^d]S , ]Tf B^[XS2^[^a1adbW2^[^abATS* l
5SAGE 2UN THE APPLICATION FROM 6ISUAL 3TUDIO SELECTING 7INDOWS 0HONE %MULATOR AS THE OUTPUT TARGET &ROM THE MAIN PAGE SELECT THE ) 7ANT !LL 0AGES 2ED CHECK BOX 4HE BACKGROUND COLOR TURNS RED SEE &IGURE
&IGURE =PeXVPcX]VFXcW6[^QP[EPaXPQ[T0__ IN ACTION
#LICK THE CHECK BOX AGAIN TO DESELECT IT AND THE MAIN PAGES BACKGROUND COLOR TURNS BLACK 3ELECT THE CHECK BOX ONCE MORE AND THEN PRESS THE .AVIGATE TO PAGE HYPERLINK BUTTON 4HE ?PVT! BACKGROUND COLOR IS RED SEE &IGURE
&IGURE %VENPAGE HAS THE BACKGROUND COLOR SET TO RED
.AVIGATING "ETWEEN 0AGES WITH 3TATE 0ROBLEM 9OU HAVE TO NAVIGATE BETWEEN PAGES AND YOU WANT TO STORE A COMPLEX OBJECT THAT IS NOT SUITABLY STORED VIA THE QUERY STRING METHOD 9OU NEED TO STORE THE OBJECT TO PREVENT TOMBSTONING
3OLUTION 9OU SHOULD USE THE BcPcT DICTIONARY PROVIDED BY THE ?W^]T0__[XRPcX^]BTaeXRT CLASS
(OW )T 7ORKS 3OMETIMES YOU HAVE TO SHARE DATA BETWEEN PAGES THAT IS NOT SUITABLE FOR THE @dTahBcaX]V PROPERTYFOR INSTANCE WHEN YOU HAVE TO PROVIDE A COMPLEX OBJECT SUCH AS AN ARRAY OR LIST TO ANOTHER PAGE -OREOVER THE @dTahBcaX]V PROPERTY CAN ACCEPT UP TO CHARACTERS FROM THE DaX OBJECT 7INDOWS 0HONE HELPS DEVELOPERS VIA THE BcPcT DICTIONARY WHICH IS PROVIDED BY THE ?W^]T0__[XRPcX^]BTaeXRT CLASS INCLUDED IN THE <XRa^b^Uc<^QX[TBWT[[ NAMESPACE 4HE ?W^]T0__[XRPcX^]BTaeXRT CLASS INCLUDES THE 2daaT]c STATIC PROPERTY THAT RETRIEVES THE ?W^]T0__[XRPcX^]BTaeXRT OBJECT RELATED TO THE CURRENT APPLICATION "Y USING THIS OBJECT YOU CAN USE THE BcPcT PROPERTY TO STORE DATA ACROSS PAGES -OREOVER THE ?W^]T0__[XRPcX^]BTaeXRT AUTOMATICALLY MANAGES THE APPLICATIONS IDLE BEHAVIOR AND THE APPLICATIONS STATE WHEN IT BECOMES EITHER ACTIVE OR INACTIVE )NDEED MANAGING ACTIVE AND INACTIVE STATES IS AN IMPORTANT ASPECT OF 7INDOWS 0HONE LIFE CYCLE APPLICATION MANAGEMENT THAT A DEVELOPER HAS TO CONSIDER $URING THE APPLICATION USAGE A LOT OF EXTERNAL EVENTS MAY OCCUR AND THE DEVELOPER HAS TO PROVIDE THE RIGHT SOLUTIONS TO AVOID A BAD USER EXPERIENCE &OR EXAMPLE IMAGINE THAT A USER IS FILLING IN A FORM ON THE PAGE YOU PROVIDED WHEN THAT USER REMEMBERS AN IMPORTANT E MAIL THAT NEEDS TO BE SENT IMMEDIATELY 4HE USER PRESSES THE HARDWARE 3TART BUTTON AND YOUR APPLICATION BECOMES INACTIVE !FTER THE E MAIL IS SENT THE USER PRESSES THE HARDWARE "ACK BUTTON UNTIL THE APPLICATION BECOMES ACTIVE AGAIN (OW WOULD THE USER REACT IF ALL DATA IN THE FORM WAS LOST 4O PROVIDE A COMPLEX OBJECT TO ANOTHER PAGE YOU COULD USE THE GLOBAL APPLICATION VARIABLE TECHNIQUE TOO SEE 2ECIPE "UT WHAT IS PROVIDED HERE FOR FREE IS TOMBSTONING MANAGEMENT 7HEN THE APPLICATION IS DEACTIVATED BECAUSE OF AN EXTERNAL EVENT SUCH AS THE HARDWARE 3TART BUTTON BEING PRESSED THE BcPcT DICTIONARY IS SERIALIZED AND STORED AUTOMATICALLY BY THE 7INDOWS 0HONE OPERATING SYSTEM )F THE APPLICATION IS ACTIVATED AGAINNOT BY LAUNCHING THE APPLICATION FROM THE 3TART MENU BUT BY GOING BACK VIA THE HARDWARE "ACK BUTTONTHE BcPcT DICTIONARY IS DESERIALIZED AND PROVIDED TO THE APPLICATION 4HATS WHY THE BcPcT DICTIONARY HAS TO CONTAIN ONLY SERIALIZABLE OBJECTS !S ALREADY STATED IN 2ECIPE WHEN THE =PeXVPcT METHOD IS CALLED A BRAND NEW PAGE IS CREATED AND SHOWN 3O IF YOUR TEXT BOXES ARE BLANK BY DEFAULT WHEN THE APPLICATION IS ACTIVATED FROM THE 7INDOWS 0HONE OPERATING SYSTEM THE PAGE WILL SHOW EMPTY TEXT BOXES 4O MANAGE THIS ASPECT AND AVOID THIS APPLICATION BEHAVIOR YOU CAN IMPLEMENT THE CODE IN THE >]=PeXVPcTS5a^\ AND THE >]=PeXVPcTSC^ EVENT HANDLERS PROVIDED BY THE ?W^]T0__[XRPcX^]?PVT CLASS 4HE >]=PeXVPcTS5a^\ EVENT IS RAISED JUST BEFORE THE USER IS GOING TO NAVIGATE OFF THE PAGE 4HIS EVENT HANDLER IS THE RIGHT PLACE TO INSERT THE CODE THAT SAVES YOUR DATA 4HE >]=PeXVPcTSC^ EVENT IS RAISED JUST AFTER THE PAGE IS SHOWN BECAUSE OF NAVIGATION EITHER FROM ANOTHER PAGE OR FROM THE 7INDOWS 0HONE OPERATING SYSTEM "OTH EVENT HANDLERS PROVIDE A =PeXVPcX^]4eT]c0aVb OBJECT THAT PROVIDES SOME INTERESTING PROPERTIES SUCH AS THE DaX OF THE TARGET PAGE OR THE TARGET APPLICATION AND THE TARGET 2^]cT]c OBJECT &OR EXAMPLE IN THE >]=PeXVPcTS5a^\ EVENT HANDLER THE 2^]cT]c PROPERTY CONTAINS THE
4HE #ODE 4O DEMONSTRATE NAVIGATION BETWEEN PAGES WITH A COMPLEX DATA OBJECT EXCHANGED WE WILL CREATE A NEW 7INDOWS 0HONE 3ILVERLIGHT APPLICATION CALLED =PeXVPcX]VFXcWBcPcT0__ )N THIS APPLICATION
!S ALREADY DONE IN PREVIOUS RECIPES WE ADD ANOTHER PAGE CALLED ?PVT!gP\[ )N THE ?PVT!gP\[ PAGE WE ADD THREE CTgc1^g CONTROLS AND ONE 1dcc^] CONTROL +2^]cT]c?P]T[ _[PRT PSSXcX^]P[ R^]cT]c WTaT+6aXS g)=P\T,2^]cT]c?P]T[ 6aXSA^f, <PaVX], ! !+BcPRZ?P]T[+CTgc1^g g)=P\T,cgc=P\T CTgc,5Xabc=P\T 6^c5^Rdb,cgcN6^c5^Rdb +CTgc1^g g)=P\T,cgc;Pbc CTgc,;Pbc=P\T 6^c5^Rdb,cgcN6^c5^Rdb +CTgc1^g g)=P\T,cgc2Xch CTgc,2Xch 6^c5^Rdb,cgcN6^c5^Rdb +1dcc^] g)=P\T,Qc]BPeT 2^]cT]c,BPeT 2[XRZ,Qc]BPeTN2[XRZ +BcPRZ?P]T[+6aXS %VERY CTgc1^g CONTROL IMPLEMENTS 6^c5^Rdb SO WHEN THE 4EXT"OX RECEIVES THE FOCUS IT WILL SELECT ITS OWN TEXT _aXePcT e^XS cgcN6^c5^Rdb^QYTRc bT]STa A^dcTS4eT]c0aVb T j CTgc1^g cgc , bT]STa Pb CTgc1^g* cgcBT[TRc0[[* l
■ 4IP 4HIS TECHNIQUE IS DONE TO AVOID USING LABELS BY SHOWING THE STRING THE TEXT BOX INDICATES WHAT ITS CONTENT SHOULD BE
4HE 3AVE BUTTON CALLS THE BPeT>aD_SPcT METHOD WHICH STORES THE TEXT BOXES TEXT INTO A ?Tab^] OBJECT &IRST THE METHOD CHECKS WHETHER THE BcPcT DICTIONARY OF ?PVT! ALREADY CONTAINS A ?Tab^] OBJECT )F IT DOES THE METHOD RETRIEVES THE OBJECT AND CHANGES ITS VALUE /THERWISE THE METHOD CREATES A BRAND NEW OBJECT FILLING IT WITH THE TEXT BOXES VALUES )N BOTH CASES THE LAST INSTRUCTION IS USED TO STORE THE 0ERSON OBJECT IN THE BcPcT DICTIONARY OF ?PVT! /NLY WHEN THE BPeT>aD_SPcT METHOD IS CALLED VIA THE 3AVE BUTTON IS THE BcPcT DICTIONARY PROVIDED BY THE 2^]cTgc PROPERTY OF THE ?W^]T0__[XRPcX^]BTaeXRT POPULATED WITH THE ?Tab^] OBJECT )N THIS WAY THE MAIN PAGE WILL SHOW THE MESSAGE ONLY WHEN THE USER SAVES DATA )F YOU DONT SEPARATE THE TWO BcPcT DICTIONARIES AND USE THE ?W^]T0__[XRPcX^]BTaeXRTS ONE TO STORE TEXT BOX VALUES BOTH ON A SAVE OPERATION AND ON TOMBSTONING YOU WILL HAVE TO IMPLEMENT A TECHNIQUE TO KNOW WHEN
XU cWXbBcPcT2^]cPX]b:Th?Tab^] j _ , ?Tab^] cWXbBcPcTJ?Tab^]L* _5Xabc=P\T , cgc=P\TCTgc* _;Pbc=P\T , cgc;PbcCTgc* _2Xch , cgc2XchCTgc* l T[bT j _ , ]Tf ?Tab^]* _5Xabc=P\T , cgc=P\TCTgc* _;Pbc=P\T , cgc;PbcCTgc* _2Xch , cgc2XchCTgc* l XU XbBPeTS j ?W^]T0__[XRPcX^]BTaeXRT2daaT]cBcPcTJ?Tab^]L , _* l cWXbBcPcTJ?Tab^]L , _* l 4HE CORE OF THIS EXAMPLE IS THE CODE IN THE >]=PeXVPcTS5a^\ AND >]=PeXVPcTSC^ EVENT HANDLERS )N THE FORMER THE BPeT>aD_SPcT METHOD IS CALLED AGAIN SO THAT WHEN THE APPLICATION IS DEACTIVATED THE USER DOESNT LOSE DATA 4HE METHOD WILL NOT BE CALLED WHEN THE USER PRESSES THE HARDWARE "ACK BUTTON BECAUSE IN THIS CASE ITS BEHAVIOR IS SIMILAR TO THE #ANCEL BUTTON IN A DIALOG BOX 2ETRIEVING WHEN THE HARDWARE "ACK BUTTON IS PRESSED IS ACCOMPLISHED BY CHECKING THE 2^]cT]c PROPERTY OF THE =PeXVPcX^]4eT]c0aVb OBJECT PASSED TO THE EVENT HANDLER _a^cTRcTS ^eTaaXST e^XS >]=PeXVPcTS5a^\BhbcT\FX]S^fb=PeXVPcX^]=PeXVPcX^]4eT]c0aVb T j XU T2^]cT]c ,, ]d[[ j BPeT>aD_SPcTUP[bT* l QPbT>]=PeXVPcTS5a^\T* l
)N THE >]=PeXVPcTSC^ EVENT HANDLER WE SIMPLY CHECK WHETHER THE BcPcT DICTIONARY FROM THE ?PVT! CLASS CONTAINS THE ?Tab^] OBJECT AND THEN WE EVENTUALLY FILL THE TEXT BOXES TEXT WITH ITS VALUES _a^cTRcTS ^eTaaXST e^XS >]=PeXVPcTSC^BhbcT\FX]S^fb=PeXVPcX^]=PeXVPcX^]4eT]c0aVb T j XU cWXbBcPcT2^]cPX]b:Th?Tab^] j ?Tab^] _ , ?Tab^]cWXbBcPcTJ?Tab^]L* cgc=P\TCTgc , _5Xabc=P\T* cgc;PbcCTgc , _;Pbc=P\T* cgc2XchCTgc , _2Xch* l QPbT>]=PeXVPcTSC^T* l &INALLY THE 3AVE BUTTON CODE CALLS THE BPeT>aD_SPcT METHOD PASSING A cadT VALUE TO INDICATE THAT IT WILL HAVE TO SAVE THE ?Tab^] OBJECT INTO THE ?W^]T0__[XRPcX^]BTaeXRTS BcPcT DICTIONARY _aXePcT e^XS Qc]BPeTN2[XRZ^QYTRc bT]STa A^dcTS4eT]c0aVb T j BPeT>aD_SPcTcadT* cWXb=PeXVPcX^]BTaeXRT6^1PRZ* l
5SAGE &ROM 6ISUAL 3TUDIO RUN THE APPLICATION AFTER CHECKING THAT THE TARGET IS SET TO 7INDOWS 0HONE %MULATOR 4HE MAIN PAGE WILL BE SHOWN BRIEFLY WITH JUST THE LINK TO NAVIGATE TO THE SECOND PAGE SEE &IGURE
&IGURE 4HE =PeXVPcX]VFXcWBcPcT0__ APPLICATIONS FIRST PAGE "Y PRESSING THE HYPERLINK BUTTON YOU GO TO THE SECOND PAGE SHOWN IN &IGURE
&IGURE 4HE SECOND PAGE CONTAINS THREE TEXT BOXES AND A BUTTON .OW YOU CAN INSERT YOUR CREDENTIALS AND PRESS THE 3AVE BUTTON SO THE APPLICATION RETURNS TO THE START PAGE AND SHOWS THE MESSAGE SEE &IGURE
&IGURE 4HE MAIN PAGE GREETS THE PERSON YOU ADDED FROM THE PAGE FORM .OW LETS PLAY A BIT WITH THE APPLICATION AND EXPLORE UNEXPECTED SITUATIONS #OMMENT THE CODE OF THE >]=PeXVPcTS5a^\ EVENT HANDLER FROM ?PVT!gP\[Rb AND RESTART THE APPLICATION 'O TO PAGE AND ADD SOME TEXT TO THE TEXT BOXES 0RESS THE HARDWARE 3TART BUTTON LEAVING THE APPLICATION AND THEN THE HARDWARE "ACK BUTTON 4HE APPLICATION IS RESUMED BUT EVERYTHING YOU INSERTED IN TEXT BOXES IS GONE .OW REDO THE SAME STEPS THIS TIME UNCOMMENTING THE >]=PeXVPcT5a^\ CODE 4HE INITIAL SITUATION WILL BE RESUMED AS YOU LEFT IT
-ANAGING 4OMBSTONING IN 7INDOWS 0HONE 3ILVERLIGHT !PPLICATIONS 0ROBLEM 9OU HAVE TO MANAGE TOMBSTONING AND STORE APPLICATION DATA PERMANENTLY SO THAT WHEN THE APPLICATION IS EITHER ACTIVATED OR EXECUTED THE APPLICATION CAN RELOAD DATA
3OLUTION 9OU HAVE TO USE 8b^[PcTSBc^aPVT CLASSES SEE #HAPTER FOR A FULL COVERAGE ON THEM TOGETHER WITH 0__[XRPcX^] CLASS EVENT HANDLERS 0__[XRPcX^]N;Pd]RWX]V 0__[XRPcX^]N0RcXePcTS 0__[XRPcX^]N3TPRcXePcTS AND 0__[XRPcX^]N2[^bX]V
(OW )T 7ORKS 4HE 7INDOWS 0HONE OPERATING SYSTEM DOESNT PROVIDE SUPPORT FOR EXECUTING CONCURRENT APPLICATIONS CONCURRENTLY IN THE FOREGROUND 4HE APPLICATION THAT YOU RUN ON YOUR PHONE IS THE ONLY ONE EXECUTED IN FOREGROUND AND NO THIRD PARTY APPLICATION CAN RUN IN THE BACKGROUND 7HEN YOU PRESS THE HARDWARE 3TART BUTTON AND RUN ANOTHER APPLICATION THE PREVIOUS APPLICATION IS ACTUALLY KILLED 4HIS BEHAVIOR IS CALLED TOMBSTONING ,ETS TAKE A LOOK AT AN EXAMPLE 3AY YOU PRESS THE HARDWARE 3TART BUTTON AND LAUNCH THE #ALENDAR APPLICATION 9OU START TO NOTE AN APPOINTMENT WITH #OMPANY 8 BUT YOU DONT REMEMBER THE NAME OF THE STREET WHERE #OMPANY 8 IS LOCATED 3O YOU PRESS THE HARDWARE 3EARCH BUTTON IN YOUR APPLICATION THE 3TPRcXePcTS EVENT IS RAISED TYPE THE NAME OF THE COMPANY AND PRESS THE %NTER KEY 4HE COMPANY SITE APPEARS AND YOU CLICK ON IT SO )NTERNET %XPLORER RUNS AND THE SITE IS SHOWN 9OU CLICK THE #ONTACT 5S LINK AND READ THE COMPANYS ADDRESS .OW YOU HAVE TWO OPTIONS v
0RESS THE HARDWARE 3TART BUTTON AND SELECT THE #ALENDAR APPLICATION AGAIN
v
0RESS THE HARDWARE "ACK BUTTON UNTIL YOU REACH THE #ALENDAR APPLICATION
)N THE FORMER CASE YOU RUN A FRESH NEW COPY OF THE #ALENDAR APPLICATION AND EVERYTHING YOU WROTE BEFORE SEARCHING FOR THE COMPANYS ADDRESS IS GONE )N THIS CASE THE ;Pd]RWX]V EVENT IS RAISED )N THE LATTER CASE YOU RUN A FRESH NEW COPY OF THE #ALENDAR APPLICATION BUT THE 7INDOWS 0HONE OPERATING SYSTEM PROVIDES A COLLECTION OF SERIALIZABLE OBJECTS IN THE BcPcT DICTIONARY AS YOU SAW IN 2ECIPE 3O YOU WILL SEE YOUR DATA AGAIN IN THE TEXT BOXES BECAUSE #ALENDAR DEVELOPERS HAVE MANAGED THE TOMBSTONING )N THIS CASE THE 0RcXePcTS EVENT IS RAISED 4HERE IS ANOTHER WAY TO MANAGE YOUR APPLICATION 9OU COULD STORE YOUR DATA PERMANENTLY )NDEED THE BcPcT DICTIONARY IS PROVIDED ONLY WHEN YOU ACTIVATE THE APPLICATION WITH THE HARDWARE "ACK BUTTON AND NOT WHEN YOU LAUNCH IT FROM THE 3TART MENU 9OU CAN USE THE FOUR 0__[XRPcX^] EVENT HANDLERS TOGETHER WITH ISOLATED STORAGE IN ORDER TO SAVE DATA IN THE MEMORY SPACE RESERVED FOR THE APPLICATION
■ .OTE 4HERE IS NO LIMITED QUOTA SIZE FOR THE STORAGE OF A 7INDOWS 0HONE APPLICATION 4HE APPLICATION ITSELF HAS TO TAKE CARE OF THE DISK SPACE AVOIDING USELESS INFORMATION 7HEN THE APPLICATION IS REMOVED FROM THE PHONE THE ISOLATED STORAGE IS REMOVED AS WELL
4HE #ODE 4O DEMONSTRATE HOW TO MANAGE THE FOUR 0__[XRPcX^] EVENT HANDLERS IN CONJUNCTION WITH THE ISOLATED STORAGE WE WILL START TO CREATE AN APPLICATION THAT WE WILL USE THROUGHOUT THE BOOK 4HE &3ad\ APPLICATION PROVIDES USEFUL TOOLS TO DRUMMERS WHO FOR INSTANCE WANT TO PLAN THEIR PRACTICES RECORD A GROOVE THEY HAVE IN MIND OR USE A METRONOME DURING THEIR DRUMMING
■ .OTE 9OU CAN DOWNLOAD THIS APPLICATION CODE AND ALL THE SOURCE CODE SHOWN IN THIS BOOK FROM THE 3OURCE #ODE$OWNLOAD AREA OF THE !PRESS WEBSITE fffP_aTbbR^\
)N THIS PARTICULAR CASE WE WILL FOCUS OUR ATTENTION ON THE 4RAINING MENU OF THE &3ad\ APPLICATION WHERE THE USER CAN CREATE A TRAINING PLAN SPECIFYING AN EXERCISE NAME A DESCRIPTION AND A DURATION 4HE APPLICATION WILL PROVIDE THREE CTgc1^g CONTROLS TO CONTAIN THAT INFORMATION 4HE CODE IS CONTAINED IN THE 4gTaRXbTgP\[ PAGE )T DEFINES A NEW 6aXS WITH TWO COLUMNS AND THREE ROWS WITHIN THE 2^]cT]c?P]T[ GRID &INALLY IT ADDS THREE CTgc1^g CONTROLS AND THREE CTgc1[^RZ CONTROLS AS LABELS )T IS WORTH NOTING THE $ESCRIPTION TEXT BOX WHICH ACCEPTS MORE THAN ONE LINE OF TEXT THANKS TO THE 0RRT_cATcda]b PROPERTY BEING SET TO cadT +2^]cT]c?P]T[ _[PRT PSSXcX^]P[ R^]cT]c WTaT+6aXS g)=P\T,2^]cT]c?P]T[ 6aXSA^f, <PaVX], ! !+BcPRZ?P]T[+6aXS+6aXSA^f3TUX]XcX^]b+A^f3TUX]XcX^] 7TXVWc,0dc^+A^f3TUX]XcX^] 7TXVWc,0dc^+A^f3TUX]XcX^] 7TXVWc,+6aXSA^f3TUX]XcX^]b+6aXS2^[d\]3TUX]XcX^]b+2^[d\]3TUX]XcX^] FXScW,0dc^ +2^[d\]3TUX]XcX^] FXScW, +6aXS2^[d\]3TUX]XcX^]b+CTgc1[^RZ 6aXSA^f, 6aXS2^[d\], CTgc,=P\T) Bch[T,jBcPcXRATb^daRT ?W^]TCTgc=^a\P[Bch[Tl ETacXRP[0[XV]\T]c,2T]cTa +CTgc1^g 6aXSA^f, 6aXS2^[d\], g)=P\T,cgc=P\T -
+CTgc1[^RZ 6aXSA^f, 6aXS2^[d\], CTgc,3TbRaX_cX^]) Bch[T,jBcPcXRATb^daRT ?W^]TCTgc=^a\P[Bch[Tl ETacXRP[0[XV]\T]c,2T]cTa +CTgc1^g 6aXSA^f, 6aXS2^[d\], g)=P\T,cgc3TbRaX_cX^] 0RRT_cbATcda],CadT 7TXVWc,"+CTgc1[^RZ 6aXSA^f,! 6aXS2^[d\], CTgc,3daPcX^]) Bch[T,jBcPcXRATb^daRT ?W^]TCTgc=^a\P[Bch[Tl ETacXRP[0[XV]\T]c,2T]cTa +CTgc1^g 6aXSA^f,! 6aXS2^[d\], g)=P\T,cgc3daPcX^] 8]_dcBR^_T,CT[T_W^]T=d\QTa :Th3^f],cgc3daPcX^]N:Th3^f]+6aXS+BcPRZ?P]T[+6aXS )N THE 4gTaRXbTgP\[Rb PAGE WE HAVE DEFINED THE CODE TO SAVE EXERCISE PLANNING 4HE %XERCISE PAGE USES THE 0__[XRPcX^]8R^]1Pa BUTTON SEE MORE ON THIS IN 2ECIPE WHICH CALLS THE 0__[XRPcX^]1Pa8R^]BPeT1dcc^]N2[XRZ EVENT HANDLER WHEN CLICKED 4HE CODE FIRST CHECKS WHETHER THE PAGE HAS TO BE SHOWN IN EDIT MODE OR WHETHER THE USER IS GOING TO CREATE A NEW EXERCISE 4HIS IS ACCOMPLISHED BY THE @dTahBcaX]V PROPERTY CHECK )F THE @dTahBcaX]V PROPERTY CONTAINS AN EXERCISE IDENTIFIER SELECTED IN THE PREVIOUS PAGETHE 4RAINING PAGE WHERE ALL EXERCISES ARE LISTEDTHEN THE USER IS GOING TO MODIFY THE EXERCISE !FTER THAT IF THE .AME AND $URATION TEXT BOXES CONTAIN VALUES A NEW 4gTaRXbTBTccX]Vb OBJECT IS CREATED )T WILL CONTAIN VALUES FROM THE RELATED PAGE TEXT BOXES 4HE EXERCISE IDENTIFIER WILL BE EITHER CREATED BY CALLING THE =Tf6dXS STATIC METHOD FROM THE 6dXS CLASS OR SET EQUAL TO THE ONE THAT HAS TO BE MODIFIED !S YOU WILL SEE SHORTLY THE 4gTaRXbTBTccX]Vb CLASS CONTAINS EVERYTHING NECESSARY TO STORE THE EXERCISES INFORMATION &INALLY WHEN THE 3AVE BUTTON IS IN MODIFY MODE IT RETRIEVES THE OLD EXERCISE FROM THE %XERCISES LIST WHICH IS STORED AS A GLOBAL VARIABLE IN THE 0__[XRPcX^] CLASS BY USING A ,).1 QUERY 4HIS %XERCISE OBJECT IS A REFERENCE TO THE STORED EXERCISE SO WE CAN CHANGE ITS PROPERTIES WITHOUT CHANGING THE 6dXS IDENTIFIER TO MODIFY THE EXERCISE _aXePcT e^XS 0__[XRPcX^]1Pa8R^]BPeT1dcc^]N2[XRZ^QYTRc bT]STa 4eT]c0aVb T j Q^^[ Q=Tf , cadT* XU cWXb=PeXVPcX^]2^]cTgc@dTahBcaX]V2^]cPX]b:Th8S Q=Tf , UP[bT* T[bT Q=Tf , cadT* XU cgc=P\TCTgc , bcaX]V4\_ch cgc3daPcX^]CTgc , bcaX]V4\_ch j 4gTaRXbTBTccX]Vb TgTaRXbT , ]d[[* XU Q=Tf j TgTaRXbT , Ua^\ Tg X] 0__[XRPcX^]2daaT]c Pb 0__4gTaRXbTb fWTaT TgXS ,, ]Tf 6dXScWXb=PeXVPcX^]2^]cTgc@dTahBcaX]VJ8SL bT[TRc TgBX]V[T>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
■ .OTE 4HIS CHAPTER DOES NOT COVER ISOLATED STORAGE CONCEPTS IN DEPTH BECAUSE #HAPTER IS DEDICATED TO THAT TOPIC
_dQ[XR bcPcXR ;Xbc+4gTaRXbTBTccX]Vb- ;^PS j ;Xbc+4gTaRXbTBTccX]Vb- TgTaRXbTb , ]Tf ;Xbc+4gTaRXbTBTccX]Vb-* 8b^[PcTSBc^aPVT5X[T bc^aPVT , 8b^[PcTSBc^aPVT5X[T6TcDbTaBc^aT5^a0__[XRPcX^]* XU bc^aPVT5X[T4gXbcbTgTaRXbTbg\[ j 8b^[PcTSBc^aPVT5X[TBcaTP\ bcaTP\ , bc^aPVT>_T]5X[TTgTaRXbTbg\[ 5X[T<^ST>_T]* G\[BTaXP[XiTa g\[ , ]Tf G\[BTaXP[XiTach_T^U;Xbc+4gTaRXbTBTccX]Vb-* TgTaRXbTb , g\[3TbTaXP[XiTbcaTP\ Pb ;Xbc+4gTaRXbTBTccX]Vb-* bcaTP\2[^bT* bcaTP\3Xb_^bT* l aTcda] TgTaRXbTb* l 4HE BPeT STATIC METHOD ACCEPTS A ;Xbc+4gTaRXbTBTccX]Vb- OBJECTS COLLECTION THAT IS STORED IN THE TgTaRXbTbg\[ FILE _dQ[XR bcPcXR e^XS BPeT;Xbc+4gTaRXbTBTccX]Vb- TgTaRXbTb j 8b^[PcTSBc^aPVT5X[T Xb^ , 8b^[PcTSBc^aPVT5X[T6TcDbTaBc^aT5^a0__[XRPcX^]* 8b^[PcTSBc^aPVT5X[TBcaTP\ bcaTP\ , Xb^2aTPcT5X[TTgTaRXbTbg\[* BcaTP\FaXcTa faXcTa , ]Tf BcaTP\FaXcTabcaTP\* G\[BTaXP[XiTa bTa , ]Tf G\[BTaXP[XiTach_T^U;Xbc+4gTaRXbTBTccX]Vb-* bTaBTaXP[XiTfaXcTa TgTaRXbTb* faXcTa2[^bT* faXcTa3Xb_^bT* l 4HE FINAL STEP IN MANAGING TOMBSTONING IN OUR APPLICATION IS TO CALL THOSE TWO METHODS IN THE FOUR 0__[XRPcX^] EVENT HANDLERS 7HEN THE APPLICATION IS LAUNCHED FROM THE 3TART MENU THE APPLICATION CALLS THE ;^PS METHOD FROM THE 4gTaRXbT
_dQ[XR _PacXP[ R[Pbb 0__ ) 0__[XRPcX^] j +bd\\Pah ?a^eXSTb TPbh PRRTbb c^ cWT a^^c UaP\T ^U cWT ?W^]T 0__[XRPcX^] +bd\\Pah +aTcda]b-CWT a^^c UaP\T ^U cWT ?W^]T 0__[XRPcX^]+aTcda]b 2^ST c^ TgTRdcT fWT] cWT P__[XRPcX^] Xb [Pd]RWX]V TV Ua^\ BcPac CWXb R^ST fX[[ ]^c TgTRdcT fWT] cWT P__[XRPcX^] Xb aTPRcXePcTS _aXePcT e^XS 0__[XRPcX^]N;Pd]RWX]V^QYTRc bT]STa ;Pd]RWX]V4eT]c0aVb T j 4gTaRXbTb , 4gTaRXbT
5SAGE &ROM 6ISUAL 3TUDIO OPEN THE &3ad\ PROJECT AND PRESS #TRL& 4HE APPLICATION STARTS BRIEFLY SHOWING THE MAIN PAGE AND THE MENU SHOWN IN &IGURE
&IGURE 4HE &3ad\ APPLICATIONS MAIN PAGE MENU 3ELECT THE 4RAINING MENU AND THEN TAP THE 0LUS BUTTON ON THE APPLICATION BAR AS SHOWN IN &IGURE
&IGURE !DD A NEW EXERCISE BY PRESSING THE 0LUS BUTTON 4HE %XERCISE PAGE IS SHOWN WITH THE THREE EMPTY TEXT BOXES 7RITE SOMETHING AS SHOWN IN &IGURE AND THEN CLICK THE 3AVE BUTTON 4HE TEXT BOXES WILL BE CLEANED IN ORDER TO LET THE USER ADD ANOTHER EXERCISE 0RESS THE HARDWARE "ACK BUTTON TO COME BACK TO THE 4RAINING PAGE
&IGURE !DDING A NEW EXERCISE TO THE TRAINING PLAN 4HE 4RAINING PAGE WILL SHOW A LIST OF EXERCISES YOU ADDED IN THE PREVIOUS STEP .OW LETS PRODUCE THE TOMBSTONING 0RESS THE HARDWARE 3TART BUTTON AND NAVIGATE TO THE APPLICATION LIST ON THE RIGHT 2UN THE &3ad\ APPLICATION AGAIN 3ELECT THE 4RAINING MENU AND YOU WILL HOPEFULLY SEE THE LIST OF EXERCISES BECAUSE YOU NEVER CLOSED THE APPLICATION SEE &IGURE
■ .OTE 7HEN YOU CLOSE THE 7INDOWS 0HONE %MULATOR THE ISOLATED STORAGE IS DELETED ALONG WITH YOUR APPLICATION
&IGURE 4HE 4RAINING PAGE CONTAINS THE LIST OF EXERCISES
-ANAGING 4OMBSTONING IN 7INDOWS 0HONE 8.! !PPLICATIONS 0ROBLEM 9OU NEED TO STOP YOUR 8.! GAME WHEN TOMBSTONING OCCURS ON YOUR PHONE BY SHOWING THE GAME IN PAUSE MODE
3OLUTION 9OU CAN USE BOTH THE >]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
■ .OTE 4HE 6ISUAL 3TUDIO 8.! GAME PROJECT DOESNT CONTAIN THE ASSEMBLIES NEEDED TO USE THE BcPcT DICTIONARY SO YOU HAVE TO ADD A REFERENCE TO <XRa^b^Uc?W^]T AND BhbcT\FX]S^fb 3;;b
_dQ[XR R[Pbb 6P\TBTccX]Vb
_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
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^]<^ST PROPERTY PROVIDED BY THE ?W^]T0__[XRPcX^]BTaeXRT CLASS AND REGISTER BOTH >QbRdaTS AND D]^QbRdaTS EVENT HANDLERS DEFINED IN THE ?W^]T0__[XRPcX^]5aP\T CLASS
(OW )T 7ORKS 0__[XRPcX^]8S[T3TcTRcX^]<^ST IS A PROPERTY THAT IS DEFINED IN THE ?W^]T0__[XRPcX^]BTaeXRT CLASS AND THAT HAS ITS DEFAULT VALUE SET TO 8S[T3TcTRcX^]<^ST4]PQ[TS 4HIS MEANS THAT THE APPLICATION IS SUSPENDED WHEN THE OPERATING SYSTEM FINDS IT IDLE 9OU CAN SET THE PROPERTY TO
8S[T3TcTRcX^]<^ST3XbPQ[TS SO THAT YOUR APPLICATION WILL CONTINUE TO RUN EVEN WHEN THE OPERATING SYSTEM LOCKS THE SCREEN
■ .OTE 4HE LOCK SCREEN IDLE TIME IS DEFINED IN THE 3ETTINGS OF YOUR PHYSICAL PHONE AND IS NOT CONFIGURABLE FROM THE EMULATOR
4HE >QbRdaTS EVENT IS RAISED WHEN THE PHONE SCREEN IS LOCKED BY THE 7INDOWS 0HONE OPERATING SYSTEM OR WHEN YOU RECEIVE A PHONE CALL 4HE D]^QbRdaTS EVENT IS RAISED WHEN THE PHONE SCREEN IS UNLOCKED OR WHEN THE PHONE CALL IS TERMINATED 7HEN THE 8S[T3TcTRcX^]<^ST PROPERTY OF 0__[XRPcX^]8S[T3TcTRcX^]<^ST IS SET TO 3XbPQ[TS YOU CAN USE THOSE TWO METHODS TO STOP POWER CONSUMING RESOURCES SUCH AS THE ACCELEROMETER SCREEN ANIMATIONS &- RADIO SERVICE AND SO ON AND THEN START THEM AGAIN WHEN THE LOCK SCREEN IS REMOVED )N THE >QbRdaTS EVENT HANDLER YOU SHOULD SPECIFY THE CODE TO STOP USELESS THE SERVICE IS ONE THAT YOUR APPLICATION IS NOT GOING TO USE BECAUSE THE PHONE SCREEN IS LOCKED 3O IF YOUR APPLICATION USES THE 3TORY"OARD TO SHOW AN ANIMATED PROGRESS BAR YOU WILL STOP THE ANIMATION BUT UPGRADE THE PROGRESS BAR LOGIC 9OU SHOULD STOP OTHER SERVICES TO REDUCE BATTERY CONSUMPTION 7HEN 8S[T3TcTRcX^]<^ST IS SET TO 4]PQ[TS YOU CAN USE >QbRdaTS AND D]^QbRdaTS EVENT HANDLERS TO MANAGE PARTICULAR EVENTS THAT ARE NOT RAISED WITH TOMBSTONING )NDEED THE PHONE LOCK SCREEN AND PHONE CALLS DONT RAISE TOMBSTONING EVENTS 3O FOR EXAMPLE IF YOU HAVE CREATED A GAME WITH 3ILVERLIGHT AND YOU WANT TO SHOW A PAUSE SCREEN AFTER A PHONE CALL ENDS YOU HAVE TO USE THE >QbRdaTS AND D]^QbRdaTS EVENTS
■ .OTE 4HE >]3TPRcXePcTS EVENT HANDLER FROM THE 8.! 6P\T CLASS RECEIVES THE PHONE SCREEN LOCK AND THE PHONE CALL EVENTS 3O IT IS NOT NECESSARY TO IMPLEMENT THE >QbRdaTS AND D]^QbRdaTS EVENT HANDLERS TO STOP A GAME 4HE >]3TPRcXePcTS EVENT HANDLER REMAINS NECESSARY WHEN YOU DISABLE IDLE DETECTION MODE
4HE #ODE /PEN 6ISUAL 3TUDIO AND CREATE A NEW 7INDOWS 0HONE 3ILVERLIGHT APPLICATION CALLED >QbRdaTSD]^QbRdaTS0__ )N
a^^c5aP\T>QbRdaTS , ]Tf 4eT]c7P]S[Ta+>QbRdaTS4eT]c0aVb-a^^c5aP\TN>QbRdaTS* a^^c5aP\TD]^QbRdaTS , ]Tf 4eT]c7P]S[Taa^^c5aP\TND]^QbRdaTS* l
■ .OTE ! RESTART APPLICATION IS REQUIRED IF YOU CHANGE THE 8S[T3TcTRcX^]<^ST VALUE TWICE AT RUNTIME 4HE OFFICIAL DOCUMENTATION INDICATES THAT THIS BEHAVIOR COULD CHANGE IN FUTURE OPERATING SYSTEM RELEASES
4HE >QbRdaTS EVENT HANDLER PROVIDES THE >QbRdaTS4eT]c0aVb PARAMETER WHICH DEFINES THE 8b;^RZTS PROPERTY USED TO KNOW IF THE EVENT IS RAISED EITHER BY THE PHONE SCREEN LOCK ITS VALUE IS cadT OR BY THE PHONE CALL ITS VALUE IS UP[bT )N THE >QbRdaTS AND D]^QbRdaTS EVENT HANDLERS WE ARE GOING TO DISABLE AND THEN ENABLE THE BATTERYS POWER CONSUMING SERVICES RESPECTIVELY e^XS a^^c5aP\TND]^QbRdaTS^QYTRc bT]STa 4eT]c0aVb T j 5<APSX^8]bcP]RT?^fTa<^ST , APSX^?^fTa<^ST>]* PRRBcPac* VT^FBcPac* l e^XS a^^c5aP\TN>QbRdaTS^QYTRc bT]STa >QbRdaTS4eT]c0aVb T j 5<APSX^8]bcP]RT?^fTa<^ST , APSX^?^fTa<^ST>UU* PRRBc^_* VT^FBc^_* l
5SAGE 4HERE IS NO WAY TO TEST THE APPLICATION BY USING THE >QbRdaTS AND D]^QbRdaTS EVENT HANDLERS IN THE EMULATOR 3O PRESS & ONLY IF YOU CHANGED THE OUTPUT TARGET TO THE 7INDOWS 0HONE DEVICE 9OU HAVE TO PUT TWO BREAKPOINTS IN THE >QbRdaTS AND D]^QbRdaTS CODE SO YOU CAN SEE THAT EVENTS ARE RAISED 4HE APPLICATION WILL START BRIEFLY SHOWING THE MAIN PAGE .OW YOU CAN CALL YOUR PHONE WITH ANOTHER PHONE OR WAIT WHILE THE 7INDOWS 0HONE OPERATING SYSTEM LOCKS THE SCREEN .OTE THE APPLICATION HITTING BREAKPOINTS
CHAPTER 3 ■■■
User Interface ! USERS FIRST IMPRESSION OF A COMPUTER APPLICATIONS USER INTERFACE IS CRITICAL 5SERS WILL IMMEDIATELY DECIDE TO UNINSTALL AN APPLICATION IF IT IS TOO COMPLEX OR IF IT NOT DO WHAT IT PROMISES TO DO 7HEN COMPARING TWO USER INTERFACES USERS WILL OFTEN CHOOSE THE MORE EYE CATCHING ONE 4HE 7INDOWS 0HONE USER INTERFACE IS NOT EXEMPT FROM THIS TYPE OF USER BEHAVIOR )N ADDITION THERE ARE LOT OF APPLICATIONS ON THE -ARKETPLACE SO THE COMPETITION IS RUTHLESS 4HE USER MIGHT TRY YOUR APPLICATION BUT YOU WILL HAVE TO CONVINCE THAT USER TO BUY IT )N THIS CHAPTER AND IN THE NEXT WHICH IS ABOUT %XPRESSION "LEND YOU WILL FIND A LOT OF RECIPES ON THE USER INTERFACE 9OU WILL SEE HOW TO USE 3ILVERLIGHT COMMON CONTROLS AND 3ILVERLIGHT FEATURES SUCH AS BINDINGS BUT ALSO HOW TO IMPLEMENT EYE CATCHING EFFECTS INCLUDING AN ANIMATED SPLASH SCREEN AND NAVIGATION BETWEEN PAGES 4HE RECIPES IN THIS CHAPTER DESCRIBE HOW TO DO THE FOLLOWING v
#REATE AN ANIMATED SPLASH SCREEN
v
5SE THE 0__[XRPcX^]1Pa CONTROL
v
$ETECT CHANGES IN THE THEME TEMPLATE
v
#USTOMIZE THE 3OFT )NPUT 0ANEL KEYBOARD TO ACCEPT ONLY NUMBERS
v
5SE THE 7INDOWS 0HONE PREDEFINED STYLES
v
,OCALIZE YOUR APPLICATION
v
5SE ?P]^aP\P AND ?Xe^c CONTROLS
v
3PICE UP THE USER INTERFACE WITH THE 3ILVERLIGHT FOR 7INDOWS 0HONE 4OOLKIT
v
5SE LAUNCHERS AND CHOOSERS
#REATING AN !NIMATED 3PLASH 3CREEN 0ROBLEM 9OUR APPLICATION STARTS CONNECTING TO A WEB PAGE AND YOU NEED TO SHOW A SPLASH SCREEN WITH AN ANIMATED PROGRESS BAR IN ORDER TO INFORM USERS THAT THEY NEED TO WAIT A FEW SECONDS BEFORE USING THE APPLICATION
3OLUTION 9OU CAN CREATE A USER CONTROL AND USE IT WITH THE 2WX[S PROPERTY PROVIDED BY THE ?^_d_ CLASS 4HE ?a^VaTbb1Pa CONTROL HAS THE 8b8]STcTa\X]PcT PROPERTY SET TO cadT
(OW )T 7ORKS 4HE SPLASH SCREEN PROVIDED BY THE 6ISUAL 3TUDIO 7INDOWS 0HONE 3ILVERLIGHT !PPLICATION PROJECT TEMPLATE IS STATIC A SIMPLE 0.' IMAGE SHOWN DURING THE APPLICATION LAUNCH 4O CREATE AN ANIMATED SPLASH SCREEN YOU NEED TO REMOVE THE B_[PbWBRaTT]_]V FILE FROM THE PROJECT AND USE A TRICK THE ?^_d_ CLASS 5SUALLY THE ?^_d_ CLASS IS USED TO SHOW TOOLTIPS DURING MOUSE ACTIVITIES IN DESKTOP APPLICATIONS (OWEVER WITH A 7INDOWS 0HONE APPLICATION YOU CAN USE IT TO SHOW A GENERIC D84[T\T]c OBJECT PERHAPS EITHER A COMMON CONTROL OR A USER CONTROL 5SER CONTROLS ARE OFTEN USED WHEN YOU NEED TO COMPOSE MORE THAN ONE COMMON CONTROL WITHIN A UNIQUE CONTROL HAVING ITS OWN LOGIC )NSTEAD OF USING DOZENS OF CONTROLS TO CREATE A COMPLEX USER INTERFACE YOU CAN SEPARATE FUNCTIONALITY INTO USER CONTROLS AND THEREBY ACHIEVE CODE REUSABILITY TOO )N THIS CASE YOU ARE GOING TO CREATE A USER CONTROL COMPOSED OF A FULL SCREEN IMAGE¾ PIXELSSOME TEXT AND A PROGRESS BAR 4HE ?^_d_ CLASS PROVIDES THE 2WX[S PROPERTY USED TO SPECIFY THE D84[T\T]c THAT HAS TO BE SHOWN )N THIS CASE THE 2WX[S PROPERTY WILL BE SET TO THE
4HE #ODE 4O DEMONSTRATE THE ANIMATED SPLASH SCREEN EXAMPLE YOU ARE GOING TO CREATE A 5[XRZa?W^c^0[Qd\ APPLICATION 4HIS APPLICATION USES THE &LICKR.%4 LIBRARY SEE Wcc_)U[XRZa]TcR^ST_[TgR^\ AND THE PHONE CAMERA TO TAKE A PICTURE AND UPLOAD IT TO A &LICKR GALLERY "EFORE UPLOADING &LICKR.%4 !0) CALLS TO THE DESTINATION USERS HAVE TO BE AUTHENTICATED TO &LICKR AND HAVE TO ACCEPT THAT YOUR APPLICATION WILL USE THEIR RESOURCES
/UR APPLICATION ACCOMPLISHES THESE STEPS BY REDIRECTING THE FTQ2^]ca^[ CONTENT TO AN 52, PAGE RETURNED BY THE 0dcW2P[RDa[ METHOD CALL )N THIS CASE THE ANIMATED SPLASH SCREEN IS REALLY USEFUL IN ENABLING YOU TO AVOID HAVING THE USER INTERFACE SHOW BLANK FTQ2^]ca^[ CONTENT UNTIL THE PAGE IS LOADED )NDEED BY USING THE =PeXVPcTS EVENT HANDLER YOU KNOW EXACTLY WHEN THE PAGE HAS FINISHED LOADING AND CAN HIDE THE SPLASH SCREEN ,ETS EXAMINE THE CODE FROM THE 5[XRZa?W^c^0[Qd\ APPLICATION )N THE
■ .OTE 4HE bRaTT]_]V IMAGE IS INCLUDED IN THE PROJECT INSIDE THE X\PVTb FOLDER AND HAS THE 1dX[S 0RcX^] PROPERTY SET TO 2^]cT]c )N THIS WAY YOU CAN USE THE RELATIVE PATH IN THE B^daRT ATTRIBUTE OF THE 8\PVT TAG
4HE 8b8]STcTa\X]PcT PROPERTY VALUE IS SET TO cadT IN THE
)N THE
5SAGE )N 6ISUAL 3TUDIO SELECT 7INDOWS 0HONE %MULATOR AS THE TARGET OUTPUT AND PRESS #TRL& 4HE EMULATOR DISPLAYS THE ANIMATED SPLASH SCREEN AS SHOWN IN &IGURE
&IGURE 4HE ANIMATED SPLASH SCREEN IN ACTION 4HE SPLASH SCREEN AUTOMATICALLY DISAPPEARS WHEN THE WEB PAGE IS LOADED SHOWING THE USER INTERFACE BENEATH SEE &IGURE
&IGURE 4HE SPLASH SCREEN IS AUTOMATICALLY HIDDEN AND THE APPLICATION IS READY TO AUTHENTICATE THE USER ON &LICKR
5SING THE !PPLICATION"AR #ONTROL 0ROBLEM 9OU NEED TO ADD THE APPLICATION BAR TO YOUR APPLICATION
3OLUTION 9OU HAVE TO ADD AN 0__[XRPcX^]1Pa SECTION TO THE 8!-, OF YOUR PAGE PROVIDED BY ?W^]T0__[XRPcX^]?PVT WITHIN THE PHONE NAMESPACE 7ITHIN THIS NEW TAG YOU CAN INCLUDE ONE OR MORE 0__[XRPcX^]1Pa TAGS PROVIDEDTHIS TIMEBY THE SHELL NAMESPACE 4HE CODE GENERATED BY 6ISUAL 3TUDIO ALREADY CONTAINS A COMMENTED SECTION IN WHICH 0__[XRPcX^]1Pa IS DEFINED WITH SOME BUTTONS AND MENU ITEMS 9OU CAN SIMPLY UNCOMMENT AND CUSTOMIZE THE CODE TO OBTAIN YOUR GOAL
(OW )T 7ORKS 0__[XRPcX^]1Pa IS A 7INDOWS 0HONE CONTROL ADDED TO 3ILVERLIGHT JUST FOR 7INDOWS 0HONE DEVICES )T ALLOWS YOU TO HAVE A SORT OF TOOLBAR AND MENU IN THE APPLICATION 4HE APPLICATION BAR IS COMPLETELY MANAGED BY THE OPERATING SYSTEM SO IT IS PLACED AT THE BOTTOM OF THE PAGE WHEN THE APPLICATION IS IN 0ORTRAIT MODE AND MOVED TO ONE SIDE WHEN THE PHONE IS PUT IN ,ANDSCAPE MODE WHICH SIDE DEPENDS ON THE DIRECTION IN WHICH YOU ROTATE YOUR PHONE 4HE APPLICATION BAR SHOULD CONTAIN AT LEAST FOUR ICONS AND YOU SHOULD USE THE ONES PROVIDED WITH THE 3$+ )N THE ?a^VaP\ 5X[TbK<XRa^b^Uc B3:bKFX]S^fb ?W^]TKe&K8R^]b PATH YOU CAN FIND BOTH DARK AND LIGHT VERSIONS OF APPLICATION BAR ICONS 9OU SHOULD USE DIFFERENT ICON COLORS DEPENDING ON THE SELECTED THEME SEE 2ECIPE )F YOU USE THE DARK VERSION THE OPERATING SYSTEM WILL TAKE CARE OF CHANGING THE ICON COLORS FOR YOU AUTOMATICALLY )F YOU DONT FIND THE ICON YOU NEED YOU CAN USE -ICROSOFT %XPRESSION "LEND FOR 7INDOWS 0HONE TO DRAW YOUR OWN 4HE APPLICATION BAR ALSO CAN CONTAIN MENU ITEMS THAT WILL BE SHOWN WHEN THE USER SELECTS THE ELLIPSES AT THE TOP RIGHT OF THE BAR 9OU SHOULD NOT SPECIFY TOO MANY MENU ITEMS HOWEVER BECAUSE THE APPLICATION BAR WILL EXPAND TOWARD THE TOP TO SHOW ALL ITEMS AND COULD COVER IMPORTANT PARTS OF THE USER INTERFACE CONTROL 4HE OFFICIAL DOCUMENTATION SETS THIS LIMIT TO AT MOST FIVE MENU ITEMS 9OU HAVE TO SET THE 8b
&IGURE 4HE 0__[XRPcX^]1Pa CLASS DIAGRAM 4HE 0__[XRPcX^]1Pa CONTROL HAS THE >_PRXch PROPERTY WHICH AFFECTS THE RECTANGLE THAT CONTAINS THE ICONS NOT THE ICONS THEMSELVES 4HIS PROPERTY ACCEPTS A DECIMAL VALUE BETWEEN AND 7HEN YOU SET THIS PROPERTY TO THE FRAME RESIZES THE PAGES CONTENT IN ORDER TO RESERVE SPACE FOR THE APPLICATION BAR /N THE OTHER HAND WHEN YOU SET THIS PROPERTY TO A VALUE LESS THAN THE APPLICATION BAR AND ITS BUTTONS WILL BE DRAWN OVER THE PAGE CONTENT 4HE 8bEXbXQ[T PROPERTY IS USED TO SET WHEN THE APPLICATION BAR HAS TO BE SHOWN cadT AND WHEN IT DOES NOT UP[bT
!LTHOUGH YOU CAN ASSIGN A NAME TO BOTH MENU ITEMS AND APPLICATION BAR BUTTONS YOU CANT USE THOSE NAMES TO ACCESS RELATED PROPERTIES 9OU HAVE TO USE THE 1dcc^]b AND
■ .OTE 2EMEMBER TO CHANGE THE ICONS 1dX[S 0RcX^]b PROPERTY FROM ATb^daRT TO 2^]cT]c SO THAT YOU CAN SPECIFY A RELATIVE 52) PATH TO THE IMAGE
4HE CTgc PROPERTY IS USED TO SPECIFY A VERY SHORT BUTTONS DESCRIPTION THAT WILL BE SHOWN WHEN THE USER SELECTS THE ELLIPSES BUTTON &INALLY 8b4]PQ[TS IS USED TO EITHER ENABLE OR DISABLE THE BUTTON 0__[XRPcX^]1Pa
4HE #ODE 9OU WILL FIND A LOT OF APPLICATIONS USING THE 0__[XRPcX^]1Pa CONTROL IN THIS BOOK 4O DEMONSTRATE THIS RECIPE WE ARE IMPLEMENTING THE 0__[XRPcX^]1Pa IN THE &3ad\ APPLICATION SPECIFICALLY IN THE 4RAINING PAGE 4HIS PAGE ALLOWS YOU TO ADD EDIT AND DELETE AN EXERCISE )N THE CaPX]X]VgP\[ PAGE YOU DEFINE AN 0__[XRPcX^]1Pa CONTROL WITH FOUR BUTTONS AND ONE MENU ITEM +BP\_[T R^ST bW^fX]V dbPVT ^U 0__[XRPcX^]1Pa+_W^]T)?W^]T0__[XRPcX^]?PVT0__[XRPcX^]1Pa+bWT[[)0__[XRPcX^]1Pa 8bEXbXQ[T,CadT 8b
+bWT[[)0__[XRPcX^]1Pa
5SAGE )N 6ISUAL 3TUDIO LOAD THE &3ad\ PROJECT FROM THE COMPANION CODE AND THEN PRESS #TRL& )F YOUR TARGET OUTPUT IS THE 7INDOWS 0HONE %MULATOR YOU WILL SEE IT RUNNING BRIEFLY 4AP THE 4RAINING MENU SO
THAT YOU GO TO THE 4RAINING PAGE SHOWN IN &IGURE !T THE BOTTOM OF THE SCREEN YOU CAN SEE THE APPLICATION BAR WITH THE !DD BUTTON ENABLED AND THE OTHERS DISABLED
&IGURE 4HE APPLICATION BAR CONTAINS FOUR BUTTONS BUT ONLY ONE IS ENABLED
#LICKING THE ELLIPSES BUTTON AT THE TOP RIGHT CORNER OF THE APPLICATION BAR CAUSES THE BUTTON DESCRIPTIONS AND THE MENU ITEMS TO APPEAR SEE &IGURE
&IGURE #LICKING THE ELLIPSES BUTTON THE APPLICATION BAR SHOWS THE BUTTONS TEXT AND MENU ITEMS
$ETECTING #HANGES IN THE 4HEME 4EMPLATE 0ROBLEM 9OU NEED TO DETECT WHEN THE USER CHANGES THE 7INDOWS 0HONE THEME FROM $ARK TO ,IGHT OR VICE VERSA SO YOU CAN CHANGE ICONS BUTTONS AND BACKGROUND COLORS ACCORDINGLY
3OLUTION 9OU CAN USE THE ATb^daRT3XRcX^]Pah CLASS PROVIDED BY THE ATb^daRTb PROPERTY FROM THE 0__[XRPcX^] CLASS
(OW )T 7ORKS 4HE 0__[XRPcX^] CLASS HAS A STATIC PROPERTY CALLED ATb^daRTb THAT RETURNS A ATb^daRT3XRcX^]Pah OBJECT FILLED WITH 7INDOWS 0HONE RESOURCES REPRESENTING FOR EXAMPLE THE CHOSEN FONTS THE BACKGROUND COLOR THE FOREGROUND COLOR AND SO ON )N THIS RECIPE YOU WILL USE THE ?W^]T1PRZVa^d]S1adbW RESOURCE TO RETRIEVE THE CHOSEN BACKGROUND THEME COLOR )F THE THEME IS SET TO $ARK THIS VALUE WILL BE EQUAL TO THE BLACK COLOR 2ED 'REEN "LUE VALUES SET TO /THERWISE IT WILL BE SET TO THE WHITE COLOR 2ED 'REEN "LUE VALUES SET TO FOR THE ,IGHT THEME
4HE #ODE 4O DEMONSTRATE THIS RECIPE YOU WILL CREATE THE 3TcTRcX]VCWT\T2WP]VX]V 3ILVERLIGHT FOR 7INDOWS 0HONE APPLICATION 4HE APPLICATION HAS A MAIN PAGE ON WHICH TWO APPLICATION BAR BUTTONS ARE SET WITH THE DARK IMAGE VERSION $URING THE ;^PSTS EVENT HANDLER THE APPLICATION CHECKS WHAT COLOR IS STORED IN THE ?W^]T1PRZVa^d]S1adbW KEY WITHIN THE ATb^daRTb DICTIONARY "ASED ON THE RETURNED VALUE THE ICONS ARE TAKEN FROM EITHER THE DARK OR THE LIGHT RELATIVE PATH )N THE
_aXePcT e^XS D_SPcTD8 j XU CWT\T3TcTRc^a8b3PaZCWT\T j Qc]?[Ph8R^]DaX , ]Tf DaX8\PVTbSPaZP__QPacaP]b_^ac_[PhaTbc_]V DaX:X]SAT[PcXeT* Qc]Bc^_8R^]DaX , ]Tf DaX8\PVTbSPaZP__QPabc^_aTbc_]V DaX:X]SAT[PcXeT* ?PVTCXc[TCTgc , 3PaZ CWT\T* l T[bT j Qc]?[Ph8R^]DaX , ]Tf DaX8\PVTb[XVWcP__QPacaP]b_^ac_[PhaTbc_]V DaX:X]SAT[PcXeT* Qc]Bc^_8R^]DaX , ]Tf DaX8\PVTb[XVWcP__QPabc^_aTbc_]V DaX:X]SAT[PcXeT* ?PVTCXc[TCTgc , ;XVWc CWT\T* l l 4HE CWT\T3TcTRc^a CLASS HAS ONLY ONE PROPERTY WHICH RETURNS A "OOLEAN VALUE INDICATING WHEN THE $ARK BACKGROUND THEME IS IN USE _dQ[XR R[Pbb CWT\T3TcTRc^a j _dQ[XR bcPcXR Q^^[ 8b3PaZCWT\T j VTc j B^[XS2^[^a1adbW QPRZVa^d]S1adbW , 0__[XRPcX^]2daaT]cATb^daRTbJ?W^]T1PRZVa^d]S1adbWL Pb B^[XS2^[^a1adbW* XU QPRZVa^d]S1adbW2^[^a ,, 2^[^a5a^\0aVQ!$$ 1[PRZ R^[^a aTcda] cadT* T[bT aTcda] UP[bT* l l l
■ 4IP 9OU CAN USE THE CWT\T3TcTRc^a CLASS IN YOUR PROJECTS TO RETRIEVE THE CURRENT BACKGROUND THEME AND TO CHANGE YOUR BUTTONS COLORS ICONS AND SO FORTH
5SAGE &ROM 6ISUAL 3TUDIO SELECT THE 7INDOWS 0HONE %MULATOR AS YOUR TARGET OUTPUT AND THEN PRESS #TRL& 4HE EMULATOR STARTS BRIEFLY DISPLAYING THE APPLICATION WITH THE APPLICATION BAR SHOWN IN &IGURE
!S YOU CAN SEE THE APPLICATION USES THE PAGE TITLE TO INFORM THE USER ABOUT THE BACKGROUND THEME IT HAS FOUND IN THE OPERATING SYSTEM
&IGURE 4HE APPLICATION HAS DETECTED THE $ARK THEME
0RESS THE HARDWARE 3TART BUTTON AND THEN GO TO THE APPLICATION LIST BY PRESSING THE RIGHT ARROW AT THE TOP RIGHT CORNER OF THE SCREEN 3ELECT THE 3ETTINGS TILE TAP THE 4HEME LIST ITEM AND CHANGE THE "ACKGROUND VALUE FROM $ARK TO ,IGHT .OW THE EMULATOR HAS THE WHITE BACKGROUND COLOR GO BACK TO THE APPLICATION EITHER BY PRESSING THE HARDWARE "ACK BUTTON UNTIL YOU REACH IT OR BY RUNNING A NEW APPLICATION INSTANCE 4HE APPLICATION RETRIEVES THE CURRENT BACKGROUND THEME AS THE ,IGHT THEME AND CHANGES THE ICON ACCORDINGLY SEE &IGURE
&IGURE 4HE APPLICATION DETECTS THE NEW BACKGROUND AND CHANGES THE ICONS AND PAGE TITLE
#USTOMIZING THE 3OFT )NPUT 0ANEL +EYBOARD TO !CCEPT /NLY .UMBERS 0ROBLEM 9OU NEED TO PROVIDE A VIRTUAL KEYBOARD ALSO CALLED A 3OFT )NPUT 0ANEL OR 3)0 THAT ACCEPTS ONLY NUMBERS SO USERS CAN INSERT NUMERIC VALUES INTO A TEXT FIELD
3OLUTION 9OU CAN USE THE 8]_dcBR^_T PROPERTY PROVIDED BY THE CTgc1^g CONTROL AND USE THE :Th3^f] EVENT TO EXCLUDE KEYS THAT ARE NOT NEEDED
(OW )T 7ORKS 7HEN THE USER HAS TO INSERT INFORMATION IN YOUR APPLICATION AND TAPS ON A TEXT FIELD A 3)0 KEYBOARD APPEARS ALLOWING THE INPUT OF TEXT "Y USING THE 8]_dcBR^_T ATTRIBUTE IN YOUR 8!-, CODE YOU CAN CUSTOMIZE THE 3)0 IN ORDER TO HELP USERS DURING TEXT INPUT 9OU CAN USE ONE OF THE VALUES AVAILABLE FROM THE 8]_dcBR^_T=P\TEP[dT ENUMERATOR AS SHOWN IN 4ABLE &OR EXAMPLE IF YOU USE THE CT[T_W^]T=d\QTa VALUE THE TAPPED TEXT BOX WILL SHOW THE PANEL USED TO COMPOSE A TELEPHONE NUMBER
■ .OTE 4HERE ARE MORE THAN VALUES IN THE 8]_dcBR^_T=P\TEP[dT ENUMERATOR AND MOST OF THEM EITHER ARE USELESS OR CAUSE NO CHANGES TO THE 3)0 4ABLE LISTS THE MOST COMMON VALUES THAT ARE SPECIFIC TO THE 7INDOWS 0HONE
4ABLE 4HE -OST #OMMON 8]_dcBR^_T %NUMERATOR 6ALUES
Value
Description
2WPc
5SED FOR CHAT MESSAGING 3)0 RECOGNIZES PRE STORED ABBREVIATIONS
3XVXcb
3PECIFIES DIGITS
4\PX[=P\T>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
3PECIFIES A MAP LOCATION
=P\T>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 8]_dcBR^_T SET TO THE CT[T_W^]T=d\QTa VALUE +2^]cT]c?P]T[ _[PRT PSSXcX^]P[ R^]cT]c WTaT+6aXS g)=P\T,2^]cT]c?P]T[ 6aXSA^f, <PaVX], ! !+BcPRZ?P]T[+6aXS+6aXSA^f3TUX]XcX^]b+A^f3TUX]XcX^] 7TXVWc,0dc^+A^f3TUX]XcX^] 7TXVWc,0dc^+A^f3TUX]XcX^] 7TXVWc,+6aXSA^f3TUX]XcX^]b+6aXS2^[d\]3TUX]XcX^]b+2^[d\]3TUX]XcX^] FXScW,0dc^ +2^[d\]3TUX]XcX^] FXScW, +6aXS2^[d\]3TUX]XcX^]b-
+CTgc1[^RZ 6aXSA^f, 6aXS2^[d\], CTgc,=P\T) Bch[T,jBcPcXRATb^daRT ?W^]TCTgc=^a\P[Bch[Tl ETacXRP[0[XV]\T]c,2T]cTa +CTgc1^g 6aXSA^f, 6aXS2^[d\], g)=P\T,cgc=P\T +CTgc1[^RZ 6aXSA^f, 6aXS2^[d\], CTgc,3TbRaX_cX^]) Bch[T,jBcPcXRATb^daRT ?W^]TCTgc=^a\P[Bch[Tl ETacXRP[0[XV]\T]c,2T]cTa +CTgc1^g 6aXSA^f, 6aXS2^[d\], g)=P\T,cgc3TbRaX_cX^] 0RRT_cbATcda],CadT 7TXVWc,"+CTgc1[^RZ 6aXSA^f,! 6aXS2^[d\], CTgc,3daPcX^] \X]) Bch[T,jBcPcXRATb^daRT ?W^]TCTgc=^a\P[Bch[Tl ETacXRP[0[XV]\T]c,2T]cTa +CTgc1^g 6aXSA^f,! 6aXS2^[d\], g)=P\T,cgc3daPcX^] 8]_dcBR^_T,CT[T_W^]T=d\QTa :Th3^f],cgc3daPcX^]N:Th3^f]+6aXS+BcPRZ?P]T[+6aXS )N THE 4gTaRXbTgP\[Rb CODE THE :Th3^f] EVENT HANDLER ENSURES THAT NO NUMERIC DIGITS ARE INSERTED IN THE $URATION TEXT BOX 4HE :Th4eT]c0aVb PARAMETER PROVIDED 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
+BcPRZ?P]T[ >aXT]cPcX^],7^aXi^]cP[ <PaVX],$$+ATRcP]V[T FXScW, 7TXVWc, 5X[[,jBcPcXRATb^daRT ?W^]T1PRZVa^d]S1adbWl +CTgc1[^RZ <PaVX],$ CTgc,?W^]T1PRZVa^d]S1adbW 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^]T2^]caPbc1PRZVa^d]S1adbWl +CTgc1[^RZ <PaVX],$ CTgc,?W^]T2^]caPbc1PRZVa^d]S1adbW 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^]T2^]caPbc5^aTVa^d]S1adbWl +CTgc1[^RZ <PaVX],$ CTgc,?W^]T2^]caPbc5^aTVa^d]S1adbW 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^]T3XbPQ[TS1adbWl +CTgc1[^RZ <PaVX],$ CTgc,?W^]T3XbPQ[TS1adbW 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^]TBdQc[T1adbWl +CTgc1[^RZ <PaVX],$ CTgc,?W^]TBdQc[T1adbW 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^]T1^aSTa1adbWl +CTgc1[^RZ <PaVX],$ CTgc,?W^]T1^aSTa1adbW 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 CaP]b_PaT]c1adbWl +CTgc1[^RZ <PaVX],$ CTgc,CaP]b_PaT]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^]TBT\XcaP]b_PaT]c1adbWl +CTgc1[^RZ <PaVX],$ CTgc,?W^]TBT\XcaP]b_PaT]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^]T2Wa^\T1adbWl +CTgc1[^RZ <PaVX],$ CTgc,?W^]T2Wa^\T1adbW 5^]cBXiT,jBcPcXRATb^daRT ?W^]T5^]cBXiT=^a\P[l +BcPRZ?P]T[+BcPRZ?P]T[+;Xbc1^g+R^]ca^[b)?Xe^c8cT\4HE SECOND ?Xe^c CONTROL CONTAINS THE STYLES APPLICABLE TO TEXT BOXES +R^]ca^[b)?Xe^c8cT\ 7TPSTa,CTgc1^gTb+;Xbc1^g <PaVX], !+BcPRZ?P]T[ >aXT]cPcX^],ETacXRP[ <PaVX], &+CTgc1^g 1^aSTa1adbW,jBcPcXRATb^daRT ?W^]TCTgc1^g4SXc1^aSTa1adbWl 1PRZVa^d]S,jBcPcXRATb^daRT ?W^]TCTgc1^g4SXc1PRZVa^d]S1adbWl 5^aTVa^d]S,jBcPcXRATb^daRT ?W^]TCTgc1^g5^aTVa^d]S1adbWl BT[TRcX^]5^aTVa^d]S,jBcPcXRATb^daRT ?W^]TCTgc1^gBT[TRcX^]5^aTVa^d]S1adbWl +CTgc1[^RZ CTgcFaP__X]V,FaP_ CTgc,CTgc1^g fXcW ?W^]TCTgc1^g4SXc1^aSTa1adbW ?W^]TCTgc1^g4SXc1PRZVa^d]S1adbW ?W^]TCTgc2PaTc1adbW ?W^]TCTgc1^g5^aTVa^d]S1adbW P]S ?W^]TCTgc1^gBT[TRcX^]5^aTVa^d]S1adbW bch[Tb +BcPRZ?P]T[+BcPRZ?P]T[ >aXT]cPcX^],ETacXRP[ <PaVX], &+CTgc1^g 8bATPS>][h,CadT 1PRZVa^d]S,jBcPcXRATb^daRT ?W^]TCTgc1^gATPS>][h1adbWl CTgc,8\ P aTPS^][h cTgcQ^g+CTgc1[^RZ CTgcFaP__X]V,FaP_ CTgc,ATPS ^][h CTgc1^g fXcW ?W^]TCTgc1^gATPS>][h1adbW +BcPRZ?P]T[+;Xbc1^g+R^]ca^[b)?Xe^c8cT\4HE THIRD ?Xe^c CONTROL CONTAINS THE 5^]cb STATIC RESOURCE STYLES 4HE 5^]c5P\X[h AND 5^]cBXiT PROPERTIES OF THE CTgc1[^RZ CONTROL ARE USED TO SHOW THE 5^]c STATIC RESOURCE STYLES +R^]ca^[b)?Xe^c8cT\ 7TPSTa,5^]cb+;Xbc1^g <PaVX], !+BcPRZ?P]T[ >aXT]cPcX^],ETacXRP[ <PaVX], &+CTgc1[^RZ 5^]c5P\X[h,jBcPcXRATb^daRT ?W^]T5^]c5P\X[h=^a\P[l 5^]cBXiT,jBcPcXRATb^daRT ?W^]T5^]cBXiTB\P[[l CTgc,?W^]T5^]c5P\X[h=^a\P[ fXcW ?W^]T5^]cBXiTB\P[[ +CTgc1[^RZ 5^]c5P\X[h,jBcPcXRATb^daRT ?W^]T5^]c5P\X[h=^a\P[l 5^]cBXiT,jBcPcXRATb^daRT ?W^]T5^]cBXiT=^a\P[l CTgc,?W^]T5^]c5P\X[h=^a\P[ fXcW ?W^]T5^]cBXiT=^a\P[ +CTgc1[^RZ 5^]c5P\X[h,jBcPcXRATb^daRT ?W^]T5^]c5P\X[h=^a\P[l 5^W]cBXiT,jBcPcXRATb^daRT ?W^]T5^]cBXiT
+CTgc1[^RZ 5^]c5P\X[h,jBcPcXRATb^daRT ?W^]T5^]c5P\X[h=^a\P[l 5^]cBXiT,jBcPcXRATb^daRT ?W^]T5^]cBXiT
+CTgc1[^RZ 5^]c5P\X[h,jBcPcXRATb^daRT ?W^]T5^]c5P\X[hBT\X;XVWcl 5^]cBXiT,jBcPcXRATb^daRT ?W^]T5^]cBXiT
-
-
+CTgc1[^RZ 5^]c5P\X[h,jBcPcXRATb^daRT ?W^]T5^]c5P\X[hBT\X1^[Sl 5^]cBXiT,jBcPcXRATb^daRT ?W^]T5^]cBXiTB\P[[l CTgc,?W^]T5^]c5P\X[hBT\X1^[S fXcW ?W^]T5^]cBXiTB\P[[ +CTgc1[^RZ 5^]c5P\X[h,jBcPcXRATb^daRT ?W^]T5^]c5P\X[hBT\X1^[Sl 5^]cBXiT,jBcPcXRATb^daRT ?W^]T5^]cBXiT=^a\P[l CTgc,?W^]T5^]c5P\X[hBT\X1^[S fXcW ?W^]T5^]cBXiT=^a\P[ +CTgc1[^RZ 5^]c5P\X[h,jBcPcXRATb^daRT ?W^]T5^]c5P\X[hBT\X1^[Sl 5^]cBXiT,jBcPcXRATb^daRT ?W^]T5^]cBXiT
+R^]ca^[b)?Xe^c8cT\ 7TPSTa,CTgc Bch[Tb+;Xbc1^g <PaVX], !+BcPRZ?P]T[ >aXT]cPcX^],ETacXRP[ <PaVX], &+CTgc1[^RZ Bch[T,jBcPcXRATb^daRT ?W^]TCTgc1[^RZ1PbTl CTgc,?W^]TCTgc1[^RZ1PbT +CTgc1[^RZ Bch[T,jBcPcXRATb^daRT ?W^]TCTgc=^a\P[Bch[Tl CTgc,?W^]TCTgc=^a\P[Bch[T +CTgc1[^RZ Bch[T,jBcPcXRATb^daRT ?W^]TCTgcCXc[T Bch[Tl CTgc,?W^]TCTgcCXc[T Bch[T +CTgc1[^RZ Bch[T,jBcPcXRATb^daRT ?W^]TCTgcCXc[T!Bch[Tl CTgc,?W^]TCTgcCXc[T!Bch[T +CTgc1[^RZ Bch[T,jBcPcXRATb^daRT ?W^]TCTgcCXc[T"Bch[Tl CTgc,?W^]TCTgcCXc[T"Bch[T +CTgc1[^RZ Bch[T,jBcPcXRATb^daRT ?W^]TCTgc;PaVTBch[Tl CTgc,?W^]TCTgc;PaVTBch[T +CTgc1[^RZ Bch[T,jBcPcXRATb^daRT ?W^]TCTgc4gcaP;PaVTBch[Tl CTgc,?W^]TCTgc4gcaP;PaVTBch[T +CTgc1[^RZ Bch[T,jBcPcXRATb^daRT ?W^]TCTgc6a^d_7TPSTaBch[Tl CTgc,?W^]TCTgc6a^d_7TPSTaBch[T +CTgc1[^RZ Bch[T,jBcPcXRATb^daRT ?W^]TCTgcB\P[[Bch[Tl CTgc,?W^]TCTgcB\P[[Bch[T +CTgc1[^RZ Bch[T,jBcPcXRATb^daRT ?W^]TCTgc2^]caPbcBch[Tl CTgc,?W^]TCTgc2^]caPbcBch[T +CTgc1[^RZ Bch[T,jBcPcXRATb^daRT ?W^]TCTgc0RRT]cBch[Tl CTgc,?W^]TCTgc0RRT]cBch[T +BcPRZ?P]T[+;Xbc1^g+R^]ca^[b)?Xe^c8cT\+R^]ca^[b)?Xe^c+6aXS4HIS CHANGES THE APPLICATION BACKGROUND COLOR TO HT[[^f6aTT] SO THAT SYSTEM COLORS CAN BE VISIBLE &INALLY ALL THE PREDEFINED SYSTEM RESOURCES ARE SPECIFIED BY USING THE jBcPcXRATb^daRTl MARKUP EXTENSION SO AS TO HAVE A VISUAL REPRESENTATION OF THOSE RESOURCES AT RUNTIME
5SAGE &ROM 6ISUAL 3TUDIO RUN THE APPLICATION BY PRESSING #TRL& $EPENDING ON THE TARGET OUTPUT THE APPLICATION DEPLOYS EITHER ON THE 7INDOWS 0HONE %MULATOR OR THE 7INDOWS 0HONE DEVICE 4HE APPLICATION STARTS SHOWING ALL THE AVAILABLE BRUSHES YOU HAVE TO SCROLL UP AND DOWN TO SEE THEM ALL &LICKING TO THE LEFT BRINGS YOU TO THE NEXT PAGE WHICH SHOWS TEXT BOX STYLES 'OING FURTHER TO THE LEFT SHOWS ALL THE PREDEFINED FONT STYLES &INALLY THE LAST PAGE SHOWS THE PREDEFINED TEXT STYLES SEE &IGURE
&IGURE 4HE ?aT3TUX]TSBhbcT\Bch[Tb3T\^ APPLICATION SHOWS ALL THE STATIC RESOURCES PROVIDED BY THE PHONE
,OCALIZING 9OUR !PPLICATION 0ROBLEM 9OU NEED TO CREATE AN APPLICATION THAT CHANGES THE USER INTERFACE DEPENDING ON THE LANGUAGE AND REGIONAL SETTINGS OF THE 7INDOWS 0HONE OPERATING SYSTEM
3OLUTION 9OU CAN USE THE 2d[cdaT8]U^ CLASS AND ITS =P\T PROPERTY TO RETRIEVE THE CURRENT LANGUAGE AND REGIONAL SETTINGS -OREOVER BY USING THE ATb^daRTb FILES FROM 6ISUAL 3TUDIO YOU CAN DEFINE CONSTANT STRINGS IN DIFFERENT LANGUAGES THAT CAN BE SHOWN ACCORDING TO THE SELECTED 7INDOWS 0HONE OPERATING SYSTEM LANGUAGE
(OW )T 7ORKS ,OCALIZING YOUR APPLICATION IS AN IMPORTANT TASK BECAUSE BY IMPLEMENTING DIFFERENT LANGUAGES YOU CAN DISTRIBUTE YOUR APPLICATION IN VARIOUS MARKETS !LSO YOU CAN OBTAIN AUTOMATIC FORMATTING OF INFORMATION THAT DIFFERS FROM COUNTRY TO COUNTRY SUCH AS DATES CALENDARS AND MONEY 6ISUAL 3TUDIO AND 7INDOWS 0HONE 3$+ GIVE YOU ALL THE NECESSARY TOOLS TO EASILY IMPLEMENT A LOCALIZED APPLICATION 4HE 2d[cdaT8]U^ CLASS INCLUDES PROPERTIES AND METHODS TO RETRIEVE THE CURRENT CULTURE SET IN THE USER PHONE SEE &IGURE FOR THE CLASS DIAGRAM !N INSTANCE OF THE 2d[cdaT8]U^ CLASS
IS RETRIEVED BY USING THE 2daaT]cCWaTPS STATIC PROPERTY PROVIDED BY THE CWaTPS CLASS 4HIS CLASS IS DEFINED IN THE BhbcT\CWaTPSX]V NAMESPACE WHILE THE 2d[cdaT8]U^ CLASS IS DEFINED IN THE BhbcT\6[^QP[XiPcX^] NAMESPACE
&IGURE 4HE 2d[cdaT8]U^ CLASS DIAGRAM
4HE =P\T PROPERTY OF THE 2d[cdaT8]U^ CLASS RETURNS THE CULTURE NAME 4HIS VALUE HAS A STANDARD FORMAT SUCH AS T]DB Xc8C Ua5A AND SO ON 4HE NAME IS DIVIDED INTO A LOWERCASE TWO LETTER PART THAT INDICATES THE LANGUAGE AND AN UPPERCASE TWO LETTER PART THAT INDICATES THE COUNTRY OR REGION 3O FOR EXAMPLE THE T]DB NAME INDICATES THE %NGLISH LANGUAGE USED IN THE 5NITED 3TATES AND THE T]20 NAME INDICATES THE %NGLISH LANGUAGE IN #ANADA "Y USING 6ISUAL 3TUDIO YOU CAN ADD RESOURCE FILES IN WHICH YOU CAN PUT STRINGS AND CONSTANT VALUES )F YOU SPECIFY THE CULTURE NAME IN THE RESOURCE FILENAME FOR EXAMPLE THE
4HE #ODE 4O DEMONSTRATE THIS RECIPE YOU WILL CREATE THE ;^RP[XiPcX^]3T\^ 3ILVERLIGHT FOR 7INDOWS 0HONE APPLICATION $EPENDING ON THE SELECTED LANGUAGE AND REGIONAL SETTINGS IN THE 7INDOWS 0HONE OPERATING SYSTEM THE APPLICATION CHANGES ITS TITLE BUTTON CAPTIONS AND IMAGE 3O CREATE A NEW 3ILVERLIGHT FOR 7INDOWS 0HONE APPLICATION AND CALL IT ;^RP[XiPcX^]3T\^ 4HEN SELECT !DD .EW )TEM FROM THE 0ROJECT MENU AND SELECT THE 2ESOURCE &ILE TEMPLATE FROM THE !DD .EW )TEM DIALOG BOX 9OU CAN GIVE YOUR OWN NAME TO THE FILE WE CHOSE ATb^daRTaTbg 2EPEAT THIS OPERATION TO ADD ANOTHER RESOURCE FILE BUT THIS TIME YOU HAVE TO APPEND THE CULTURE NAME AND REGION )N OUR CASE BEING )TALIAN WE ADDED THE RESOURCE FILE ATb^daRTXc8CaTbg 3PECIFY THE SAME KEYS IN THE RESOURCE FILE BUT WITH DIFFERENT VALUES &IGURE COMPARES THE TWO RESOURCE FILES
&IGURE 4HE RESOURCE FILES COMPARED 4HE CIRCLED !CCESS 0UBLIC COMBO BOX IN &IGURE HAS TO BE SET TO 0UBLIC SO THAT 6ISUAL 3TUDIO GENERATES A CLASS FOR YOU 4HIS CLASSWHICH HAS THE SAME RESOURCE FILENAME WITHOUT THE FILE EXTENSION CAN BE USED DIRECTLY IN YOUR CODE SO THAT YOU CAN SPECIFY RESOURCES IN THE 8!-, FILE 4HE ATb^daRT CLASS GENERATED FROM THE ATb^daRTaTbg RESOURCE FILE IS INSTANTIATED INTO THE CUSTOM ;^RP[XiTSBcaX]V CLASS )N THE CLASS CONSTRUCTOR A NEW ATb^daRT OBJECT IS CREATED AND BY USING THE ;^RP[XiTSATb^daRT PROPERTY IS RETURNED TO THE CALLER 4HIS CLASS WILL BE USED IN
+0__[XRPcX^] g)2[Pbb,;^RP[XiPcX^]3T\^0__ g\[]b,Wcc_)bRWT\Pb\XRa^b^UcR^\fX]Ug!%gP\[_aTbT]cPcX^] g\[]b)g,Wcc_)bRWT\Pb\XRa^b^UcR^\fX]Ug!%gP\[ g\[]b)_W^]T,R[a]P\Tb_PRT)<XRa^b^Uc?W^]T2^]ca^[b*PbbT\Q[h,<XRa^b^Uc?W^]T g\[]b)bWT[[,R[a]P\Tb_PRT)<XRa^b^Uc?W^]TBWT[[*PbbT\Q[h,<XRa^b^Uc?W^]T g\[]b)[^RP[,R[a]P\Tb_PRT);^RP[XiPcX^]3T\^+0__[XRPcX^] ATb^daRTb+0__[XRPcX^]ATb^daRTb+[^RP[);^RP[XiTSBcaX]V g):Th,;^RP[XiTSBcaX]V +0__[XRPcX^]ATb^daRTb )N THE
5SAGE 0RESS #TRL& TO EXECUTE THE APPLICATION 4HE APPLICATION DEPLOYS EITHER ON THE EMULATOR OR THE DEVICE DEPENDING ON THE TARGET OUTPUT CHOSEN
)N OUR CASE THE EMULATOR STARTS WITH THE %NGLISH LANGUAGE SET AS THE CULTURE SO THE APPLICATION SHOWS THE TITLE THE BUTTON CAPTION AND THE IMAGE TAKEN FROM THE %NGLISH RESOURCE FILE SEE THE LEFT PART OF &IGURE
■ .OTE 4HIS IS THE INVARIANT CULTURE RESOURCE FILE SO YOU WILL SEE THE %NGLISH LANGUAGE EVEN IF YOU CHOSE OTHER UNSUPPORTED LANGUAGES SUCH AS &RENCH OR 3PANISH
&IGURE 4HE ;^RP[XiPcX^]3T\^ APPLICATION SHOWING BOTH SUPPORTED LANGUAGES .OW GO TO THE 3TART MENU BY PRESSING THE HARDWARE 3TART BUTTON 4AP THE TOP RIGHT CIRCLED ARROW TO ACCESS THE APPLICATION LIST AND THEN TAP THE 3ETTINGS APP &ROM THE 2EGION ,ANGUAGE MENU SELECT THE
)TALIANO LANGUAGE &INALLY TAP THE 4AP (ERE 4O !CCEPT #HANGES !ND 2ESTART 9OUR 0HONE LINK TO ACCEPT THE NEW LANGUAGE SEE &IGURE
&IGURE 4HE 2EGION ,ANGUAGE SETTINGS PAGE 4HE PHONE RESTARTS AND YOU CAN GO TO THE APPLICATION LIST AND AGAIN EXECUTE THE ;^RP[XiPcX^]3T\^ APPLICATION 4HIS TIME IT WILL SHOW THE )TALIAN LANGUAGE AND THE LOCALIZED IMAGE SEE THE RIGHT PART OF &IGURE
5SING 0ANORAMA AND 0IVOT #ONTROLS 0ROBLEM 9OU NEED TO DEVELOP AN APPLICATION THAT SHOWS A LOT OF INFORMATION THAT IS SEPARATED INTO CATEGORIES OR GROUPS 9OU DONT WANT TO PUT THIS INFORMATION ON SEPARATE PAGES AND PROVIDE A NAVIGATION SYSTEM YOU WOULD PREFER TO HAVE THEM ON THE SAME MAIN PAGE OF THE APPLICATION
3OLUTION 9OU CAN USE EITHER A ?P]^aP\P CONTROL OR A ?Xe^c CONTROL PROVIDED BY THE <XRa^b^Uc?W^]T2^]ca^[b ASSEMBLY
(OW )T 7ORKS "OTH CONTROLS ARE SIMILAR IN THEIR PROGRAMMING AND FINAL OUTPUT SO YOU CAN CHOOSE WHICH ONE TO USE IN YOUR APPLICATION %ACH PROVIDES A CXc[T PROPERTY USED TO SPECIFY A TITLE FOR THE APPLICATION %ACH ALSO PROVIDES THE ggg8cT\ CHILD CONTROL WHERE ggg CAN BE EITHER A ?Xe^c OR ?P]^aP\P CONTROL USED TO SPECIFY A CATEGORY OR A GROUP OF INFORMATION 9OU CAN SPECIFY WHATEVER YOU WANT WITHIN THIS CHILD CONTROL BECAUSE IT DERIVES FROM 2^]cT]c2^]ca^[ 4HE COMMON IMPLEMENTATION PROVIDES A ;Xbc1^g CONTROL WITH ITS OWN TEMPLATE PROVIDING AN IMAGE AND SOME RELATED TEXT )N THE 7INDOWS 0HONE OPERATING SYSTEM YOU CAN SEE THE ?P]^aP\P CONTROL IN ACTION EXECUTING THE -ARKETPLACE APPLICATION /N THE OTHER HAND EXECUTE THE BTccX]Vb APPLICATION TO SEE THE ?Xe^c CONTROL IN ACTION !S YOU CAN SEE THE MAIN DIFFERENCE BETWEEN THESE TWO CONTROLS IS THE BACKGROUND IMAGE PROVIDED BY THE ?P]^aP\P CONTROL 4HE CXc[T PROPERTY IN THE ?P]^aP\P CONTROL USES A LARGER FONT RESPECT TO THE ONE PROVIDED BY THE ?Xe^c CONTROL )NDEED WITH THE ?P]^aP\P CONTROL THE TITLE GIVES THE PANORAMA EFFECT BECAUSE THE FULL TITLE IS READABLE ONLY BY SCROLLING BETWEEN PANORAMAS ITEMS
4HE #ODE )N THIS RECIPE YOU WILL CREATE AN APPLICATION THAT SHOWS TODAYS ""# PROGRAM SCHEDULE BY USING BOTH A ?P]^aP\P AND A ?Xe^c CONTROL 4HE 46 SCHEDULE IS PROVIDED BY A WEB SERVICE FROM THE fffQ[TQ^aV SITE SEE MORE ON HOW TO USE WEB SERVICES IN YOUR APPLICATION IN #HAPTER 4HE FIRST OPERATION TO PERFORM IS TO ADD A REFERENCE TO THE <XRa^b^Uc?W^]T2^]ca^[bS[[ ASSEMBLY ONLY IF YOU HAVENT CREATED THE APPLICATION FROM THE 7INDOWS 0HONE 0ANORAMA !PPLICATION OR THE 7INDOWS 0HONE 0IVOT !PPLICATION 6ISUAL 3TUDIO TEMPLATE )N THIS CASE WE STARTED THE CeBRWTSd[T& APPLICATION AND THE CeBRWTSd[T?Xe^c& APPLICATION TOO FROM THE 6ISUAL 3TUDIO TEMPLATE SO WE ALREADY HAVE ALL THAT IS NEEDED TO USE BOTH ?P]^aP\P AND ?Xe^c CONTROLS 4HIS TEMPLATE IMPLEMENTS THE -ODEL 6IEW 6IEW-ODEL -66- ARCHITECTURE SO YOU WILL FIND THE EXTf<^ST[b FOLDER IN THE 6ISUAL 3TUDIO SOLUTION CONTAINING TWO FILES 8cT\EXTf<^ST[Rb AND
j _aXePcT bcaX]V NcXc[T* +bd\\Pah ?a^VaP\\T cXc[T +bd\\Pah +aTcda]b-+aTcda]b_dQ[XR bcaX]V CXc[T j VTc j aTcda] NcXc[T* l bTc j XU eP[dT , NcXc[T j NcXc[T , eP[dT* =^cXUh?a^_Tach2WP]VTSCXc[T* l l l _aXePcT bcaX]V NbcPac4]S* +bd\\Pah ?a^VaP\\T bcPac T]S +bd\\Pah +aTcda]b-+aTcda]b_dQ[XR bcaX]V BcPac4]S j VTc j aTcda] NbcPac4]S* l bTc j XU eP[dT , NbcPac4]S j NbcPac4]S , eP[dT* =^cXUh?a^_Tach2WP]VTSBcPac4]S* l l l
_aXePcT bcaX]V NSTbRaX_cX^]* +bd\\Pah BP\_[T EXTf<^ST[ _a^_Tach* cWXb _a^_Tach Xb dbTS X] cWT eXTf c^ SXb_[Ph Xcb eP[dT dbX]V P 1X]SX]V +bd\\Pah +aTcda]b-+aTcda]b_dQ[XR bcaX]V 3TbRaX_cX^] j VTc j aTcda] NSTbRaX_cX^]* l bTc j XU eP[dT , NSTbRaX_cX^] j NSTbRaX_cX^] , eP[dT* =^cXUh?a^_Tach2WP]VTS3TbRaX_cX^]* l l l _dQ[XR TeT]c ?a^_Tach2WP]VTS4eT]c7P]S[Ta ?a^_Tach2WP]VTS* _aXePcT e^XS =^cXUh?a^_Tach2WP]VTSBcaX]V _a^_Tach=P\T j ?a^_Tach2WP]VTS4eT]c7P]S[Ta WP]S[Ta , ?a^_Tach2WP]VTS* XU ]d[[ , WP]S[Ta j WP]S[TacWXb ]Tf ?a^_Tach2WP]VTS4eT]c0aVb_a^_Tach=P\T* l l l )N THE
8=^cXUh?a^_Tach2WP]VTS
>QbTaePQ[T2^[[TRcX^]+8cT\EXTf<^ST[-* >QbTaePQ[T2^[[TRcX^]+8cT\EXTf<^ST[-* >QbTaePQ[T2^[[TRcX^]+8cT\EXTf<^ST[-*
+bd\\Pah 0 R^[[TRcX^] U^a 8cT\EXTf<^ST[ ^QYTRcb +bd\\Pah_dQ[XR >QbTaePQ[T2^[[TRcX^]+8cT\EXTf<^ST[- 112 8cT\b j VTc* _aXePcT bTc* l _dQ[XR >QbTaePQ[T2^[[TRcX^]+8cT\EXTf<^ST[- 112!8cT\b j VTc* _aXePcT bTc* l _dQ[XR >QbTaePQ[T2^[[TRcX^]+8cT\EXTf<^ST[- 8CE 8cT\b j VTc* _aXePcT bTc* l 4HEN IN THE ;^PS3PcP METHOD YOU DEFINE THE CODE TO LOAD THE 46 SCHEDULE FROM THE WEB SERVICE 3O YOU CREATE A NEW FTQ2[XT]c OBJECT AND HOOK ITS OWN 3^f][^PSBcaX]V2^\_[TcTS EVENT 4HIS IS RAISED WHEN THE CALL TO THE 3^f][^PSBcaX]V0bh]R METHOD IS COMPLETED 9OU CALL THIS METHOD TO RETRIEVE INFORMATION FROM THE WEB SERVICE 4HE LAST METHOD PARAMETER REPRESENTS A USER TOKEN STRING THAT IS PASSED AS A PARAMETER TO THE 3^f][^PSBcaX]V2^\_[TcTS EVENT HANDLER 9OU USE IT TO DETERMINE WHICH 46 CHANNEL IS REQUIRED FOR THE WEB SERVICE AND WHICH IS THE NEXT CHANNEL TO RETRIEVE _dQ[XR e^XS ;^PS3PcP j fTQ , ]Tf FTQ2[XT]c* fTQ3^f][^PSBcaX]V0bh]R]Tf DaXWcc_)fffQ[TQ^aVceSPcP[XbcX]VbQQR g\[ 112 * fTQ3^f][^PSBcaX]V2^\_[TcTS , ]Tf 3^f][^PSBcaX]V2^\_[TcTS4eT]c7P]S[TafTQN3^f][^PSBcaX]V2^\_[TcTS* l 4HE REAL DATA LOADING IS IN THE 3^f][^PSBcaX]V2^\_[TcTS EVENT HANDLER "ECAUSE THE WEB SERVICE RETURNS 8-, CONTENT YOU USE THE ,).1 TO 8-, LIBRARY TO LOAD AND MANAGE THIS RESULT ! SNIPPET OF THE 8-, CONTENT IS SHOWN HERE +.g\[ eTabX^], T]R^SX]V,DC5'.+ _a^SdRTS U^a cWT Q[TQ^aV CE bhbcT\ Pc Bd] <Pa % ')"()" ! +RWP]]T[ XS,QQR b^daRT,G<;CE SPcT,%"! +_a^VaP\\T+U[PVb-B+U[PVb+STbR-CWT [PcTbc ]Tfb b_^acb QdbX]Tbb P]S fTPcWTa Ua^\ cWT 112b 1aTPZUPbc cTP\+STbR+cXc[T-1aTPZUPbc+cXc[T+T]S-&"$+T]S+bcPac-%+bcPac+_a^VaP\\T 4HE ?PabT METHOD FROM THE G4[T\T]c CLASS LOADS AND PARSES THE 8-, AND THEN GOES THROUGH ITS _a^VaP\\T ELEMENTS FILLING THE
■ .OTE )T IS NOT POSSIBLE TO CALL THE 3^f][^PSBcaX]V0bh]R METHOD AGAIN UNTIL THE 3^f][^PSBcaX]V2^\_[TcTS EVENT IS RAISED /THERWISE THE APPLICATION RETRIEVES AN EXCEPTION
&INALLY YOU SET THE 8b3PcP;^PSTS PROPERTY TO cadT TO INDICATE THAT THE LOADING OPERATIONS ARE CONCLUDED e^XS fTQN3^f][^PSBcaX]V2^\_[TcTS^QYTRc bT]STa 3^f][^PSBcaX]V2^\_[TcTS4eT]c0aVb T j XU T4aa^a , ]d[[ T4aa^a
cWXb8b3PcP;^PSTS , cadT* l 4HE CODE SHOWN TO THIS POINT IS COMMON TO BOTH THE ?P]^aP\P AND ?Xe^c EXAMPLES BECAUSE IT MANAGES THE MODEL AND DATA PART OF THE -66- ARCHITECTURE .OW YOU CAN FOCUS YOUR ATTENTION ON HOW TO VISUALLY REPRESENT THIS DATA "OTH THE ?P]^aP\P AND ?Xe^c ITEM CHILDREN CONTROLS HAVE DEFINED A ;Xbc1^g WITH A TEMPLATE INCLUDING AN IMAGE CONTROL AND TWO CTgc1[^RZS WITHIN A STACK PANEL 4HE ;Xbc1^gAS WITH MOST OF THE CONTROLSPROVIDES THE BINDING FEATURE USED TO POPULATE THE CONTROL READING DATA FROM A DATA SOURCE 4HE 8cT\bB^daRT ATTRIBUTE FROM THE ;Xbc1^g CONTROL ACCEPTS THE BINDING TO THE COLLECTIONS DEFINED IN THE
■ .OTE 4HE ;Xbc1^g CONTROL DEFINES THE BT[TRcX^]2WP]VTS EVENT HANDLER USED TO RETRIEVE WHEN THE USER TAPS ON A LIST ITEM )N THIS APPLICATION THIS EVENT HANDLER IS USED TO SHOW PROGRAM DETAILS "Y THE WAY THIS IS NOT THE PROPER IMPLEMENTATION IF YOU WANT TO WRITE CODE USING THE PURE -66- PATTERN #HAPTER COVERS THE -66- PATTERN
.OW LETS SEE THE DIFFERENCES IN THE 8!-, CODE IN ORDER TO DEFINE EITHER A ?P]^aP\P OR A ?Xe^c CONTROL 4HE ?P]^aP\P HAS A BACKGROUND THAT IS NOT PROVIDED BY THE ?Xe^c BUT THE REST OF CODE IS REALLY SIMILAR (ERE IS THE ?Xe^c CONTROL DEFINITION WITH ONE ITEM +;Ph^dcA^^c Xb cWT a^^c VaXS fWTaT P[[ _PVT R^]cT]c Xb _[PRTS-
+6aXS g)=P\T,;Ph^dcA^^c 1PRZVa^d]S,CaP]b_PaT]c+?Xe^c 2^]ca^[+R^]ca^[b)?Xe^c CXc[T,CeBRWTSd[T&+?Xe^c XcT\ ^]T+R^]ca^[b)?Xe^c8cT\ 7TPSTa,112 +3^dQ[T [X]T [Xbc fXcW cTgc faP__X]V !ND HERE IS THE ?P]^aP\P DEFINITION +;Ph^dcA^^c Xb cWT a^^c VaXS fWTaT P[[ _PVT R^]cT]c Xb _[PRTS+6aXS g)=P\T,;Ph^dcA^^c 1PRZVa^d]S,CaP]b_PaT]c+?P]^aP\P R^]ca^[+R^]ca^[b)?P]^aP\P CXc[T,CeBRWTSd[T&+R^]ca^[b)?P]^aP\P1PRZVa^d]S+8\PVT1adbW 8\PVTB^daRT,?P]^aP\P1PRZVa^d]S_]V+R^]ca^[b)?P]^aP\P1PRZVa^d]S+?P]^aP\P XcT\ ^]T+R^]ca^[b)?P]^aP\P8cT\ 7TPSTa,112 4HATS IT 4HE CODE DEFINES THE OTHER TWO CONTROL ITEMS WITH THE OTHER TWO 46 CHANNELS BUT THE CODE IS PRETTY MUCH THE SAME IT DIFFERS ONLY IN ITS )$ AND HEADER TEXT
5SAGE 7E HAVE TWO PROJECTS CeBRWTSd[T& THAT USES THE ?P]^aP\P CONTROL AND CeBRWTSd[T?Xe^c& THAT USES THE ?Xe^c CONTROL 3O OPEN TWO 6ISUAL 3TUDIO PROGRAM INSTANCES AND LOAD THESE TWO PROJECTS 0RESS #TRL& FROM ONE 6ISUAL 3TUDIO INSTANCE AND WAIT UNTIL THE APPLICATION IS DEPLOYED AND STARTED &OR EXAMPLE STARTING WITH THE CeBRWTSd[T& EXAMPLE YOU WILL SEE THE ?P]^aP\P CONTROL SHOWING A BACKGROUND WITH ""# 46 SCHEDULED PROGRAMS AND PART OF ""# 46 SCHEDULED PROGRAMS SEE THE LEFT PART OF &IGURE 9OU CAN FLICK TO THE LEFT SO THAT THE ?P]^aP\P CONTROL SHOWS SOME OTHER PART OF THE TITLE AND THE ""#S PROGRAM SCHEDULES 7HEN YOU REACH THE LAST ITEM OF THE ?P]^aP\P CONTROL AND FLICK AGAIN TO THE LEFT THE CONTROL WILL SHOW YOU THE FIRST PAGE
,EAVING THE EMULATOR IN EXECUTION LAUNCH THE OTHER PROJECT 4HE ?Xe^c CONTROL WILL BRIEFLY SHOW THE SAME INFORMATION BUT WITH A DIFFERENT USER INTERFACE SEE THE RIGHT HAND SIDE OF &IGURE 4HE TITLE IS FULLY READABLE AND THERE ARE MORE LIST BOX ITEMS VISIBLE %VEN WITH THE ?Xe^c CONTROL YOU CAN FLICK EITHER LEFT OR RIGHT TO NAVIGATE THROUGH ITEMS
&IGURE ?P]^aP\P VS ?Xe^c CONTROLS
3PICING 5P THE 5SER )NTERFACE WITH THE 3ILVERLIGHT 4OOLKIT 0ROBLEM 9OU WOULD LIKE TO ENHANCE YOUR USER INTERFACE WITH SOME NEW CONTROLS BUT DONT WANT TO SPEND TIME MAKING THEM
3OLUTION 9OU CAN USE THE 3ILVERLIGHT FOR 7INDOWS 0HONE 4OOLKIT WHICH IS AVAILABLE FROM #ODE0LEX AT Wcc_)bX[eTa[XVWcR^ST_[TgR^\
(OW )T 7ORKS 4HE <XRa^b^Uc?W^]T2^]ca^[bC^^[ZXcS[[ ASSEMBLY THAT YOU DOWNLOAD FROM THE #ODE0LEX SITE HAS CONTROLS 3OME ARE NEW CONTROLS AND OTHERS ARE ENHANCED VERSIONS OF EXISTING CONTROLS !T THE TIME OF THIS WRITING THE 3ILVERLIGHT FOR 7INDOWS 0HONE 4OOLKIT IS THE &EBRUARY VERSION )T CONTAINS THE FOLLOWING CONTROLS v
4HE 0dc^2^\_[TcT1^g CONTROL IS AN ENHANCED VERSION OF THE CTgc1^g CONTROL THAT IMPLEMENTS THE AUTOCOMPLETE FEATURE 7HILE YOU ARE WRITING TEXT A POP UP APPEARS SUGGESTING SIMILAR WORDS
v
4HE 2^]cTgc
v
4HE 3PcT?XRZTa AND CX\T?XRZTa CONTROLS ALLOW USERS TO EASILY SELECT A DATE AND A TIME RESPECTIVELY
v
4HE 6TbcdaTBTaeXRT6TbcdaT;XbcT]Ta CONTROLS HELP DEVELOPERS TO EASILY MANAGE GESTURES IN A 3ILVERLIGHT APPLICATION SEE 2ECIPE IN #HAPTER
v
4HE ;Xbc?XRZTa CONTROL IS A SORT OF COMBO BOX ALLOWING USERS TO PICK A VALUE FROM A LIST $EPENDING ON ITS ATTRIBUTES THE LIST CAN EITHER BE SHOWN AS A POP UP OR CAN FILL THE FULL SCREEN
v
4HE ;^]V;XbcBT[TRc^a CONTROL AS ITS NAME SUGGESTS PROVIDES A LIST THAT IS CAPABLE OF CONTAINING A LOT OF ITEMS AND OF AUTOMATICALLY ADDING A SCROLLBAR WHEN NEEDED
v
4HE ?PVT CaP]bXcX^]b ARE A SET OF CLASSES DEDICATED TO ADDING PAGE TRANSITION EFFECTS DURING PAGE NAVIGATION
v
4HE ?TaU^a\P]RT?a^VaTbb1Pa CONTROL IS AN ENHANCED VERSION OF THE ?a^VaTbb1Pa CONTROL THAT USES THE COMPOSITOR THREAD TO PAINT ITSELF $IFFERING FROM THE USER INTERFACE THREAD THE COMPOSITOR IS A SEPARATE THREAD THAT MANAGES ANIMATION AND OTHER DEDICATED TASKS 4HIS THREAD PERFORMS BETTER THAN THE USER INTERFACE THREAD AND THIS CONTROL USES IT TO CREATE THE PROGRESS BAR ANIMATION
v
4HE CX[c4UUTRc CONTROL PROVIDES A HIGHLY REQUIRED ANIMATION FROM THE )NTERNET COMMUNITY THE TILT EFFECT 4HE TILT ANIMATION IS APPLIED TO CONTROLS THAT IMPLEMENT THE 2[XRZ EVENT ADDING A SHAKING EFFECT WHEN THE CONTROL IS CLICKED 4HE CX[c4UUTRc CONTROL PROVIDES AN ATTACHED PROPERTY SET TO A CONTAINER CONTROL SUCH AS THE ?PVT THAT ADDS THE TILT EFFECT TO ITS OWN CONTROLS
v
4HE C^VV[TBfXcRW CONTROL IS USED TO TURN ON OR OFF SETTINGS OR FEATURES THAT YOU HAVE ADDED TO YOUR APPLICATION &OR EXAMPLE THE 7INDOWS 0HONE OPERATING SYSTEM USES THIS CONTROL ON ITS 3ETTINGS PAGE TO ACTIVATE OR DEACTIVATE !IRPLANE MODE
v
4HE FaP_?P]T[ CONTROL IS AN ENHANCED VERSION OF THE BcPRZ?P]T[ THAT IMPLEMENTS A WRAP FEATURE FOR THE CONTROLS IT CONTAINS
4HE #ODE 4O DEMONSTRATE THIS RECIPE WE HAVE BORROWED THE OFFICIAL EXAMPLE THAT SHIPS WITH THE 3ILVERLIGHT FOR 7INDOWS 0HONE 4OOLKIT LIBRARY 4O USE IT IN YOUR CODE YOU FIRST NEED TO ADD A REFERENCE TO THE LIBRARY THAT USUALLY IS INSTALLED IN THE ?a^VaP\ 5X[TbK<XRa^b^Uc B3:bKFX]S^fb ?W^]TKe&KC^^[ZXc PATH 4HE ?W^]TC^^[ZXcBP\_[T APPLICATION HAS A MAIN PAGE WITH BUTTONS %ACH OF THEM POINTS TO A CONTROL DEMO 4HE DATE AND TIME PICKERS HAVE BEEN GROUPED TOGETHER SO THERE ARE REALLY CONTROLS AS STATED EARLIER 4HE 0dc^2^\_[TcT1^g CONTROL IS DEFINED IN THE 0dc^2^\_[TcT1^gBP\_[TgP\[ PAGE &IRST OF ALL IT IS WORTH NOTING THE TOOLKIT NAMESPACE ADDED TO THE ?PVT TAG THIS IS COMMON TO ALL PAGES USING THE TOOLKIT CONTROLS +_W^]T)?W^]T0__[XRPcX^]?PVT g)2[Pbb,?W^]TC^^[ZXcBP\_[TBP\_[Tb0dc^2^\_[TcT1^gBP\_[T g\[]b,Wcc_)bRWT\Pb\XRa^b^UcR^\fX]Ug!%gP\[_aTbT]cPcX^] g\[]b)g,Wcc_)bRWT\Pb\XRa^b^UcR^\fX]Ug!%gP\[ g\[]b)_W^]T,R[a]P\Tb_PRT)<XRa^b^Uc?W^]T2^]ca^[b*PbbT\Q[h,<XRa^b^Uc?W^]T g\[]b)bWT[[,R[a]P\Tb_PRT)<XRa^b^Uc?W^]TBWT[[*PbbT\Q[h,<XRa^b^Uc?W^]T g\[]b)c^^[ZXc,R[a ]P\Tb_PRT)<XRa^b^Uc?W^]T2^]ca^[b*PbbT\Q[h,<XRa^b^Uc?W^]T2^]ca^[bC^^[ZXc 4HE USUAL 2^]cT]c?P]T[ GRID IS REPLACED BY A STACK PANEL CONTAINING TWO CTgc1[^RZ CONTROLS AND TWO 0dc^2^\_[TcT1^g CONTROLS 4HE 8cT\B^daRT PROPERTY IS USED TO DEFINE THE SOURCE FROM WHICH SUGGESTIONS ARE PICKED AND SHOWN 4HE SECOND 0dc^2^\_[TcT1^g CONTROL USES A TWO LINE SUGGESTION SUCH AS THE ONE USED BY )NTERNET %XPLORER THAT SHOWS BOTH PAGE TITLE AND ITS 52, +BcPRZ?P]T[ g)=P\T,2^]cT]c?P]T[ 6aXSA^f, <PaVX], ! !+CTgc1[^RZ CTgc,0dc^2^\_[TcT1^g bX]V[T[X]T XcT\b Bch[T,jBcPcXRATb^daRT ?W^]TCTgc=^a\P[Bch[Tl+c^^[ZXc)0dc^2^\_[TcT1^g ETacXRP[0[XV]\T]c,C^_ 8cT\bB^daRT,jBcPcXRATb^daRT f^aSbl <PaVX], !+CTgc1[^RZ CTgc,0dc^2^\_[TcT1^g S^dQ[T[X]T XcT\b Bch[T,jBcPcXRATb^daRT ?W^]TCTgc=^a\P[Bch[Tl-
+c^^[ZXc)0dc^2^\_[TcT1^g 8]_dcBR^_T,Da[ 8cT\bB^daRT,jBcPcXRATb^daRT fTQbXcTbl <PaVX], ! EP[dT
+c^^[ZXc)2^]cTgc
+CTgc1[^RZ CTgc,CP_ P]S W^[S WTaT c^ X]e^ZT P 2^]cTgc
+c^^[ZXc);Xbc?XRZTa8cT\CT\_[PcT+3PcPCT\_[PcT+BcPRZ?P]T[ >aXT]cPcX^],7^aXi^]cP[+ATRcP]V[T 5X[[,j1X]SX]Vl FXScW,!# 7TXVWc,!#+CTgc1[^RZ CTgc,j1X]SX]Vl <PaVX], ! +BcPRZ?P]T[+3PcPCT\_[PcT+c^^[ZXc);Xbc?XRZTa8cT\CT\_[PcT+c^^[ZXc);Xbc?XRZTa5d[[<^ST8cT\CT\_[PcT+3PcPCT\_[PcT+BcPRZ?P]T[ >aXT]cPcX^],7^aXi^]cP[ <PaVX], % ! !+ATRcP]V[T 5X[[,j1X]SX]Vl FXScW,#" 7TXVWc,#"+CTgc1[^RZ CTgc,j1X]SX]Vl <PaVX], % 5^]cBXiT,#" 5^]c5P\X[h,jBcPcXRATb^daRT ?W^]T5^]c5P\X[h;XVWcl+BcPRZ?P]T[+3PcPCT\_[PcT+c^^[ZXc);Xbc?XRZTa5d[[<^ST8cT\CT\_[PcT+c^^[ZXc);Xbc?XRZTa4HE ;^]V;XbcBT[TRc^a CONTROL IS SHOWN IN THE ;^]V;XbcBT[TRc^aBP\_[TgP\[ FILE 4HIS PAGE IMPLEMENTS THE ?Xe^c CONTROL YOU SAW IN THE PREVIOUS RECIPE )N THE FIRST PART OF THE ;^]V;XbcBT[TRc^aBP\_[TgP\[ CODE THE RESOURCES USED TO POPULATE THE ;^]V;XbcBT[TRc^a CONTROL ARE DEFINED $ATA IS TAKEN FROM READING SOME EXTERNAL SOURCE TEXT FILES AND USING CLASSES CONTAINED IN THE 3PcP FOLDER OF THE PROJECT !S SHOWN IN THE FOLLOWING CODE THE DATA IS MOVIE RESOURCES +_W^]T)?W^]T0__[XRPcX^]?PVTATb^daRTb+ <>E84 A4B>DA24B + CWT cT\_[PcT U^a cWT [Xbc WTPSTa CWXb fX[[ bRa^[[ Pb P _Pac ^U cWT [Xbc +3PcPCT\_[PcT g):Th,\^eXT;Xbc7TPSTa+CTgc1[^RZ CTgc,]Tf aT[TPbTb Bch[T,jBcPcXRATb^daRT ?W^]TCTgcCXc[T Bch[Tl+3PcPCT\_[PcT+ CWT Va^d_ WTPSTa cT\_[PcT U^a Va^d_b X] cWT \PX] [Xbc +3PcPCT\_[PcT g):Th,\^eXT6a^d_7TPSTa+1^aSTa 1PRZVa^d]S,jBcPcXRATb^daRT ?W^]T0RRT]c1adbWl ?PSSX]V,jBcPcXRATb^daRT ?W^]TC^dRWCPaVTc>eTaWP]Vl+CTgc1[^RZ CTgc,j1X]SX]V :Thl Bch[T,jBcPcXRATb^daRT ?W^]TCTgc;PaVTBch[Tl+1^aSTa+3PcPCT\_[PcT-
+ CWT cT\_[PcT U^a Va^d_b fWT] cWTh PaT XcT\b X] cWT Yd\_ [Xbc =^c bTccX]V + cWT 6a^d_8cT\CT\_[PcT _a^_Tach fX[[ SXbPQ[T Yd\_ [Xbc Ud]RcX^]P[Xch +3PcPCT\_[PcT g):Th,Va^d_8cT\7TPSTa+1^aSTa 1PRZVa^d]S,jBcPcXRATb^daRT ?W^]T0RRT]c1adbWl <PaVX],jBcPcXRATb^daRT ?W^]TC^dRWCPaVTc>eTaWP]Vl ?PSSX]V,jBcPcXRATb^daRT ?W^]TC^dRWCPaVTc>eTaWP]Vl+CTgc1[^RZ CTgc,j1X]SX]V :Thl Bch[T,jBcPcXRATb^daRT ?W^]TCTgc;PaVTBch[Tl+1^aSTa+3PcPCT\_[PcT+ CWT cT\_[PcT U^a \^eXT XcT\b +3PcPCT\_[PcT g):Th,\^eXT8cT\CT\_[PcT+6aXS <PaVX],jBcPcXRATb^daRT ?W^]TC^dRWCPaVTc>eTaWP]Vl+6aXS2^[d\]3TUX]XcX^]b+2^[d\]3TUX]XcX^] FXScW,0dc^+2^[d\]3TUX]XcX^] FXScW,+6aXS2^[d\]3TUX]XcX^]b+8\PVT FXScW, 7TXVWc, $ B^daRT,j1X]SX]V 8\PVTDa[l ETacXRP[0[XV]\T]c,C^_+BcPRZ?P]T[ 6aXS2^[d\], ETacXRP[0[XV]\T]c,C^_+CTgc1[^RZ CTgc,j1X]SX]V CXc[Tl Bch[T,jBcPcXRATb^daRT ?W^]TCTgc;PaVTBch[Tl 5^]c5P\X[h,jBcPcXRATb^daRT ?W^]T5^]c5P\X[hBT\X1^[Sl CTgcFaP__X]V,FaP_ <PaVX], ! ! !%+CTgc1[^RZ CTgc,j1X]SX]V BcPabl Bch[T,jBcPcXRATb^daRT ?W^]TCTgc=^a\P[Bch[Tl CTgcFaP__X]V,FaP_ 5^]c5P\X[h,jBcPcXRATb^daRT ?W^]T5^]c5P\X[hBT\X1^[Sl+CTgc1[^RZ CTgc,j1X]SX]V 8]U^a\PcX^]l Bch[T,jBcPcXRATb^daRT ?W^]TCTgcB\P[[Bch[Tl 5^]c5P\X[h,jBcPcXRATb^daRT ?W^]T5^]c5P\X[hBT\X1^[Sl+CTgc1[^RZ CTgc,j1X]SX]V 3TbRaX_cX^]l Bch[T,jBcPcXRATb^daRT ?W^]TCTgc=^a\P[Bch[Tl CTgcFaP__X]V,FaP_ 5^]c5P\X[h,jBcPcXRATb^daRT ?W^]T5^]c5P\X[hBT\X;XVWcl+BcPRZ?P]T[+6aXS+3PcPCT\_[PcT+SPcP)<^eXTb1h2PcTV^ah g):Th,\^eXTb+SPcP)<^aT2^\\P]S g):Th,\^aT2^\\P]S+ 1D3384B A4B>DA24B +SPcP)?T^_[T1h5Xabc=P\T g):Th,QdSSXTb+SPcP)6a^d_C^1adbWEP[dT2^]eTacTa g):Th,Va^d_1adbW+_W^]T)?W^]T0__[XRPcX^]?PVTATb^daRTb-
)N THE FIRST ?Xe^c ITEM THE BASIC VERSION OF THE ;^]V;XbcBT[TRc^a IS USED TO SHOW MOVIES SEPARATED BY CATEGORIES 4HESE DATA ARE RETRIEVED BY USING A ,).1 QUERY THAT IS ASSIGNED TO THE 8cT\B^daRT PROPERTY IN THE CODE %ACH ;^]V;XbcBT[TRc^a SECTION IS ASSOCIATED TO THE RESOURCES DEFINED IN THE PRECEDING CODE 4HE ;Xbc7TPSTaCT\_[PcT IS USED TO ADD SOME HEADER TEXT TO THE LIST 4HE 6a^d_7TPSTaCT\_[PcT AND 6a^d_8cT\CT\_[PcT ARE USED WHEN A GROUPING OPERATION IS ACCOMPLISHED ON THE DATA &INALLY 8cT\CT\_[PcT IS THE TEMPLATE USED TO SHOW ITEMS +6aXS g)=P\T,;Ph^dcA^^c 1PRZVa^d]S,CaP]b_PaT]c+R^]ca^[b)?Xe^c CXc[T,;>=6;8BCB4;42C>A B0;4B+R^]ca^[b)?Xe^c8cT\ 7TPSTa,[X]`+c^^[ZXc);^]V;XbcBT[TRc^a g)=P\T,[X]`<^eXTb 1PRZVa^d]S,CaP]b_PaT]c ;Xbc7TPSTaCT\_[PcT,jBcPcXRATb^daRT \^eXT;Xbc7TPSTal 6a^d_7TPSTaCT\_[PcT,jBcPcXRATb^daRT \^eXT6a^d_7TPSTal 6a^d_8cT\CT\_[PcT,jBcPcXRATb^daRT Va^d_8cT\7TPSTal 8cT\CT\_[PcT,jBcPcXRATb^daRT \^eXT8cT\CT\_[PcTl+c^^[ZXc);^]V;XbcBT[TRc^a+R^]ca^[b)?Xe^c8cT\4HE NEXT ?Xe^c ITEM PROVIDES A ;^]V;XbcBT[TRc^a THAT HAS A 6a^d_5^^cTaCT\_[PcT DEFINED TO ADD A BUTTON THAT SHOWS OTHER RESULTS WHEN PRESSED +R^]ca^[b)?Xe^c8cT\ 7TPSTa,R^ST+c^^[ZXc);^]V;XbcBT[TRc^a g)=P\T,R^ST<^eXTb 1PRZVa^d]S,CaP]b_PaT]c 8cT\bB^daRT,jBcPcXRATb^daRT \^eXTbl ;Xbc7TPSTaCT\_[PcT,jBcPcXRATb^daRT \^eXT;Xbc7TPSTal 6a^d_7TPSTaCT\_[PcT,jBcPcXRATb^daRT \^eXT6a^d_7TPSTal 6a^d_8cT\CT\_[PcT,jBcPcXRATb^daRT Va^d_8cT\7TPSTal 8cT\CT\_[PcT,jBcPcXRATb^daRT \^eXT8cT\CT\_[PcTl+ CWT Va^d_ U^^cTa cT\_[PcT U^a Va^d_b X] cWT \PX] [Xbc +c^^[ZXc);^]V;XbcBT[TRc^a6a^d_5^^cTaCT\_[PcT+3PcPCT\_[PcT+[^RP[)2^\\P]S1dcc^] 3PcP2^]cTgc,j1X]SX]Vl 2^]cT]c,j1X]SX]V 6Tc<^aTl 2^\\P]S,jBcPcXRATb^daRT \^aT2^\\P]Sl 2^\\P]S?PaP\TcTa,j1X]SX]Vl+3PcPCT\_[PcT+c^^[ZXc);^]V;XbcBT[TRc^a6a^d_5^^cTaCT\_[PcT+c^^[ZXc);^]V;XbcBT[TRc^a+R^]ca^[b)?Xe^c8cT\4HE THIRD ?Xe^c ITEM CONTAINS A ;^]V;XbcBT[TRc^a CONTROL IN WHICH EACH SECTION IS DEFINED BY A 3PcPCT\_[PcT DIFFERENT FROM THE ONE DEFINED IN THE RESOURCES 4HIS IS BECAUSE THE INFORMATION TO SHOW IS DIFFERENT IN THIS CASE A LIST OF PEOPLE IS RETRIEVED BY USING THE ?T^_[T1h5Xabc=P\T CLASS 4HE ;^]V;XbcBT[TRc^a PROVIDES THE ITEMS SELECTION TOO )N THE CODE BEHIND THE 8!-, FILE IN THE CLASSS CONSTRUCTOR THE BT[TRcX^]2WP]VTS EVENT IS HOOKED AND THE PERSONAL DETAILS ARE SHOWN ON A DIFFERENT PAGE +R^]ca^[b)?Xe^c8cT\ 7TPSTa,QdSSXTb-
+c^^[ZXc);^]V;XbcBT[TRc^a g)=P\T,QdSSXTb 1PRZVa^d]S,CaP]b_PaT]c 8cT\bB^daRT,jBcPcXRATb^daRT QdSSXTbl+c^^[ZXc);^]V;XbcBT[TRc^a6a^d_8cT\b?P]T[+8cT\b?P]T[CT\_[PcT+c^^[ZXc)FaP_?P]T[ >aXT]cPcX^],7^aXi^]cP[+8cT\b?P]T[CT\_[PcT+c^^[ZXc);^]V;XbcBT[TRc^a6a^d_8cT\b?P]T[+c^^[ZXc);^]V;XbcBT[TRc^a6a^d_8cT\CT\_[PcT+3PcPCT\_[PcT+1^aSTa 1PRZVa^d]S,j1X]SX]V 2^]eTacTa,jBcPcXRATb^daRT Va^d_1adbWll FXScW,(( 7TXVWc,(( <PaVX],% 8b7XcCTbcEXbXQ[T,j1X]SX]V 7Pb8cT\bl+CTgc1[^RZ CTgc,j1X]SX]V :Thl 5^]c5P\X[h,jBcPcXRATb^daRT ?W^]T5^]c5P\X[hBT\X1^[Sl 5^]cBXiT,"% <PaVX],jBcPcXRATb^daRT ?W^]TC^dRWCPaVTc>eTaWP]Vl 5^aTVa^d]S,jBcPcXRATb^daRT ?W^]T5^aTVa^d]S1adbWl ETacXRP[0[XV]\T]c,1^cc^\+1^aSTa+3PcPCT\_[PcT+c^^[ZXc);^]V;XbcBT[TRc^a6a^d_8cT\CT\_[PcT+c^^[ZXc);^]V;XbcBT[TRc^a6a^d_7TPSTaCT\_[PcT+3PcPCT\_[PcT+1^aSTa 1PRZVa^d]S,CaP]b_PaT]c+1^aSTa 1PRZVa^d]S,jBcPcXRATb^daRT ?W^]T0RRT]c1adbWl FXScW,&$ 7TXVWc,&$ 7^aXi^]cP[0[XV]\T]c,;TUc+CTgc1[^RZ CTgc,j1X]SX]V :Thl 5^aTVa^d]S,jBcPcXRATb^daRT ?W^]T5^aTVa^d]S1adbWl Bch[T,jBcPcXRATb^daRT ?W^]TCTgc4gcaP;PaVTBch[Tl ETacXRP[0[XV]\T]c,1^cc^\+1^aSTa+1^aSTa+3PcPCT\_[PcT+c^^[ZXc);^]V;XbcBT[TRc^a6a^d_7TPSTaCT\_[PcT+c^^[ZXc);^]V;XbcBT[TRc^a8cT\CT\_[PcT+3PcPCT\_[PcT+6aXS <PaVX],jBcPcXRATb^daRT ?W^]TC^dRWCPaVTc>eTaWP]Vl+6aXS2^[d\]3TUX]XcX^]b+2^[d\]3TUX]XcX^] FXScW,0dc^+2^[d\]3TUX]XcX^] FXScW,+6aXS2^[d\]3TUX]XcX^]b+8\PVT FXScW, 7TXVWc, $ B^daRT,j1X]SX]V 8\PVTDa[l ETacXRP[0[XV]\T]c,C^_-
+BcPRZ?P]T[ 6aXS2^[d\], ETacXRP[0[XV]\T]c,C^_+CTgc1[^RZ CTgc,j1X]SX]V 5d[[=P\Tl Bch[T,jBcPcXRATb^daRT ?W^]TCTgc;PaVTBch[Tl 5^]c5P\X[h,jBcPcXRATb^daRT ?W^]T5^]c5P\X[hBT\X1^[Sl <PaVX], ! ! !%+CTgc1[^RZ CTgc,j1X]SX]V 4\PX[l Bch[T,jBcPcXRATb^daRT ?W^]TCTgc=^a\P[Bch[Tl CTgcFaP__X]V,FaP_ 5^]c5P\X[h,jBcPcXRATb^daRT ?W^]T5^]c5P\X[hBT\X1^[Sl+BcPRZ?P]T[ >aXT]cPcX^],7^aXi^]cP[+CTgc1[^RZ CTgc,<^QX[T) Bch[T,jBcPcXRATb^daRT ?W^]TCTgcB\P[[Bch[Tl+CTgc1[^RZ CTgc,j1X]SX]V <^QX[Tl Bch[T,jBcPcXRATb^daRT ?W^]TCTgcB\P[[Bch[Tl 5^]c5P\X[h,jBcPcXRATb^daRT ?W^]T5^]c5P\X[hBT\X1^[Sl+BcPRZ?P]T[+BcPRZ?P]T[ >aXT]cPcX^],7^aXi^]cP[+CTgc1[^RZ CTgc,7^\T) Bch[T,jBcPcXRATb^daRT ?W^]TCTgcB\P[[Bch[Tl+CTgc1[^RZ CTgc,j1X]SX]V 7^\Tl Bch[T,jBcPcXRATb^daRT ?W^]TCTgcB\P[[Bch[Tl 5^]c5P\X[h,jBcPcXRATb^daRT ?W^]T5^]c5P\X[hBT\X1^[Sl+BcPRZ?P]T[+BcPRZ?P]T[+6aXS+3PcPCT\_[PcT+c^^[ZXc);^]V;XbcBT[TRc^a8cT\CT\_[PcT+c^^[ZXc);^]V;XbcBT[TRc^a+R^]ca^[b)?Xe^c8cT\+R^]ca^[b)?Xe^c+6aXS 4HE ?TaU^a\P]RT?a^VaTbb1Pa CONTROL IS DEFINED IN THE ?TaU^a\P]RT?a^VaTbb1PaBP\_[TgP\[ FILE 4HIS IS AN ENHANCED VERSION OF THE ?a^VaTbb1Pa CONTROL BECAUSE IT USES THE COMPOSITOR THREAD )TS USAGE IS VERY SIMPLE YOU CAN SPECIFY THE ?TaU^a\P]RT?a^VaTbb1Pa TAG AS SHOWN IN THE FOLLOWING CODE +c^^[ZXc)?TaU^a\P]RT?a^VaTbb1Pa ETacXRP[0[XV]\T]c,C^_ g)=P\T,N_TaU^a\P]RT?a^VaTbb1Pa 4HIS PROGRESS BAR IS ACTIVATED BY SETTING ITS 8b8]STcTa\X]PcT PROPERTY TO cadT AND DEACTIVATED BY SETTING IT TO UP[bT )N THIS EXAMPLE THIS PROPERTY IS BOTH ACTIVATED AND DEACTIVATED BY A CHECK BOX THAT USES A 3ILVERLIGHT BINDING FEATURE )T BINDS ITS OWN 8b2WTRZTS "OOLEAN PROPERTY TO THE 8b8]STcTa\X]PcT PROPERTY SO THAT WHEN THE CHECK BOX IS SELECTED THE PROGRESS BAR APPEARS AT THE TOP OF THE SCREEN
+2WTRZ1^g 2^]cT]c,BW^f _TaU^a\P]RT _a^VaTbb QPa 8b2WTRZTS,j1X]SX]V 8b8]STcTa\X]PcT 4[T\T]c=P\T,N_TaU^a\P]RT?a^VaTbb1Pa <^ST,Cf^FPhl 4HE C^VV[TBfXcRW CONTROL IS SHOWN IN THE C^VV[TBfXcRWBP\_[TgP\[ FILE 4HIS CONTROL IS A SWITCH THAT ASSUMES TWO STATES ON AND OFF )T PROVIDES THE 7TPSTa PROPERTY USED TO SHOW TEXT ASSOCIATED WITH THE CONTROL 7HEN YOU NEED TO SHOW MORE TEXT OR OTHER CONTROLS NEAR THE SWITCH CONTROL YOU CAN DEFINE HOW THE TEMPLATE SHOULD LOOK BY USING BOTH THE 7TPSTaCT\_[PcT AND THE 2^]cT]cCT\_[PcT +BcPRZ?P]T[ g)=P\T,2^]cT]c?P]T[ 6aXSA^f, <PaVX], ! !+c^^[ZXc)C^VV[TBfXcRW 7TPSTa,FX 5X ]Tcf^aZX]V+c^^[ZXc)C^VV[TBfXcRW 7TPSTa,BTc Pdc^\PcXRP[[h+c^^[ZXc)C^VV[TBfXcRW 7TPSTa,$)#$ 0<+c^^[ZXc)C^VV[TBfXcRW7TPSTaCT\_[PcT+3PcPCT\_[PcT+2^]cT]c2^]ca^[ 5^]cBXiT,jBcPcXRATb^daRT ?W^]T5^]cBXiT;PaVTl 5^aTVa^d]S,jBcPcXRATb^daRT ?W^]T5^aTVa^d]S1adbWl 2^]cT]c,j1X]SX]Vl+3PcPCT\_[PcT+c^^[ZXc)C^VV[TBfXcRW7TPSTaCT\_[PcT+c^^[ZXc)C^VV[TBfXcRW2^]cT]cCT\_[PcT+3PcPCT\_[PcT+BcPRZ?P]T[+BcPRZ?P]T[ >aXT]cPcX^],7^aXi^]cP[+CTgc1[^RZ CTgc,0[Pa\) 5^]cBXiT,jBcPcXRATb^daRT ?W^]T5^]cBXiTB\P[[l+2^]cT]c2^]ca^[ 7^aXi^]cP[0[XV]\T]c,;TUc 5^]cBXiT,jBcPcXRATb^daRT ?W^]T5^]cBXiTB\P[[l 2^]cT]c,j1X]SX]Vl+BcPRZ?P]T[+CTgc1[^RZ CTgc,TeTah bRW^^[SPh 5^]cBXiT,jBcPcXRATb^daRT ?W^]T5^]cBXiTB\P[[l 5^aTVa^d]S,jBcPcXRATb^daRT ?W^]TBdQc[T1adbWl+BcPRZ?P]T[+3PcPCT\_[PcT+c^^[ZXc)C^VV[TBfXcRW2^]cT]cCT\_[PcT+c^^[ZXc)C^VV[TBfXcRW+BcPRZ?P]T[4HE CX[c4UUTRc CONTROL IS DEMONSTRATED IN THE CX[c4UUTRcBP\_[TgP\[ FILE !CTIVATING THE TILT EFFECT ON A PAGE IS AS EASY AS ADDING A ?W^]T0__[XRPcX^]?PVT ATTRIBUTE %VERY CONTROL THAT RESPONDS TO A TAPPING GESTURE WILL AUTOMATICALLY PROVIDE THE TILT EFFECT ANIMATION
+_W^]T)?W^]T0__[XRPcX^]?PVT g)2[Pbb,?W^]TC^^[ZXcBP\_[TBP\_[TbCX[c4UUTRcBP\_[T g\[]b,Wcc_)bRWT\Pb\XRa^b^UcR^\fX]Ug!%gP\[_aTbT]cPcX^] g\[]b)g,Wcc_)bRWT\Pb\XRa^b^UcR^\fX]Ug!%gP\[ g\[]b)_W^]T,R[a]P\Tb_PRT)<XRa^b^Uc?W^]T2^]ca^[b*PbbT\Q[h,<XRa^b^Uc?W^]T g\[]b)bWT[[,R[a]P\Tb_PRT)<XRa^b^Uc?W^]TBWT[[*PbbT\Q[h,<XRa^b^Uc?W^]T g\[]b)S,Wcc_)bRWT\Pb\XRa^b^UcR^\Tg_aTbbX^]Q[T]S!' g\[]b)\R,Wcc_)bRWT\Pb^_T]g\[U^a\Pcb^aV\PaZd_R^\_PcXQX[Xch!% g\[]b)c^^[ZXc,R[a ]P\Tb_PRT)<XRa^b^Uc?W^]T2^]ca^[b*PbbT\Q[h,<XRa^b^Uc?W^]T2^]ca^[bC^^[ZXc 5^]c5P\X[h,jBcPcXRATb^daRT ?W^]T5^]c5P\X[h=^a\P[l 5^]cBXiT,jBcPcXRATb^daRT ?W^]T5^]cBXiT=^a\P[l 5^aTVa^d]S,jBcPcXRATb^daRT ?W^]T5^aTVa^d]S1adbWl Bd__^acTS>aXT]cPcX^]b,?^acaPXc>a;P]SbRP_T >aXT]cPcX^],?^acaPXc \R)8V]^aPQ[T,S S)3TbXV]7TXVWc,&%' S)3TbXV]FXScW,#' bWT[[)BhbcT\CaPh8bEXbXQ[T,CadT c^^[ZXc)CX[c4UUTRc8bCX[c4]PQ[TS,CadT 4HE CaP]bXcX^]b EFFECTS ARE SHOWN IN THE CaP]bXcX^]bBP\_[TgP\[ FILE 4HE 3ILVERLIGHT FOR 7INDOWS 0HONE 4OOLKIT LIBRARY GIVES YOU TWO POSSIBILITIES THE TRANSITION BETWEEN PAGES DURING THE NAVIGATION AND THE TRANSITION EFFECT ON THE PAGE ITSELF )N THE CaP]bXcX^]bBP\_[TgP\[ FILE AND IN ALL THE PAGES SEEN UNTIL NOW AS WELL BETWEEN THE ?W^]T0__[XRPcX^]?PVT TAGS ARE THE =PeXVPcX^]8]CaP]bXcX^] AND =PeXVPcX^]>dcCaP]bXcX^] TAGS WHICH DEFINE THE TRANSITION EFFECTS WHEN THE PAGE IS LOADED AND BEFORE IT IS UNLOADED RESPECTIVELY +c^^[ZXc)CaP]bXcX^]BTaeXRT=PeXVPcX^]8]CaP]bXcX^]+c^^[ZXc)=PeXVPcX^]8]CaP]bXcX^]+c^^[ZXc)=PeXVPcX^]8]CaP]bXcX^]1PRZfPaS+c^^[ZXc)Cda]bcX[TCaP]bXcX^] <^ST,1PRZfPaS8]+c^^[ZXc)=PeXVPcX^]8]CaP]bXcX^]1PRZfPaS+c^^[ZXc)=PeXVPcX^]8]CaP]bXcX^]5^afPaS+c^^[ZXc)Cda]bcX[TCaP]bXcX^] <^ST,5^afPaS8]+c^^[ZXc)=PeXVPcX^]8]CaP]bXcX^]5^afPaS+c^^[ZXc)=PeXVPcX^]8]CaP]bXcX^]+c^^[ZXc)CaP]bXcX^]BTaeXRT=PeXVPcX^]8]CaP]bXcX^]+c^^[ZXc)CaP]bXcX^]BTaeXRT=PeXVPcX^]>dcCaP]bXcX^]+c^^[ZXc)=PeXVPcX^]>dcCaP]bXcX^]+c^^[ZXc)=PeXVPcX^]>dcCaP]bXcX^]1PRZfPaS+c^^[ZXc)Cda]bcX[TCaP]bXcX^] <^ST,1PRZfPaS>dc+c^^[ZXc)=PeXVPcX^]>dcCaP]bXcX^]1PRZfPaS+c^^[ZXc)=PeXVPcX^]>dcCaP]bXcX^]5^afPaS+c^^[ZXc)Cda]bcX[TCaP]bXcX^] <^ST,5^afPaS>dc+c^^[ZXc)=PeXVPcX^]>dcCaP]bXcX^]5^afPaS+c^^[ZXc)=PeXVPcX^]>dcCaP]bXcX^]+c^^[ZXc)CaP]bXcX^]BTaeXRT=PeXVPcX^]>dcCaP]bXcX^] 4HE CaP]bXcX^]bBP\_[TgP\[ FILE CONTAINS TWO BUTTONS AND TWO LIST PICKER CONTROLS /NE BUTTON STARTS THE TRANSITION EFFECT ON THE PAGE ITSELF PICKING THE TRANSITION TYPE FROM BOTH THE LIST PICKERS 4HE
OTHER BUTTON SHOWS PAGE NAVIGATION TRANSITION EFFECTS IN THE SAME WAY AS DESCRIBED EARLIER 3O LETS FOCUS ON THE FIRST BUTTON AND THE CODE BEHIND THE 2[XRZ EVENT 4HE BTT METHOD IS CALLED WHEN THE BUTTON IS CLICKED SO THAT THE SELECTED TRANSITION FROM THE FAMILY LIST PICKER IS STARTED 4HE CODE CHECKS WHETHER THE SELECTED TRANSITION TYPE OR FAMILY IS A^[[ BECAUSE THAT IS THE ONLY TRANSITION TYPE THAT DOESNT HAVE AN ASSOCIATED TRANSITION MODE 4HE A^[[ EFFECT SIMPLY ROLLS THE PAGE IN A UNIQUE WAY THERE IS NO WAY TO CHOOSE THE WAY IT ROLLS /N THE OTHER HAND THE OTHER TRANSITION FAMILIES HAVE DIFFERENT MODES 4HOSE FAMILIES ARE A^cPcT B[XST BfXeT[ AND Cda]bcX[T AND SUPPORT DIFFERENT MODES 4HEY ARE RETURNED FROM THE 4]d\2^]eTacTa CLASS THAT DEPENDING ON THE TRANSITION FAMILY RETURNS A ;Xbc COLLECTION FILLED WITH ALL THE SUPPORTED MODES $EPENDING ON THE SELECTED TRANSITION FAMILY A NEW TRANSITION OBJECT IS CREATED AND ASSOCIATED TO THE PAGE 4HE AVAILABLE CLASSES ARE A^[[CaP]bXcX^] A^cPcTCaP]bXcX^] B[XSTCaP]bXcX^] BfXeT[CaP]bXcX^] AND Cda]bcX[TCaP]bXcX^] %ACH CLASSEXCEPT THE A^[[CaP]bXcX^] CLASSACCEPTS A TRANSITION MODE AS THE CLASS CONSTRUCTORS PARAMETER &INALLY THE REFERENCE TO THE ?W^]T0__[XRPcX^]?PVT IS USED TO ASSOCIATE THE NEW TRANSITION THAT IS STARTED BY CALLING THE 1TVX] METHOD 7HEN THE TRANSITION IS COMPLETED THE 2^\_[TcTS EVENT IS RAISED AND THE Bc^_ METHOD IS CALLED _aXePcT e^XS BTT^QYTRc bT]STa A^dcTS4eT]c0aVb T j bcaX]V UP\X[h , bcaX]V5P\X[hBT[TRcTS8cT\* bcaX]V \^ST , bcaX]V<^STBT[TRcTS8cT\* CaP]bXcX^]4[T\T]c caP]bXcX^]4[T\T]c , ]d[[* XU UP\X[h4`dP[bA^[[ j caP]bXcX^]4[T\T]c , ]Tf A^[[CaP]bXcX^]* l T[bT j caP]bXcX^]4[T\T]c , CaP]bXcX^]4[T\T]cUP\X[h \^ST* l ?W^]T0__[XRPcX^]?PVT _W^]T0__[XRPcX^]?PVT , ?W^]T0__[XRPcX^]?PVT?W^]T0__[XRPcX^]5aP\T0__[XRPcX^]2daaT]cA^^cEXbdP[2^]cT]c* 8CaP]bXcX^] caP]bXcX^] , caP]bXcX^]4[T\T]c6TcCaP]bXcX^]_W^]T0__[XRPcX^]?PVT* caP]bXcX^]2^\_[TcTS , ST[TVPcT j caP]bXcX^]Bc^_* l* caP]bXcX^]1TVX]* l _dQ[XR R[Pbb 4]d\2^]eTacTa ) 8EP[dT2^]eTacTa j _dQ[XR ^QYTRc 2^]eTac^QYTRc eP[dT Ch_T cPaVTcCh_T ^QYTRc _PaP\TcTa 2d[cdaT8]U^ Rd[cdaT j bcaX]V b , eP[dT Pb bcaX]V* XU b ,, ]d[[ j aTcda] ]d[[* l bfXcRW b j
RPbT A^[[) aTcda] ]Tf ;Xbc+bcaX]V-* RPbT A^cPcT) aTcda] ]Tf ;Xbc+bcaX]Vj 8](2[^RZfXbT 8](2^d]cTaR[^RZfXbT 8] '2[^RZfXbT 8] '2^d]cTaR[^RZfXbT >dc(2[^RZfXbT >dc(2^d]cTaR[^RZfXbT >dc '2[^RZfXbT >dc '2^d]cTaR[^RZfXbT l* RPbT B[XST) aTcda] ]Tf ;Xbc+bcaX]Vj B[XSTD_5PST8] B[XSTD_5PST>dc B[XST3^f]5PST8] B[XST3^f]5PST>dc B[XST;TUc5PST8] B[XST;TUc5PST>dc B[XSTAXVWc5PST8] B[XSTAXVWc5PST>dc l* RPbT BfXeT[) aTcda] ]Tf ;Xbc+bcaX]Vj 5d[[BRaTT]8] 5d[[BRaTT]>dc 5^afPaS8] 5^afPaS>dc 1PRZfPaS8] 1PRZfPaS>dc l* RPbT Cda]bcX[T) aTcda] ]Tf ;Xbc+bcaX]Vj 5^afPaS8] 5^afPaS>dc 1PRZfPaS8] 1PRZfPaS>dc l* l aTcda] ]d[[* l l 4HE FaP_?P]T[ IS SHOWN IN THE FaP_?P]T[BP\_[TgP\[ PAGE $EPENDING ON THE >aXT]cPcX^] PROPERTY VALUE THE ITEMS ARE ALIGNED FROM LEFT TO RIGHT OR FROM TOP TO BOTTOM BREAKING THEM IN A NEW LINE WHEN THE CONTAINER EDGE IS REACHED !DDING TO YOUR PAGE IS AS EASY AS SPECIFYING THE FaP_?P]T[ TAG IN THE PAGE
+c^^[ZXc)FaP_?P]T[ g)=P\T,faP_?P]T[ >aXT]cPcX^],ETacXRP[-
5SAGE &ROM 6ISUAL 3TUDIO PRESS #TRL& AND THEN CHECK THAT THE TARGET OUTPUT IS SET TO 7INDOWS 0HONE %MULATOR 4HE APPLICATION DEPLOYS TO THE EMULATOR AND STARTS BRIEFLY SHOWING THE MAIN PAGE AS IN &IGURE
&IGURE 4HE 3ILVERLIGHT FOR 7INDOWS 0HONE 4OOLKIT OFFICIAL APPLICATION 4HE APPLICATION IS COMPOSED OF BUTTONS THAT YOU CAN SEE IF YOU DRAG UP AND DOWN THE PAGE )F YOU TAP ONE BUTTON YOU WILL NAVIGATE TO THE RELATED PAGE CONTAINING THAT CONTROL &OR EXAMPLE TO SEE THE
0dc^2^\_[TcT1^g IN ACTION TAP THE !UTO#OMPLETE"OX BUTTON AND YOU WILL BE REDIRECTED TO THE 0dc^2^\_[TcT1^gBP\_[TgP\[ PAGE SEE &IGURE
&IGURE 4HE 0dc^2^\_[TcT1^g CONTROL SHOWING BOTH ONE LINE AND TWO LINE SUGGESTIONS 9OU CAN CONTINUE BY TRYING EVERY CONTROL AND SEEING IT IN ACTION ON THE RELATED PAGE
5SING ,AUNCHERS AND #HOOSERS 0ROBLEM 9OU HAVE TO ADD INTERACTION BETWEEN YOUR APPLICATION AND EXTERNAL PHONE APPLICATIONS SUCH AS 0HONE 3EARCH AND -ARKETPLACE
3OLUTION 9OU CAN ADD INTERACTION BETWEEN YOUR APPLICATION AND YOUR PHONE APPLICATIONS BY USING LAUNCHERS AND CHOOSERS CLASSES
(OW )T 7ORKS 7INDOWS 0HONE APPLICATIONS HAVE THEIR OWN PRIVATE STORAGE AND CANNOT INTERACT WITH OTHER APPLICATIONS INSTALLED ON THE PHONE )N SOME CASES YOU NEED TO PERFORM A PARTICULAR TASK IN YOUR APPLICATION THAT REQUIRES USE OF EXISTING 7INDOWS 0HONE APPLICATIONS )N THOSE CASES YOU CAN USE BOTH LAUNCHERS AND CHOOSERS TO ADD INTERACTION WITH PARTICULAR 7INDOWS 0HONE APPLICATIONS )NDEED THERE IS NO WAY TO ADD INTERACTION BETWEEN TWO APPLICATIONS WITH LAUNCHERS AND CHOOSERS 9OU CAN ONLY INTEGRATE INTO YOUR APPLICATION COMMON TASKS SUCH AS A PHONE CALL AN E MAIL COMPOSER THE -ARKETPLACE THE PHOTO CAMERA THE WEB BROWSER AND THE SEARCH FUNCTION 4HE MAIN DIFFERENCE BETWEEN LAUNCHERS AND CHOOSERS IS THAT LAUNCHERS DONT RETURN ANY KIND OF DATA TO THE APPLICATION CALLER 4HE CHOOSERS IMPLEMENT AN ASYNCHRONOUS EVENT HANDLER THAT IS CALLED AFTER THE OPERATION IS COMPLETED RETURNING THE DATA TO THE APPLICATION CALLER !FTER HAVING USED A LAUNCHER OR A CHOOSER THE APPLICATION CALLER IS CLOSED SO ITS VERY IMPORTANT TO CORRECTLY MANAGE TOMBSTONING SEE 2ECIPE AND 2ECIPE IN #HAPTER )NDEED WHEN THE LAUNCHER OR CHOOSER HAS COMPLETED ITS OPERATIONS THE APPLICATION CALLER IS LAUNCHED AGAIN WITH THE TOMBSTONING FEATURE )N 4ABLE AND 4ABLE YOU CAN FIND THE NAMES AND DESCRIPTIONS OF EACH LAUNCHER AND CHOOSER AVAILABLE FROM THE <XRa^b^Uc?W^]TCPbZb NAMESPACE RESPECTIVELY 4ABLE LAUNCHERS !VAILABLE FROM THE 7INDOWS 0HONE 3$+
Launcher
Description
4\PX[2^\_^bTCPbZ
,AUNCHES THE E MAIL APPLICATION AND OPTIONALLY FILLS AN E MAIL FIELD SUCH AS "ODY 4O #C AND SO ON
<PaZTc_[PRT3TcPX[CPbZ
,AUNCHES THE -ARKETPLACE APPLICATION SHOWING DETAILS EITHER ON THE CURRENT APPLICATION OR THE APPLICATION SPECIFIED BY ITS IDENTIFIER
<PaZTc_[PRT7dQCPbZ
,AUNCHES THE -ARKETPLACE APPLICATION SHOWING EITHER THE !PPLICATION SECTION OR THE -USIC SECTION
Launcher
Description
<PaZTc_[PRTATeXTfCPbZ
,AUNCHES THE -ARKETPLACE APPLICATION SHOWING THE REVIEW FORM TO ADD A COMMENT TO YOUR APPLICATION
<PaZTc_[PRTBTPaRWCPbZ
,AUNCHES THE -ARKETPLACE APPLICATION SHOWING THE SEARCH FORM WITH RESULTS BASED ON THE TEXT YOU PROVIDED
,AUNCHES THE -EDIA 0LAYER APPLICATION PLAYING THE SPECIFIED MEDIA FILE
?W^]T2P[[CPbZ
,AUNCHES THE 0HONE APPLICATION SHOWING THE PHONE NUMBER AND DISPLAY NAME 4HE PHONE CALL IS NOT AUTOMATICALLY STARTED
BTPaRWCPbZ
,AUNCHES THE 3EARCH APPLICATION PERFORMING THE QUERY WITH THE PROVIDED TEXT
B\b2^\_^bTCPbZ
,AUNCHES THE -ESSAGING APPLICATION WITH A NEW 3-3 FILLED WITH PROVIDED ARGUMENTS SUCH AS THE "ODY AND 4O DATA
FTQ1a^fbTaCPbZ
,AUNCHES THE )NTERNET %XPLORER APPLICATION DISPLAYING THE PROVIDED 52,
4ABLE #HOOSERS !VAILABLE FROM THE 7INDOWS 0HONE 3$+
Chooser
Description
2P\TaP2P_cdaTCPbZ
,AUNCHES THE #AMERA APPLICATION AND IF THE USER TAKES THE PHOTO THE PHOTO IS RETURNED TO THE APPLICATION CALLER
4\PX[0SSaTbb2W^^bTaCPbZ
,AUNCHES THE #ONTACT APPLICATION ALLOWING USERS TO SELECT A CONTACT WHOSE E MAIL IS RETURNED TO THE APPLICATION CALLER
?W^]T=d\QTa2W^^bTaCPbZ
,AUNCHES THE #ONTACT APPLICATION ALLOWING USERS TO SELECT A CONTACT WHOSE PHONE NUMBER IS RETURNED TO THE APPLICATION CALLER
?W^c^2W^^bTaCPbZ
,AUNCHES THE 0HOTO 0ICKER APPLICATION ALLOWING USERS TO PICK A PHOTO FROM THE MEDIA LIBRARY
BPeT4\PX[0SSaTbbCPbZ
3AVES THE PROVIDED E MAIL ADDRESS INTO THE #ONTACT APPLICATION
BPeT?W^]T=d\QTaCPbZ
3AVES THE PHONE NUMBER INTO THE #ONTACT APPLICATION
4HE #ODE )N THIS RECIPE YOU WILL CREATE A 3ILVERLIGHT FOR 7INDOWS 0HONE APPLICATION CALLED ;Pd]RWTab0]S2W^^bTab3T\^ THAT IMPLEMENTS THE ?Xe^c CONTROL WITH TWO ITEMS LAUNCHERS AND CHOOSERS %VERY PIVOT ITEM CONTAINS A ;Xbc1^g WITH AN ITEM FOR EACH LAUNCHER AND FOR EACH CHOOSER !FTER THE USER SELECTS A LIST BOX ITEM THE APPLICATION WILL LAUNCH EITHER THE RELATED LAUNCHER OR CHOOSER )N THE
+;Xbc1^g8cT\ g)=P\T,X4\PX[0SSaTbb2W^^bTaCPbZ 2^]cT]c,4\PX[0SSaTbb2W^^bTaCPbZ 7^aXi^]cP[0[XV]\T]c,2T]cTa 7TXVWc,($ ETacXRP[0[XV]\T]c,2T]cTa +;Xbc1^g8cT\ g)=P\T,X?W^]T=d\QTa2W^^bTaCPbZ 2^]cT]c,?W^]T=d\QTa2W^^bTaCPbZ 7^aXi^]cP[0[XV]\T]c,2T]cTa 7TXVWc,($ ETacXRP[0[XV]\T]c,2T]cTa +;Xbc1^g8cT\ g)=P\T,X?W^c^2W^^bTaCPbZ 2^]cT]c,?W^c^2W^^bTaCPbZ 7^aXi^]cP[0[XV]\T]c,2T]cTa 7TXVWc,($ ETacXRP[0[XV]\T]c,2T]cTa +;Xbc1^g8cT\ g)=P\T,XBPeT4\PX[0SSaTbbCPbZ 2^]cT]c,BPeT4\PX[0SSaTbbCPbZ 7^aXi^]cP[0[XV]\T]c,2T]cTa 7TXVWc,($ ETacXRP[0[XV]\T]c,2T]cTa +;Xbc1^g8cT\ g)=P\T,XBPeT?W^]T=d\QTaCPbZ 2^]cT]c,BPeT?W^]T=d\QTaCPbZ 7^aXi^]cP[0[XV]\T]c,2T]cTa 7TXVWc,($ ETacXRP[0[XV]\T]c,2T]cTa +;Xbc1^g+R^]ca^[b)?Xe^c8cT\+R^]ca^[b)?Xe^c )N THE
4HE <PaZTc_[PRTATeXTfCPbZ CLASS PROVIDES ONLY THE BW^f METHOD BECAUSE IT OPENS THE -ARKETPLACE ALLOWING USERS TO REVIEW THE CURRENT APPLICATION 4HE <PaZTc_[PRTBTPaRWCPbZ CLASS PROVIDES THE BTPaRWCTa\b PROPERTY FOR SPECIFYING THE TEXT THAT HAS TO BE SEARCHED IN THE CONTEXT SET BY THE 2^]cT]cCh_T PROPERTY RPbT X<PaZTc_[PRT3TcPX[CPbZ) <PaZTc_[PRT3TcPX[CPbZ \Sc , ]Tf <PaZTc_[PRT3TcPX[CPbZ* \Sc2^]cT]cCh_T , <PaZTc_[PRT2^]cT]cCh_T0__[XRPcX^]b* \ScBW^f* QaTPZ* RPbT X<PaZTc_[PRT7dQCPbZ) <PaZTc_[PRT7dQCPbZ \Wc , ]Tf <PaZTc_[PRT7dQCPbZ* \Wc2^]cT]cCh_T , <PaZTc_[PRT2^]cT]cCh_T0__[XRPcX^]b* \WcBW^f* QaTPZ* RPbT X<PaZTc_[PRTATeXTfCPbZ) <PaZTc_[PRTATeXTfCPbZ \ac , ]Tf <PaZTc_[PRTATeXTfCPbZ* \acBW^f* QaTPZ* RPbT X<PaZTc_[PRTBTPaRWCPbZ) <PaZTc_[PRTBTPaRWCPbZ \bc , ]Tf <PaZTc_[PRTBTPaRWCPbZ* \bc2^]cT]cCh_T , <PaZTc_[PRT2^]cT]cCh_T
RPbT X?W^]T2P[[CPbZ) ?W^]T2P[[CPbZ _Rc , ]Tf ?W^]T2P[[CPbZ* _Rc3Xb_[Ph=P\T ,
■ .OTE %ACH LAUNCHER CLASS AND EACH CHOOSER CLASS PROVIDES THE BW^f METHOD THAT IS RESPONSIBLE FOR PERFORMING THE RELATED ACTION SUCH AS SHOWING THE WEB BROWSER OPENING THE E MAIL COMPOSER AND SO ON
)N THE OTHER BT[TRcX^]2WP]VTS EVENT HANDLER OF THE #HOOSERS LIST BOX THERE IS ANOTHER SWITCH CASE THAT IS EXECUTED BY THE CODE RELATED TO THE USERS CHOICE 4HE FIRST TWO CASES ARE JUST AN INTRODUCTION IN #HAPTER THESE TWO CHOOSERS ARE EXPLAINED MORE COMPLETELY _aXePcT e^XS BTR^]S;Xbc1^gNBT[TRcX^]2WP]VTS^QYTRc bT]STa BT[TRcX^]2WP]VTS4eT]c0aVb T j bfXcRW T0SSTS8cT\bJL Pb ;Xbc1^g8cT\=P\T j RPbT X2P\TaP2P_cdaTCPbZ)
RPbT X?W^]T=d\QTa2W^^bTaCPbZ) ?W^]T=d\QTa2W^^bTaCPbZ _]Rc , ]Tf ?W^]T=d\QTa2W^^bTaCPbZ* _]Rc2^\_[TcTS , ]Tf 4eT]c7P]S[Ta+?W^]T=d\QTaATbd[c-?W^]T=d\QTa2W^^bTaCPbZN2^\_[TcTS* _]RcBW^f* QaTPZ* e^XS ?W^]T=d\QTa2W^^bTaCPbZN2^\_[TcTS^QYTRc bT]STa ?W^]T=d\QTaATbd[c T j XU TCPbZATbd[c ,, CPbZATbd[c>:
e^XS BPeT4\PX[0SSaTbbCPbZN2^\_[TcTS^QYTRc bT]STa CPbZ4eT]c0aVb T j XU TCPbZATbd[c ,, CPbZATbd[c>:
5SAGE &ROM 6ISUAL 3TUDIO PRESS #TRL& $EPENDING ON THE TARGET OUTPUT THE APPLICATION DEPLOYS EITHER ON THE PHYSICAL DEVICE OR THE EMULATOR 4HE ;Pd]RWTab0]S2W^^bTab3T\^ APPLICATION WILL RUN BRIEFLY SHOWING THE ,AUNCHERS PIVOT ITEM WITH ITS OWN LIST BOX FILLED WITH LAUNCHERS SEE &IGURE
&IGURE 4HE ;Pd]RWTab0]S2W^^bTab3T\^ APPLICATION IN ACTION
)F YOU FLICK TO THE LEFT THE APPLICATION WILL SHOW THE SECOND PIVOT ITEM FILLED WITH ALL THE AVAILABLE CHOOSERS SEE &IGURE
&IGURE 4HE #HOOSERS PIVOT ITEM SHOWING ALL AVAILABLE CHOOSERS
.OW YOU CAN TAP A LIST BOX ITEM AND SEE THE RELATED FUNCTIONALITY &OR EXAMPLE &IGURE SHOWS THE <PaZTc_[PRTBTPaRWCPbZ LAUNCHER
&IGURE 4HE <PaZTc_[PRTBTPaRWCPbZ LAUNCHER IN ACTION
■ .OTE 4HE 4\PX[2^\_^bTCPbZ LAUNCHER CANNOT BE TESTED ON THE EMULATOR BECAUSE IT DOESNT PROVIDE AN E MAIL COMPOSER APPLICATION -OREOVER THE <PaZTc_[PRT3TcPX[CPbZ LAUNCHER DOESNT WORK IN EITHER TARGET OUTPUT UNTIL THE -ARKETPLACE ACCEPTS YOUR APPLICATION
CHAPTER ■■■
User Interface With Expression Blend 4HIS CHAPTER EXPLAINS HOW EASY IT IS TO CUSTOMIZE CONTROLS IN 3ILVERLIGHT FOR 7INDOWS 0HONE 7E ALSO WANTED TO SHOW THE USE OF SPECIAL EFFECTS BUT UNFORTUNATELY THE FACT THAT IN THE OFFICIAL RELEASE HAVENT BEEN INCLUDED REQUIRES US TO NOT INCLUDE THEM IN THIS CHAPTER "UT BEFORE STARTING WITH THE RECIPES YOU NEED TO REMEMBER SOME FUNDAMENTAL CONCEPTS SUCH AS THE IMPORTANCE OF A GOOD USER EXPERIENCE )N ADDITION IT IS ESSENTIAL FOR YOU TO FOLLOW THE USER INTERFACE GUIDELINES PROVIDED BY -ICROSOFT TO ENSURE THAT YOUR APPLICATION IS NOT REJECTED FROM THE -ARKETPLACE EVEN IF IT IS EXTREMELY FUNCTIONAL "EFORE STARTING WITH THE CUSTOMIZATION OF CONTROLS READ THE h5) $ESIGN AND )NTERACTION 'UIDE FOR 7INDOWS 0HONE v DOCUMENT PUBLISHED BY -ICROSOFT AND AVAILABLE AT Wcc_)\bS]\XRa^b^UcR^\T]db[XQaPahUU%"&$ $e,eb(!Pb_g 4HIS SITE ALSO INCLUDES A SERIES OF TEMPLATES FOR 0HOTOSHOP 4HE RECIPES IN THIS CHAPTER DESCRIBE HOW TO DO THE FOLLOWING v
#REATE A DATA TEMPLATE THAT WILL ENABLE YOUR APPLICATION TO DISPLAY WELL WITH A LIGHT OR DARK THEME
v
#HANGE THE SKIN OF YOUR APP
v
#REATE SOME COOL ANIMATION #USTOMIZE A CONTROL
'ETTING 2EADY FOR ,IGHT AND $ARK 0ROBLEM 9OU WANT YOUR APPLICATION TO DISPLAY A LIST OF ITEMS INSIDE A LIST BOX 4HIS LIST BOX NEEDS A CUSTOM LAYOUT THAT ENABLES YOU TO DISPLAY A RECTANGLE NEXT TO EACH LIST ITEM 4HE RECTANGLE WILL APPEAR WHEN THE ITEM IS SELECTED 9OU ALSO WANT TO TEST THE DISPLAY OF THE LIST BOX BY USING VARIOUS COMBINATIONS OF THEMES ALLOWED BY 7INDOWS 0HONE
3OLUTION 4O CREATE THE LAYOUT OF YOUR LIST YOU MUST CREATE AN 8cT\CT\_[PcT TEMPLATE AND AN 8cT\2^]cPX]TaCT\_[PcT 4HEN YOU MUST INTERACT WITH THE $EVICE PANEL IN %XPRESSION "LEND TO CHANGE BETWEEN VARIOUS COMBINATIONS OF THEMES
(OW )T 7ORKS 4HE DATA TEMPLATE IS A POWERFUL TOOL PUT IN THE HANDS OF DEVELOPERS AND DESIGNERS THAT PROVIDES SIGNIFICANT CONTROL OVER CUSTOMIZING 5) ELEMENTS INCLUDING FOR EXAMPLE A LIST BOX 4HESE TEMPLATES ALLOW YOU TO CREATE A CUSTOM ORGANIZATION OF 5) ELEMENTS THAT IS BASED ON THE WAY YOU WANT USERS TO VISUALIZE THE INFORMATION AND THAT ALLOWS USERS TO EASILY FIND WHAT THEY NEED "Y COMBINING THE POWER OF THE DATA TEMPLATE WITH THE $EVICE PANEL OF "LEND AT DESIGN TIME YOU CAN TRY OUT VARIOUS COMBINATIONS OF THEMES AND ACCENT COLORS TO DETERMINE WHAT THE USERS FEEDBACK WILL BE
4HE #ODE )T IS IMPORTANT THAT YOUR APPLICATION BE ABLE TO ADAPT TO THE USERS VISUAL CHOICES ) )F YOU DONT USE A COLOR SCHEME SUITED TO THE THEME CHOSEN BY THE USER YOUR APPLICATION COULD BECOME UNUSED /F COURSE SOME APPLICATIONS CAN IMPOSE A SCHEMA OF COLOR THAT DIFFERS FROM THE CHOICES OF THE USER WHILE STILL PROVIDING A GREAT USER EXPERIENCE BY ADAPTING THE NEEDS OF THE USER TO THAT GRAPHIC STYLE LOOK AT &ACEBOOK )N OTHER CASES HOWEVER YOU WONT BE ABLE TO BOAST WITH SUCH BOLDNESS AND YOULL WANT YOUR APPLICATION TO BE IN LINE WITH THE USERS CHOICES 3UPPOSE THAT ON THE MAIN PAGE YOUR APPLICATION HAS A LIST BOX 7ITHOUT HAVING ANY CUSTOMIZATION ON BRUSHES YOU USE SYSTEM COLORS 4HEN WHEN THE USER CHANGES THE THEME YOUR APPLICATION IS STILL IN LINE WITH IT 0ROBLEMS ARISE WHEN YOU DECIDE THAT YOU DONT WANT TO DESIGN AN APPLICATION SIMILAR TO OTHERS )NSTEAD YOU WANT ONE THAT REFLECTS FOR EXAMPLE THE WEB VERSION OF YOUR APPLICATION 9OU WANT TO USE YOUR COLOR SCHEME AND WOULD LIKE IT IF WE USE THE LIGHT OR DARK THEME 7ELL THE FIRST THING TO KNOW IS THAT YOU DONT NEED TO MAKE ONGOING CHANGES TO THE SETTINGS OF YOUR DEVICE OR EMULATOR "LEND ALREADY SUPPORTS AT DESIGN TIME THE CHANGE OF THEMES BY PROVIDING AN INSTANT PREVIEW 3O BEFORE WE SHOW YOU HOW TO CUSTOMIZE YOUR APPLICATION WE WILL SHOW YOU HOW TO USE THE $EVICE PANEL OF -ICROSOFT %XPRESSION "LEND SHOWN IN &IGURE BECAUSE ITS IMPORTANT TO BECOME FAMILIAR WITH THE TOOL THAT YOU WILL BE USING OVER THE COURSE OF THIS CHAPTER
&IGURE $EVICE PANEL INSIDE "LEND
"Y CLICKING ONE OF THE TWO BUTTONS HIGHLIGHTED IN &IGURE YOU CAN ROTATE THE PREVIEW IN LANDSCAPE OR PORTRAIT ORIENTATION AND THEN IMMEDIATELY TEST WHETHER THE APPLICATION IS READY FOR THE TWO DISPLAY MODES /F COURSE IF YOUR APPLICATION DOESNT NEED TO ROTATE IN THE HANDS OF THE USER THIS OPTION IS NOT FOR YOU
&IGURE /RIENTATION BUTTONS 3IMILARLY YOU CAN CHANGE THE APPEARANCE DARK OR LIGHT AND THE ACCENT COLOR MATCHING ?W^]T0RRT]c1adbW WHICH WILL ALLOW YOU TO KEEP THE DISPLAY IN LINE WITH THE hMOODv OF THE USER 4HE $EVICE PANEL ENABLES YOU TO TRY VARIOUS COMBINATIONS OF THEMES AND ACCENT COLORS AS YOU CAN SEE HIGHLIGHTED IN &IGURE (OWEVER IN ADDITION TO ENABLING YOU TO SEE WHETHER YOUR LAYOUT WORKS WITH VARIOUS ACCENT COLORS THE $ISPLAY PANEL ALSO ENABLES YOU TO MONITOR HOW THE VARIOUS BRUSHES THAT YOU HAVE DEFINED IN YOUR APPLICATION ARE COMPATIBLE WITH DARK AND LIGHT THEMES
&IGURE 4HEME SELECTION
■ .OTE *UST LIKE THE PHYSICAL DEVICE THE EMULATOR SELECTS THE DARK THEME BY DEFAULT
9OU HAVE REACHED NEARLY THE CENTRAL POINT OF THIS BOOK BUT YOU WILL ALSO CONSIDER APPLICATIONS FROM OTHER CHAPTERS ALSO LATER FOR CUSTOMIZE IT &OR THIS EXAMPLE YOU WILL USE THE FEED READER FROM #HAPTER 2ECIPE !T FIRST IT HAS SIMPLY A LIST BOX 9OU WILL EDIT THE ITEM TEMPLATE WITH "LEND RIGHT CLICK THE LIST BOX AND THEN CHOOSE %DIT !DDITIONAL 4EMPLATES ➤ %DIT 'ENERATED )TEMS ➤ %DIT ! #OPY ! SCREEN SIMILAR TO &IGURE DISPLAYS AND ASKS WHERE YOU WANT TO CREATE THE RESOURCE 7E RECOMMEND THAT YOU ALWAYS CREATE A DICTIONARY IN WHICH YOU CAN ENTER ALL THE DATA TEMPLATE AND CONTAINER STYLES 7E MAKE THIS RECOMMENDATION FOR SEVERAL REASONS &IRST IF YOU CREATE A TEMPLATE AND YOUR APPLICATION CONSISTS OF MANY PAGES YOU WILL WANT TO REUSE THE TEMPLATE FOR DATA OF THE SAME TYPE !LTHOUGH IT WOULD BE EQUALLY AVAILABLE PROFILES IN THE P__gP\[ FILE BUT IS OUR BEST PRACTICE TO LEAVE THIS AS CLEAN AS POSSIBLE BECAUSE BY USING THE 2ESOURCES PANEL IN "LEND YOU HAVE AVAILABLE ALL THE RESOURCES FROM VARIOUS DICTIONARIES MERGED INTO A SINGLE POINT 4HEN IF YOURE EDITING THE TEMPLATE YOU ALREADY KNOW WHERE TO GO TO FIND IT 7E DO NOT RECOMMEND USING THE TEMPLATE DEFINED INSIDE THE CONTROL BECAUSE IT IS MORE DIFFICULT TO SEE THE TEMPLATE WHILE YOU ARE CREATING THE APPLICATION WITHOUT SELECTING THE TEMPLATE AGAIN AND BECAUSE THIS TEMPLATE WILL NOT BE EASILY REUSABLE
&IGURE #REATING A DATA TEMPLATE 3O CREATE A NEW DICTIONARY NAMED 5TTSATPSTaCWT\TgP\[ AND CREATE A NEW TEMPLATE NAMED =Tfb8cT\CT\_[PcT )N THIS CASE WE OPTED FOR A SIMPLE TEMPLATE THAT HAS A STACK PANEL WITH A TEXT BLOCK TO SHOW THE TITLE OF THE NEWS AND A HYPERLINK BUTTON TO OPEN THE LINK TO THE NEWS IN A BROWSER 4HE 8!-, IS AS FOLLOWS
+3PcPCT\_[PcT g):Th,=Tfb8cT\CT\_[PcT+BcPRZ?P]T[+CTgc1[^RZ CTgc,j1X]SX]V CXc[Tl Bch[T,jBcPcXRATb^daRT=TfbCXc[TCTgc1[^RZBch[Tl +7h_Ta[X]Z1dcc^]7^aXi^]cP[0[XV]\T]c,;TUc 2^]cT]c,j1X]SX]V ;X]Zl 2[XRZ,7h_Ta[X]Z1dcc^]N2[XRZ+BcPRZ?P]T[+3PcPCT\_[PcT 2EFER TO #HAPTER TO LEARN MORE ABOUT THE CONCEPT OF BINDING WHICH IS EXPLAINED TOGETHER WITH PRELIMINARY INFORMATION ABOUT IMPLEMENTING THE -ODEL 6IEW 6IEW-ODEL -66- PATTERN !S YOU CAN SEE IN THE FOLLOWING CODE YOU ALSO RETRIEVE THE STYLE OF THE TEXT BLOCK THAT DISPLAYS THE TITLE AND FOR THIS WE HAVE CHOSEN A 4AHOMA "OLD POINT FONT +Bch[T g):Th,=TfbCXc[TCTgc1[^RZBch[T CPaVTcCh_T,CTgc1[^RZ+BTccTa ?a^_Tach,5^]cFTXVWc EP[dT,1^[S+BTccTa ?a^_Tach,5^]c5P\X[h EP[dT,CPW^\P +BTccTa ?a^_Tach,5^]cBXiT EP[dT, %+Bch[T !FTER DEFINING THE STYLE OF THE ELEMENTS CONTAINED IN THE LIST YOU WILL CUSTOMIZE THE ITEM#ONTAINER FOR THE SELECTION OF AN ITEM THAT APPEARS AS A RECTANGLE OUTLINE !GAIN RIGHT CLICK THE LIST BOX AND THEN CHOOSE %DIT !DDITIONAL 4EMPLATE ➤ %DIT 'ENERATED )TEM #ONTAINER ➤ %DIT ! #OPY #ALL THE STYLE =Tfb;Xbc8cT\2^]cPX]TaBch[T 4HE TEMPLATE WILL APPEAR VERY SIMPLE BUT COMPLETE ENOUGH )N "LENDS 3TATES PANEL YOU CAN SEE THE STATES THAT CURRENTLY CAN TAKE THIS CONTROL 7HAT INTERESTS US IS BT[TRcTS STATUS )F YOU SELECT IT THE INTERFACE IS PUT IN RECORDING AND THE TEXT IS DISPLAYED WITH THE COLOR THAT YOU CHOSE FOR THE ACCENT BRUSH .OW YOU GET TO PLAY WITH THE $EVICE PANEL IN "LEND )N THE 3TATES PANEL SELECT THE ELEMENT "ASE TO WHICH YOU WILL ADD A RECTANGLE WITHOUT FILL 3ET THE OUTLINE COLOR TO !CCENT #OLOR AND THEN SET THE OPACITY TO SO THAT IN ALL CASES THE RECTANGLE WILL BE TRANSPARENT 4HEN SELECT 3ELECTED STATUS BUT THIS TIME FOR WORKING MORE COMFORTABLE PRESS & TO CHANGE THE LAYOUT OF PANELS AND ENTER IN 3TORYBOARD #REATION MODALITY 3ELECT THE RECTANGLE AND IF YOU DO NOT SEE THE STORYBOARD CLICK THE 3HOW 4IMELINE BUTTON SHOWN IN &IGURE .OW YOU WANT THE RECTANGLE TO APPEAR WITH A FADING EFFECT WITH A DELAY OF SECONDS SO SELECT THE RECTANGLE AND MOVE THE PLAYHEAD ALONG THE TIMELINE UP TO MILLISECONDS AS SHOWN IN &IGURE )N THE 0ROPERTIES PANEL EDIT THE PROPERTY OPACITY TO
&IGURE 3HOW 4IMELINE BUTTON
&IGURE 4IMELINE
)N THIS WAY YOU JUST CREATED A STORYBOARD WHICH WILL RESULT IN THE FOLLOWING 8!-, +EXbdP[BcPcT+Bc^ahQ^PaS+>QYTRc0]X\PcX^]DbX]V:Th5aP\Tb Bc^ahQ^PaSCPaVTc?a^_Tach,5^aTVa^d]S Bc^ahQ^PaSCPaVTc=P\T,2^]cT]c2^]cPX]Ta+3XbRaTcT>QYTRc:Th5aP\T :ThCX\T, EP[dT,jBcPcXRATb^daRT ?W^]T0RRT]c1adbWl+>QYTRc0]X\PcX^]DbX]V:Th5aP\Tb+>QYTRc0]X\PcX^]DbX]V:Th5aP\Tb Bc^ahQ^PaSCPaVTc?a^_Tach,D84[T\T]cEXbXQX[Xch Bc^ahQ^PaSCPaVTc=P\T,aTRcP]V[T+3XbRaTcT>QYTRc:Th5aP\T :ThCX\T,+3XbRaTcT>QYTRc:Th5aP\TEP[dT+EXbXQX[Xch-EXbXQ[T+EXbXQX[Xch+3XbRaTcT>QYTRc:Th5aP\TEP[dT+3XbRaTcT>QYTRc:Th5aP\T+>QYTRc0]X\PcX^]DbX]V:Th5aP\Tb+3^dQ[T0]X\PcX^]DbX]V:Th5aP\Tb Bc^ahQ^PaSCPaVTc?a^_Tach,D84[T\T]c>_PRXch Bc^ahQ^PaSCPaVTc=P\T,aTRcP]V[T+4PbX]V3^dQ[T:Th5aP\T :ThCX\T, EP[dT,+4PbX]V3^dQ[T:Th5aP\T :ThCX\T,))$ EP[dT, +3^dQ[T0]X\PcX^]DbX]V:Th5aP\Tb+Bc^ahQ^PaS+EXbdP[BcPcT /BVIOUSLY IT IS MUCH EASIER FOR A DESIGNER TO CREATE AN ANIMATION WITH A FEW SIMPLE CLICKS THAN TO WRITE THE 8!-, 4HEREFORE EVEN THOUGH EXPLAINED STEP BY STEP IS NOT DIFFICULT BUT ONLY REQUIRES MORE TIME AND IN THE REAL WORLD WHEN YOU WORK TIME IS NEVER ENOUGH 4HE PORTION OF 8!-, STORYBOARDS THAT MOST INTERESTS US IS INCLUDED IN THE ITEM 3^dQ[T0]X\PcX^]DbX]V:Th5aP\TbWHICH CONTRARY TO WHAT IT MAY SEEM IS AN ANIMATION IN WHICH YOU DEFINE CHANGES TO PROPERTIES THAT HAVE VALUES OF TYPE 3^dQ[T Bc^ahQ^PaSCPaVTc?a^_Tach INDICATES TO THE STORYBOARD WHAT PROPERTIES OF THE ELEMENT SPECIFIED IN Bc^ahQ^PaSCPaVTc=P\T APPLY THE CHANGES KEYFRAME BY KEYFRAME )N FACT YOU SPECIFY WHICH ARE KEYFRAMES FOR US AT TIME AND AND DECLARE THAT AT TIME THE VALUE OF THE PROPERTY IS WHILE AT TIME THE VALUE IS 4HEN YOURE FINISHED BECAUSE AN ANIMATION DECLARED IN THIS WAY WITH 4PbX]V3^dQ[T:Th5aP\T WILL INCREASE WITH A LINEAR FUNCTION
5SAGE &ROM "LEND SELECT THE TARGET OF YOUR TEST IN THE $EVICE PANEL 0RESS & OR #TRL& AND WAIT FOR THE APPLICATION TO TAKE THE INFORMATION FROM THE 7EB 3ELECT AN ELEMENT AND WATCH THE RECTANGLES OPACITY INCREASE 4HEN SELECT ANOTHER AND WATCH THE UNFOCUSED ELEMENT RETURN TO NORMAL
#HANGING THE 3KIN OF 9OUR !PP 0ROBLEM 9OU WANT TO CUSTOMIZE YOUR APPLICATION WITH A DIFFERENT RESOURCE DICTIONARY DEPENDING ON WHETHER THE LIGHT OR DARK THEME IS SELECTED AND YOU WANT TEST IT WITH FAKE DATA
3OLUTION 9OU MUST CREATE DIFFERENT DICTIONARIES WITH YOUR BRUSHES 4HEN YOU SELECT ?W^]T;XVWcCWT\TEXbXQX[Xch AND APPLY THE THEME THAT YOU PREFER USING SAMPLE DATA CREATED INSIDE "LEND
(OW )T 7ORKS 4HIS RECIPE IS ACHIEVABLE IN PART ONLY WITH "LEND )N 6ISUAL 3TUDIO YOU CAN EDIT ONLY THE P__gP\[Rb CODE AND THEN FROM ONE OF THE TWO INSTRUMENTS YOU CREATE A NEW PROJECT FOR 7INDOWS 0HONE IN "LEND AS YOU CAN SEE IN &IGURE /NCE YOU HAVE CREATED THE PROJECT ADD A FOLDER NAMED BZX]b AND ADD TO THIS FOLDER TWO DICTIONARIES 3PaZCWT\TgP\[ AND ;XVWcCWT\TgP\[ .EXT EDIT THE P__G0<; FILE WHICH YOU WILL BE AUTOMATICALLY LINKED TO THE DICTIONARY TAKING CARE OF COMMENT UNDERLINED TWO LINES REPRESENTING THE THEMES TO BE APPLIED UNFORTUNATELY NOT AT DESIGN TIME BUT AT RUNTIME )F YOU ALSO HAVE SETTINGS THAT ARE SHARED BY BOTH THEMES YOU COULD ADD A RESOURCE DICTIONARY THAT CONTAINS THE SHARED KEYS +ATb^daRT3XRcX^]Pah
&IGURE #REATING A NEW PROJECT IN %XPRESSION "LEND !T THIS POINT YOU USE "LENDS $ATA PANEL WHICH ENABLES YOU TO MANAGE YOUR APPLICATION DATA SOURCES AND TO GENERATE SAMPLE DATA TO TEST YOUR PAGES !NOTHER VERY NICE FEATURE OFFERED BY THIS PANEL IS THE CREATION OF DATA REPRESENTATION FROM DATA &OLLOW ALONG STEP BY STEP #LICK THE BUTTON TO DISPLAYS THE MENU IN &IGURE &ROM THIS MENU SELECT .EW 3AMPLE $ATA ! DIALOG BOX APPEARS WHERE YOU CAN CHOOSE THE DATA SOURCES NAME THE POINT AT WHICH TO DEFINE THE SCOPE AND THE DATA SOURCES VISIBILITY #ALL THE DATA SOURCE BP\_[T3PcPB^daRT )F YOU ARE USING A DOMAIN ORIENTED APPROACH CONSIDER CREATING THE DATA SOURCE AT THE PROJECT LEVEL SO THAT YOU CAN REUSE IT IN ANOTHER VIEW !ND BECAUSE THIS IS AN APPLICATION THAT IS SIMPLY ALLOWING TO TAKE INTO CONSIDERATION THESE FEATURES OFFERED BY "LEND ENABLE THE SAMPLE DATA AT RUNTIME
&IGURE $ATA PANEL INSIDE "LEND !T THIS POINT THE BASE TEMPLATE HAS GENERATED A DATA SOURCE CALLED BP\_[T3PcPB^daRT WHICH THROUGH THE TEMPLATE HIERARCHY THAT YOU SEE IN &IGURE WILL HAVE A COMPLEX TYPE CALLED BP\_[T3PcPB^daRT 7ITHIN THE COMPLEX TYPE YOU CAN FIND A COLLECTION OF OBJECTS COMPOSED OF TWO PROPERTIES CALLED ?a^_Tach AND ?a^_Tach! WHICH WILL BE THE ONES THAT ARE GOING TO CHANGE 4O SIMULATE AN APPLICATION DOMAIN THINK OF YOUR APPLICATION AS AN ORGANIZER THAT LETS YOU KEEP TRACK OF YOUR MONEY 2ENAME THE TWO PROPERTIES AUTOMATICALLY GENERATED BY THE TOOL AS ATPb^] AND <^]Th AND ADD ANOTHER BY CLICKING THE PLUS SYMBOL NEXT TO COLLECTION AND NAMING IT 3PcT !T THIS POINT BY CLICKING THE %DIT 3AMPLE 6ALUE BUTTON YOU CAN EDIT THE VALUES THAT THE PROPERTIES MUST TAKE &OR 3PcT YOU DEFINE A TYPE BcaX]V ➤ 3PcT REMEMBER THAT 7INDOWS 0HONE DOESNT HAVE BcaX]V5^a\Pc IN BINDING &OR <^]Th YOU DEFINE A TYPE BcaX]V ➤ ?aXRT AND FOR ATPb^] YOU USE BcaX]V ➤ [^aT\X_bd\ &ROM THIS SCREEN YOU CAN SPECIFY THE NUMBER OF ITEMS THAT MUST BE CONTAINED IN YOUR COLLECTION 4O HAVE A GOOD AMOUNT OF DATA WE HAVE CHOSEN !SSUMING THAT IT WAS UP TO THE DEVELOPER TO CREATE THE SAMPLE DATA SOURCE ITS NOW UP TO THE DESIGNER TO CREATE A VIEW TEMPLATE )T IS TRUE THAT OFTEN THESE TWO JOB TITLES MERGE INTO ONE PERSON BUT ITS ALWAYS NICE TO TALK OF AN IDEAL WORLD !ND ASSUMING THAT IF YOU ARE READING THIS CHAPTER YOU ARE THE DESIGNER IN THIS CASE WE INFORM THAT THIS FIGURE WORKS A LOT OF INVENTIVENESS AND NONCODE TOOL
)N FACT YOU CAN JUST DRAG THE COLLECTION CONTAINED IN THE DATA SOURCE ON THE PAGE WHERE YOU WANT IT TO DISPLAY THE LIST TO CREATE A LIST BOX WITH ALREADY AN 8cT\CT\_[PcT 5NFORTUNATELY THE BASIC TEMPLATE IS NOT AS APPEALING AS A DESIGNER MIGHT HOPE BUT IT STILL SAVES A BIT OF WORK +3PcPCT\_[PcT g):Th,8cT\CT\_[PcT+BcPRZ?P]T[+CTgc1[^RZ CTgc,j1X]SX]V 3PcTl+CTgc1[^RZ CTgc,j1X]SX]V <^]Thl+CTgc1[^RZ CTgc,j1X]SX]V ATPb^]l+BcPRZ?P]T[+3PcPCT\_[PcT 3TARTING FROM THIS TEMPLATE YOU WANT TO GET A TABLE DESIGN AND THEN YOU WILL DELETE THE BcPRZ?P]T[ TO GET A 6aXS TO DEFINE COLUMNS FROM PIXELS ABOVE THE LIST BOX YOU WILL CREATE ANOTHER 6aXS WITH THE SAME COLUMNS TO MAKE THE HEADER OF THE GRID 4HEN THE 8!-, FOR YOUR TEMPLATE MUST BE SIMILAR TO THIS +3PcPCT\_[PcT g):Th,8cT\CT\_[PcT+6aXS+6aXS2^[d\]3TUX]XcX^]b+2^[d\]3TUX]XcX^] FXScW, '! +2^[d\]3TUX]XcX^] FXScW,&% +2^[d\]3TUX]XcX^] FXScW,! +6aXS2^[d\]3TUX]XcX^]b+CTgc1[^RZ CTgc,j1X]SX]V 3PcTl +CTgc1[^RZ CTgc,j1X]SX]V <^]Thl 6aXS2^[d\], +CTgc1[^RZ CTgc,j1X]SX]V ATPb^]l 6aXS2^[d\],! +6aXS+3PcPCT\_[PcT-
■ .OTE &OR MORE INFORMATION ABOUT DATA BINDING LOOK AT #HAPTER
!T THIS POINT THE INFORMATION IS DISPLAYED IN WHITE ON BLACK AND VICE VERSA DEPENDING ON THE THEME #REATE YOUR THEME AND TRY IT TO SEE IF YOU LIKE THE RESULT 4HE WISEST CHOICE IS TO UNCOMMENT THE CHOSEN THEME AND USE THE $EVICE PANEL TO CHANGE THE THEME OF YOUR PHONE 3O FIRST YOU DEFINE WITHIN THE DARK THEME THE FOLLOWING BRUSHES +B^[XS2^[^a1adbW g):Th,3PcT1adbW 2^[^a,55555555 +B^[XS2^[^a1adbW g):Th,ATPb^]1adbW 2^[^a,511414 +B^[XS2^[^a1adbW g):Th,<^]Th1adbW 2^[^a,5555
)N THE LIGHT THEME THE BRUSHES ARE DEFINED THE SAME WAY BUT WITH DIFFERENT COLORS +B^[XS2^[^a1adbW g):Th,3PcT1adbW 2^[^a,55 %55( +B^[XS2^[^a1adbW g):Th,ATPb^]1adbW 2^[^a,514&&01 +B^[XS2^[^a1adbW g):Th,<^]Th1adbW 2^[^a,550( 9OU NOW HAVE TWO THEMES AND YOU HAVE TESTED THEM IN VARIOUS COMBINATIONS FOR THE PHONE 4HE LAST THING TO DO IS APPLY THEM AT RUNTIME 5NLIKE EVERYTHING YOUVE DONE SO FAR THIS TASK MUST BE DONE BY HAND WITH CODE AT RUNTIME BECAUSE ONLY AT THIS TIME CAN YOU KNOW WHICH THEME HAS BEEN CHOSEN BY THE USER 7ITHIN THE 0__gP\[Rb FILE CREATE A PRIVATE METHOD THAT HAS THE SCOPE TO APPLY THE THEME AND CALL IT WITH EXTREME IMAGINATION 0__[hCWT\T 4HIS METHOD SHOULD BE INVOKED TO RAISE EITHER OF THE EVENTS ;Pd]RWX]V OR 0RcXePcTS FOR THE SIMPLE REASON THAT IN CASE YOUR APPLICATION HAS BEEN SIMPLY REACTIVATED FOLLOWING A TOMBSTONING YOU MUST BE READY TO ACKNOWLEDGE ANY CHANGE IN THEME SETTINGS MADE BY THE USER IN THE MEANTIME _aXePcT e^XS 0__[XRPcX^]N;Pd]RWX]V^QYTRc bT]STa ;Pd]RWX]V4eT]c0aVb T j 0__[hCWT\T* l _aXePcT e^XS 0__[XRPcX^]N0RcXePcTS^QYTRc bT]STa 0RcXePcTS4eT]c0aVb T j 0__[hCWT\T* l _aXePcT e^XS 0__[hCWT\T j EXbXQX[Xch eXb , EXbXQX[Xch0__[XRPcX^]2daaT]cATb^daRTbJ?W^]T;XVWcCWT\TEXbXQX[XchL* ATb^daRT3XRcX^]Pah SXRc , ]Tf ATb^daRT3XRcX^]Pah* SXRcB^daRT , ]Tf DaXeXb ,, BhbcT\FX]S^fbEXbXQX[XchEXbXQ[T . BZX]b;XVWcCWT\TgP\[ ) BZX]b3PaZCWT\TgP\[ DaX:X]SAT[PcXeT* 0__[XRPcX^]2daaT]cATb^daRTb
5SAGE 9OU CAN RUN THE PROJECT FROM "LEND OR 6ISUAL 3TUDIO BY PRESSING & ,OOK FOR THE INFORMATION DISPLAYED ACCORDING TO THE COLOR SCHEME YOUVE CHOSEN WITH RESPECT TO THE MOOD OF THE USER .OW GO BACK TO THE START PAGE PRESSING THE WINDOWS BUTTON %NTER THE SETTINGS AND CHANGE THE THEME TO LIGHT OR DARK DEPENDING ON WHAT YOU HAD BEFORE 'O BACK INTO YOUR APPLICATION AND VIEW IT IN THE THEME WITH THE MOOD CHOSEN BUT WITH THE COLORS CHANGED FOR BETTER DISPLAY
#REATING 3OME #OOL !NIMATION 0ROBLEM 9OU WANT TO ADD ANIMATIONS TO YOUR APPLICATION TO MAKE THE INTERACTION WITH THE USER MORE INTERESTING
3OLUTION 9OU WILL CONSIDER THE IDEA OF CREATING STORYBOARD BASED ANIMATIONS AND BIND THEM TO THE VARIOUS STATES OF YOUR CONTROLS
(OW )T 7ORKS 9OU WILL MODIFY &3ad\ OUR PILOT PROJECT AND CHANGE THE THREE TEXT BLOCKS INTO THREE BUTTONS 9OU WILL ADD A DIFFERENT EFFECT TO EACH BUTTON BY CREATING A TEMPLATE FOR EACH AND APPLYING TRANSFORMATIONS TO THE ELEMENTS THAT MAKE UP THE TEMPLATE 4HE INTERFACE WILL THEN BECOME ANIMATED OFFERING THE USER A MORE INTERACTIVE EXPERIENCE
4HE #ODE /PEN THE &3ad\ PROJECT FROM "LEND AND OPEN THE MAIN PAGE ,ETS START WITH THE COMMENT ON THE THREE TEXT BLOCKS + +CTgc1[^RZ g)=P\T,cQATR^aS6a^^eT CTgc,CPZT h^da Va^^eT Bch[T,jBcPcXRATb^daRT ?W^]TCTgc4gcaP;PaVTBch[Tl
4HEN ADD THE THREE BUTTONS +1dcc^] g)=P\T,ATR^aS6a^^eT1dcc^] 2^]cT]c,CPZT h^da Va^^eT +1dcc^] g)=P\T,CaPX]X]V1dcc^] 2^]cT]c,CaPX]X]V +1dcc^] g)=P\T,
&IGURE 4RANSFORM SECTION INSIDE THE 0ROPERTIES PANEL .OW YOUR FIRST ANIMATION OF THE BUTTON IS READY AND YOU CAN MOVE ON TO THE NEXT ANIMATION )N THIS CASE YOU WANT THE BUTTON AREA TO BECOME SMALLER AND WILL BE ONLY A RECTANGLE THAT WIDENS AND NARROWS TO DO ANIMATION !S BEFORE YOUR FIRST TASK IS TO EDIT A COPY OF THE BUTTONS CURRENT TEMPLATE PLACING IT IN THE RESOURCE DICTIONARY THAT YOU CREATED EARLIER #ALL THE TEMPLATE CaPX]X]V1dcc^]CT\_[PcT 5NLIKE BEFORE THIS TIME YOU WILL GO DEEPER INTO THE STUDY OF WHY YOU NEED TO MODIFY THE TEMPLATE BY ADDING A ATRcP]V[T THAT WILL CREATE THE BUTTON ANIMATION THAT YOU DESIRE 4HE TEMPLATE CONSISTS OF A MAIN 6aXS CONTROL +2^]ca^[CT\_[PcTCPaVTcCh_T,1dcc^]+6aXS 1PRZVa^d]S,CaP]b_PaT]c )NSIDE OF IS SET THE VALUE OF THE ATTACHED PROPERTY EXbdP[BcPcT
3ELECT FROM THE 3TATES PANEL THE ?aTbbTS STATE AND SELECT 1dcc^]1PRZVa^d]S THAT YOU WANT TO REMAIN SMALLER FOR ALL THE TIME OF THE PRESSURE -OVE THE PLAYHEAD ALONG THE TIMELINE TO SECONDS IF YOU HAVE DIFFICULTY DOING SO YOU NEED TO DISABLE SNAPPING TO THE TIMELINE AS YOU DID WITH THE PREVIOUS BUTTON SIZE CLIMBING UP TO BUT IN THIS CASE YOU DO NOT WANT YOUR STORYBOARD TO BE PERFORMED CYCLICALLY SO YOU WILL NOT DEFINE AT_TPc1TWPeX^a AND YOU DONT WANT TO RUN BACK SO YOU WILL NOT DEFINE THE AUTOREVERSE WHICH BY DEFAULT IS SET TO UP[bT 3O FOR THIS ANIMATION YOU HAVE THIS 8!-, +3^dQ[T0]X\PcX^]DbX]V:Th5aP\Tb Bc^ahQ^PaSCPaVTc?a^_Tach,D84[T\T]cAT]STaCaP]bU^a\2^\_^bXcTCaP]bU^a\BRP[TG Bc^ahQ^PaSCPaVTc=P\T,1dcc^]1PRZVa^d]S+4PbX]V3^dQ[T:Th5aP\T :ThCX\T, EP[dT, +4PbX]V3^dQ[T:Th5aP\T :ThCX\T,))# EP[dT,'+3^dQ[T0]X\PcX^]DbX]V:Th5aP\Tb+3^dQ[T0]X\PcX^]DbX]V:Th5aP\Tb Bc^ahQ^PaSCPaVTc?a^_Tach,D84[T\T]cAT]STaCaP]bU^a\2^\_^bXcTCaP]bU^a\BRP[TH Bc^ahQ^PaSCPaVTc=P\T,1dcc^]1PRZVa^d]S+4PbX]V3^dQ[T:Th5aP\T :ThCX\T, EP[dT, +4PbX]V3^dQ[T:Th5aP\T :ThCX\T,))# EP[dT,'+3^dQ[T0]X\PcX^]DbX]V:Th5aP\Tb.OW YOU JUST HAVE TO ANIMATE THE RECTANGLE THAT YOU ADDED EARLIER 4HEREFORE ALWAYS REMAINING WITHIN THE EDITING OF THE ?aTbbTS STATE SELECT THE RECTANGLE AND MOVE THE PLAYHEAD TO THE BEGINNING OF THE TIMELINE IF IT ISNT THERE ALREADY 9OU CREATE A KEYFRAME AND THEN MOVING ALONG THE TIMELINE AT THE LEVEL OF SECONDS SCALE THE RECTANGLE TO FOR BOTH THE X AND Y AXIS )N THIS CASE HOWEVER YOU DEFINE AN INFINITE LOOP AND SET 0dc^aTeTabT TO cadT SO THAT THE ANIMATION WILL EXPAND AND SHRINK THE RECTANGLE CONTINUOUSLY UNTIL THE FINGER IS ON THE BUTTON 9OUR 8-, SHOULD LOOK LIKE THIS +3^dQ[T0]X\PcX^]DbX]V:Th5aP\Tb 0dc^ATeTabT,CadT AT_TPc1TWPeX^a,5^aTeTa Bc^ahQ^PaSCPaVTc?a^_Tach,D84[T\T]cAT]STaCaP]bU^a\2^\_^bXcTCaP]bU^a\BRP[TG Bc^ahQ^PaSCPaVTc=P\T,aTRcP]V[T+4PbX]V3^dQ[T:Th5aP\T :ThCX\T, EP[dT, +4PbX]V3^dQ[T:Th5aP\T :ThCX\T,))! EP[dT,'+3^dQ[T0]X\PcX^]DbX]V:Th5aP\Tb+3^dQ[T0]X\PcX^]DbX]V:Th5aP\Tb 0dc^ATeTabT,CadT AT_TPc1TWPeX^a,5^aTeTa Bc^ahQ^PaSCPaVTc?a^_Tach,D84[T\T]cAT]STaCaP]bU^a\2^\_^bXcTCaP]bU^a\BRP[TH Bc^ahQ^PaSCPaVTc=P\T,aTRcP]V[T+4PbX]V3^dQ[T:Th5aP\T :ThCX\T, EP[dT, +4PbX]V3^dQ[T:Th5aP\T :ThCX\T,))! EP[dT,'+3^dQ[T0]X\PcX^]DbX]V:Th5aP\Tb)TS TIME TO ANIMATE THE LAST BUTTON 4HIS TIME THE ANIMATION WILL BE A BIT MORE $ !S THE USER PRESSES THE BUTTON IT WILL FLIP ALONG THE Y AXIS !S WITH THE OTHER BUTTONS YOU HAVE TO EDIT THE TEMPLATE IN THE USUAL WAY SO RIGHT CLICK THE BUTTON AND EDIT THE TEMPLATE AS
)N THE 0ROPERTIES PANEL UNDER THE TRANSFORSECTION YOU HAVE OTHER KINDS OF TRANSFORMATIONS TO APPLY TO OBJECTS INCLUDING PROJECTION THAT IS THE ARRANGEMENT OF CONTROL ALONG THE X Y AND Z AXIS !T INSTANT YOU SET THE 9 VALUE OF THE ?a^YTRcX^] PROPERTY TO 4HEN IN THE INSTANT YOU SET IT TO n &INALLY AT INSTANT YOU RESET IT TO )N THIS WAY THERE IS PERPETUAL MOVEMENT AND ADJUSTMENTS OVER TIME 9OU ALSO HAVE TO SET AT_TPc1TWPeX^a TO 5^aTeTa FOR THIS ANIMATION TO BE READY 4HE 8!-, RESULTING FROM THESE STEPS IS AS FOLLOWS +3^dQ[T0]X\PcX^]DbX]V:Th5aP\Tb AT_TPc1TWPeX^a,5^aTeTa Bc^ahQ^PaSCPaVTc?a^_Tach,D84[T\T]c?a^YTRcX^]?[P]T?a^YTRcX^]A^cPcX^]H Bc^ahQ^PaSCPaVTc=P\T,1dcc^]1PRZVa^d]S+4PbX]V3^dQ[T:Th5aP\T :ThCX\T, EP[dT,+4PbX]V3^dQ[T:Th5aP\T :ThCX\T,)) EP[dT, '+4PbX]V3^dQ[T:Th5aP\T :ThCX\T,))" EP[dT, '+4PbX]V3^dQ[T:Th5aP\T :ThCX\T,))# EP[dT,+3^dQ[T0]X\PcX^]DbX]V:Th5aP\Tb4HIS ANIMATION PRESENTS A LOT TO CONSIDER INCLUDING THE FACT THAT IT DEVELOPS WITH REGULAR INTERVALS JUST LIKE A METRONOME )N THIS WAY THE ANIMATION DRAWS THE USERS ATTENTION TO WHAT AWAITS VIA CLICKING THAT BUTTON 4HE ANIMATION ITSELF GROWS IN A SHORT TIME ENABLING THE USER TO RETRIEVE A VISUAL BENEFIT 4HERE IS ALSO TO SAY THAT AN ANIMATION TOO LONG ON A CONTROL THAT SHOULD JUST MANAGE THE 4!0 DOES NOT MAKE SENSE .OW YOU HAVE TO PERFORM THE DEVELOPERS TASK AND CREATE THE EVENT HANDLER TO MANAGE THE 2[XRZ EVENT OF ALL THREE BUTTONS SO THEY DO WHAT THEY WERE DOING BEFORE THE TEXT BLOCKS % I TRE EVENTHANDLER SARANNO TUTTI UGUALI _aXePcT e^XS ATR^aS6a^^eT1dcc^]N2[XRZ^QYTRc bT]STa BhbcT\FX]S^fbA^dcTS4eT]c0aVb T j cWXb=PeXVPcX^]BTaeXRT=PeXVPcT]Tf DaXEXacdP[3ad\gP\[ DaX:X]SAT[PcXeT* l _aXePcT e^XS CaPX]X]V1dcc^]N2[XRZ^QYTRc bT]STa A^dcTS4eT]c0aVb T j cWXb=PeXVPcX^]BTaeXRT=PeXVPcT]Tf DaXCaPX]X]VgP\[ DaX:X]SAT[PcXeT* l _aXePcT e^XS
5SAGE &ROM %XPRESSION "LEND RUN THE PROJECT BY PRESSING & OR #TRL& #LICK ALL THREE BUTTONS TO TEST THAT ALL THE ANIMATIONS WORK AND RELATIVE EVENT HANDLER
#USTOMIZING A #ONTROL 0ROBLEM 9OU WOULD LIKE TO HAVE A CUSTOMIZED BUTTON THAT SHOWS AN IMAGE INSTEAD OF THE USUAL WRITTEN TEXT
3OLUTION 9OU HAVE SEVERAL SOLUTIONS TO THIS PROBLEM EACH WITH ITS PROS AND CONS AND WE WILL BE LISTING THEM ALL BROUGHT THEN A DEFINITIVE TEMPLATE THAT REFLECTS WHAT WE WANT FROM THIS CUSTOMIZATION
(OW )T 7ORKS 7ITH 8!-, YOU HAVE THE ABILITY TO CREATE MULTIPLE CONTROLS TOGETHERSO FOR EXAMPLE ITEMS IN A LIST BOX CAN BE A SERIES OF CHECK BOXES 9OU CAN ALSO USE 8!-, TO SET THE CONTENTS OF A BUTTON TO BE NOT TEXT BUT AN IMAGE &INALLY YOU CAN CUSTOMIZE THE BEHAVIOR OF A CHECK BOX SO THAT IT HAS A DIFFERENT SYMBOL THAN THE STANDARD BY EDITING THE TEMPLATE TO MODIFY THE PATH REPRESENTING THE USUAL CHECK MARK
4HE #ODE &ROM %XPRESSION "LEND CREATE A NEW PROJECT FOR 7INDOWS 0HONE AND CALL IT ?[PhFXcW2^]ca^[CT\_[PcT $O NOT CREATE A PILOT PROJECT FOR THIS RECIPE BECAUSE YOU COULD USE THIS INFORMATION IN ALL YOUR APPLICATIONS AND CONSEQUENTLY BRING YOUR TEMPLATE AROUND YOUR PRODUCTS 3UPPOSE THAT YOU HAVE CREATED A SUITE OF PRODUCTS TO WHICH YOU HAVE GIVEN YOUR FOOTPRINT GRAPHIC AND YOU WANT THESE ARE ALWAYS ON THE SAME LINE FOR EACH PRODUCT TO LET THE USER EASILY SETTLE WITH YOUR OTHER SOFTWARE )N THIS PROJECT THE FIRST THING YOU DO IS ADD AN 8\PVTb FOLDER AND ADD AN IMAGE NAMED CTbc8\PVT_]V ,OOK AT THIS LINK IF YOU WANT SOME INFORMATION ABOUT THIS IMAGE FORMAT fff[XQ_]V^aV_dQ_]V _]VX]ca^Wc\[ )N THIS EXAMPLE THE IMAGE IS THE ONE SHOWN IN &IGURE BUT YOU ARE FREE TO CHOOSE ANOTHER
&IGURE /UR ICON 4HE FIRST THING YOU WANT TO GET IS AN IMAGE THAT WORKS JUST LIKE A BUTTON 4HERE ARE SEVERAL WAYS TO ACHIEVE THIS GOAL BUT THE EASIEST IS TO USE AN IMAGE INSTEAD OF TEXT AS THE CONTENT OF THE BUTTON (ERE IS AN EXAMPLE +1dcc^] g)=P\T,8\PVT1dcc^] 7TXVWc,'# +8\PVT B^daRT,8\PVTbCTbc8\PVT_]V +1dcc^]-
4HIS CODE CREATES A BUTTON SHOWN IN &IGURE WHICH IS APPARENTLY ALREADY A BUTTON THAT IS ACCEPTABLE BUT LACKS SOME SPECIALTIES FOR EXAMPLE HAS KEPT THE EDGE TO THE CONTENT THEN WE HAVE TO EDIT THE TEMPLATE OF THE BUTTON TO REMOVE THE "OARD AND ADD OUR BUTTON SOME SMALL EFFECT TO MAKE IT COMPLETE 4HEN AS ALWAYS RIGHT CLICK THE BUTTON AND EDIT THE TEMPLATE CALLING IT 8\PVT1dcc^]CT\_[PcT &IRST YOU NEED TO LOCATE 1dcc^]1PRZVa^d]S WHICH CURRENTLY IS AN ELEMENT OF TYPE 1^aSTa 9OU WANT TO DELETE IT OR REPLACE IT WITH A COMMON 6aXS WHOSE 1PRZVa^d]S REMAINS BOUND TO THE TEMPLATE 4HEN THIS 6aXS WILL ADD A RECTANGLE THAT YOU WILL CALL >eTa[PhATRcP]V[T AND WILL FILL WITH BLACK SO THAT ITS OPACITY IS NOT VISIBLE INITIALLY
&IGURE !N IMAGE AS CONTENT 4HE ADDITION OF THIS RECTANGLE TO AFFORD WHEN THE BUTTON IS DISABLED SHOWING AN OVERLAY ON THE IMAGE OR ANY OTHER CUSTOM CONTENT 4HEN THE 8!-, THAT YOU NEED TO USE IS SIMILAR TO THE FOLLOWING +6aXSg)=P\T,1dcc^]1PRZVa^d]S1PRZVa^d]S,jCT\_[PcT1X]SX]V 1PRZVa^d]Sl <PaVX],jBcPcXRATb^daRT ?W^]TC^dRWCPaVTc>eTaWP]Vl+2^]cT]c2^]ca^[ g)=P\T,2^]cT]c2^]cPX]Ta 2^]cT]cCT\_[PcT,jCT\_[PcT1X]SX]V 2^]cT]cCT\_[PcTl 2^]cT]c,jCT\_[PcT1X]SX]V 2^]cT]cl 5^aTVa^d]S,jCT\_[PcT1X]SX]V 5^aTVa^d]Sl 7^aXi^]cP[2^]cT]c0[XV]\T]c,jCT\_[PcT1X]SX]V 7^aXi^]cP[2^]cT]c0[XV]\T]cl ?PSSX]V,jCT\_[PcT1X]SX]V ?PSSX]Vl ETacXRP[2^]cT]c0[XV]\T]c,jCT\_[PcT1X]SX]V ETacXRP[2^]cT]c0[XV]\T]cl+ATRcP]V[T g)=P\T,>eTa[PhATRcP]V[T 5X[[,1 EXbXQX[Xch,2^[[P_bTS +6aXS.OW YOU HAVE TO EDIT THE STATUSES DISABLED AND PRESSED 4HIS STEP WOULD BE AVOIDABLE IF YOU DONT REMOVE THE 1^aSTa BUT AS YOU CHANGE IT WITH THE 6aXS REMEMBER THAT IF YOU DO IT WILL RESULT IN AN ERROR IN THE STORYBOARD BECAUSE UNLIKE THE 6aXS DOES NOT HAVE A BORDER ATTRIBUTE AS 1^aSTa1adbW 4O COMPLETE THIS CUSTOM CONTROL PRESS & TO TOGGLE TO STORYBOARD MODE AND SELECT THE ?aTbbTS STATE AND THEN THE GRID CHANGING THE BACKGROUND TO jBcPcXRATb^daRT?W^]T5^aTVa^d]S1adbWl *UST AS BEFORE THE BUTTON WILL CHANGE COLOR FROM BLACK TO WHITE AND VICE VERSA DEPENDING ON THE VISUAL THEME CHOSEN BY THE USER WHICH SHOULD ALWAYS BE TAKEN INTO ACCOUNT 4HE 8!-, FOR THIS EFFECT SHOULD BE SIMILAR TO THIS +EXbdP[BcPcT g)=P\T,?aTbbTS+Bc^ahQ^PaS+>QYTRc0]X\PcX^]DbX]V:Th5aP\Tb Bc^ahQ^PaSCPaVTc=P\T,1dcc^]1PRZVa^d]S+3XbRaTcT>QYTRc:Th5aP\T ?W^]T5^aTVa^d]S1adbWl+>QYTRc0]X\PcX^]DbX]V:Th5aP\Tb+Bc^ahQ^PaS+EXbdP[BcPcT-
Bc^ahQ^PaSCPaVTc?a^_Tach,1PRZVa^d]S :ThCX\T, EP[dT,jBcPcXRATb^daRT
9OU ARE CHANGING THE FOREGROUND COLOR BECAUSE YOU ARE THINKING OF ABSTRACTING THIS TEMPLATE COMPARED TO CONTENTS CONTRARY TO WHAT IS CHOSEN FOR THE NAMING CONVENTION OF THE TEMPLATES SO THAT IF YOU APPLY THIS STYLE TO A BUTTON WITH TEXT AS ITS CONTENT YOU WOULD GET THE SAME RESULT A REVERSAL OF THE BACKGROUND AND FOREGROUND COLOR 4HE AIM IS ALWAYS THE SAME TO HAVE CONSISTENT BEHAVIOR BETWEEN THE VARIOUS ELEMENTS THAT MAKE UP THE USER INTERFACE SO THAT THEY ARE PART OF ONE BIG PICTURE 7ELL YOU JUST HAVE TO MANAGE THE 3XbPQ[TS STATE OF YOUR TEMPLATES SO THAT THE RECTANGLE FORMING THE OVERLAY TO SHOW INERT OUR ELEMENTS TO CHANGE THEIR VISIBILITY IN VISIBLE THEN ONCE AGAIN SELECT THE ELEMENT AND CHANGE THE VISIBILITY INTO PROPERTY IN ORDER TO OBTAIN AUTOMATICALLY THE 8!-, LIKE THIS +EXbdP[BcPcT g)=P\T,3XbPQ[TS+Bc^ahQ^PaS+>QYTRc0]X\PcX^]DbX]V:Th5aP\Tb Bc^ahQ^PaSCPaVTc?a^_Tach,D84[T\T]cEXbXQX[Xch Bc^ahQ^PaSCPaVTc=P\T,>eTa[PhATRcP]V[T+3XbRaTcT>QYTRc:Th5aP\T :ThCX\T,+3XbRaTcT>QYTRc:Th5aP\TEP[dT+EXbXQX[Xch-EXbXQ[T+EXbXQX[Xch+3XbRaTcT>QYTRc:Th5aP\TEP[dT+3XbRaTcT>QYTRc:Th5aP\T+>QYTRc0]X\PcX^]DbX]V:Th5aP\Tb+Bc^ahQ^PaS+EXbdP[BcPcT.OTE )F YOU HAVE PREVIOUSLY CHANGED THE 1^aSTa CONTROL IN 8!-, TO A 6aXS CONTROL AND THEN HAVENT DELETED THE STORYBOARD ATTACHED TO IT YOULL END UP WITH A CHANGE OF THE FOREGROUND COLOR IN THIS CASE (OWEVER DOES NOTHING MORE THAN WHAT IS ALREADY DONE BY THE RECTANGLE EXCEPT THAT IN THIS CASE IT ALSO APPLIES TO IMAGES IN EITHER CASE APPLIES ONLY TO TEXT 4HE TEMPLATE IS READY AS YOU HAVE CUSTOMIZED THE BUTTON TEMPLATE %ARLIER WE SAID THAT YOU COULD CREATE THIS TEMPLATE IN SEVERAL WAYSAND JUST FOR THE SAKE OF INFORMATION THERE IS ALSO A REVERSE WAY THAT COULD COME IN HANDY IF YOU WANTED TO GIVE A BACKGROUND IMAGE TO YOUR BUTTON (OWEVER KEEPING A NORMAL BEHAVIOR COMPARED TO TEXTUAL CONTENT 4HIS TEMPLATE WILL DEPART FROM USING AN ITEM IMAGE FOR A BUTTON CONTROL 4HE PROCESS IS VIRTUALLY AUTOMATIC THANKS TO "LEND AND ALLOWS YOU TO ACHIEVE SATISFACTORY RESULTS WITH REGARD TO THE USER EXPERIENCE /UR IMAGE FOR THE BUTTON SHOWN IN &IGURE REPRESENTS A PROTOTYPE IDEA OF A CIRCULAR BUTTON )NSERT IT INTO YOUR OWN 8!-, AS A NORMAL IMAGE +8\PVT B^daRT,8\PVTb2XaR[T 1dcc^] ATS_]V 3O NOW YOU JUST HAVE TO RIGHT CLICK AND CHOOSE THE MENU ITEM -AKE )NTO #ONTROL !T THIS POINT YOU WILL SEE A SCREEN FOR SELECTING THE CONTROLS THAT YOU CAN ACHIEVE STARTING FROM THIS IMAGE )N OUR CASE WE CHOSE A BUTTON BUT IF YOU HAD A DIFFERENT IMAGE THAT REPRESENTED FOR EXAMPLE A SHEET OF NOTEBOOK PAPER YOU MIGHT HAVE CONSIDERED USING A LIST BOX
&IGURE 4HE BASE IMAGE FOR OUR BUTTON .AME THE TEMPLATE 2XaR[T1dcc^]CT\_[PcT )F YOU TRY TO YOU WILL REALIZE THAT THE BUTTON IS INERT IT DOES NOT REACT TO CHANGES IN STATE TO USER PRESSURE OR TO BEING DISABLED 3O YOU HAVE TO DEFINE THE BEHAVIOR UNDER THESE CONDITIONS !LTHOUGH THIS IS UNLIKE THE TYPE OF TEMPLATE THAT YOU CREATED EARLIER ITS NOT A BIG PROBLEM !LL YOU HAVE TO DO TO START IS ADD TWO ELLIPSES TO THE TEMPLATE THAT WILL OVERLAY THE BUTTONS ?aTbbTS AND 3XbPQ[TS STATES 9OU COULD ALSO USE A RECTANGLE TO ACHIEVE THIS GOAL BUT JUST TO LET YOU SEE THAT YOU CAN ACHIEVE THE SAME RESULT IN THIS MANNER THIS EXAMPLE USES AN ELLIPSE 4HE FIRST ELLIPSE ?aTbbTS4[[X_bT WILL OVERLAY THE IMAGE WHEN THE BUTTON IS PRESSED 4HE SECOND ELLIPSE 3XbPQ[TS4[[X_bT WILL AS ITS NAME SUGGESTS OVERLAY THE IMAGE WHEN THE BUTTON IS DISABLED "OTH ELLIPSES MUST HAVE THEIR VISIBILITY SET TO 2^[[P_bTS 4HEIR OPACITY MASK MUST BE THE IMAGE THAT YOU USED TO CREATE THE BUTTON 4HE FILL COLOR IS WHITE FOR THE PRESSED STATE AND GRAY FOR THE DISABLED STATE "OTH ARE NOT ENTIRELY OPAQUE AND HAVE A GOOD LEVEL OF TRANSPARENCY +4[[X_bT g)=P\T,?aTbbTS4[[X_bT EXbXQX[Xch,2^[[P_bTS 5X[[,&!343030 +4[[X_bT>_PRXch
+>QYTRc0]X\PcX^]DbX]V:Th5aP\Tb+Bc^ahQ^PaS+EXbdP[BcPcT+EXbdP[BcPcT g)=P\T,3XbPQ[TS+Bc^ahQ^PaS+>QYTRc0]X\PcX^]DbX]V:Th5aP\Tb Bc^ahQ^PaSCPaVTc?a^_Tach,D84[T\T]cEXbXQX[Xch Bc^ahQ^PaSCPaVTc=P\T,3XbPQ[TS4[[X_bT+3XbRaTcT>QYTRc:Th5aP\T :ThCX\T,+3XbRaTcT>QYTRc:Th5aP\TEP[dT+EXbXQX[Xch-EXbXQ[T+EXbXQX[Xch+3XbRaTcT>QYTRc:Th5aP\TEP[dT+3XbRaTcT>QYTRc:Th5aP\T+>QYTRc0]X\PcX^]DbX]V:Th5aP\Tb+Bc^ahQ^PaS+EXbdP[BcPcT .OW YOU HAVE A FULLY FUNCTIONAL BUTTON !ND NOW THAT YOUVE LEARNED HOW TO CUSTOMIZE THE DATA TEMPLATE BUTTON AND INTEREZIONI WITH THESE TOOLS UNDERSTANDING HOW TO CHANGE THE TEMPLATE OF A CHECK BOX WILL BE MUCH EASIER ! CHECK BOX TEMPLATE IS COMPOSED OF VARIOUS ELEMENTS A CONTENT CONTAINER WHICH ALLOWS YOU TO SPECIFY THE TEXT TO DISPLAY AS YOU MAY HAVE GUESSED EVEN IN THIS CASE YOU COULD USE AN IMAGE A PATH A SEQUENCE OF POINTS CONNECTED BY LINES THAT MAKE UP A FIGURE THAT IS MADE VISIBLE WHEN THE CHECK BOX IS SELECTED AND A RECTANGLE THAT IS MADE VISIBLE IN THE CASE OF AN INDETERMINATE STATE AS IN THE CASE OF THREE STATE CHECK BOX 3UPPOSE THAT FOR YOUR APPLICATION YOU WANT YOUR CHECK BOX TO BE MARKED WITH AN 8 INSTEAD OF THE USUAL CHECK MARK 9OU ALSO WANT TO DISPLAY A QUESTION MARK INSTEAD OF A SQUARE FOR THE INDETERMINATE STATE 4HE FIRST THING TO DO IS GET THE PATH THAT REFLECTS THIS FORMS 7E RECOMMEND USING -ICROSOFT %XPRESSION $ESIGN FOR THIS PURPOSE BECAUSE CREATING A PATH BY HAND CAN BE TOO DIFFICULT 4O CREATE AN 8 THE CODE WOULD BE WRITTEN AS FOLLOWS +?PcW g)=P\T,2WTRZ<PaZ 5X[[,jBcPcXRATb^daRT ?W^]TAPSX^2WTRZ1^g2WTRZ1adbWl FXScW,!$ 7TXVWc,!$ 2P]ePb;TUc, 2P]ePbC^_, BcaTcRW,5X[[ Bca^ZT;X]T9^X],A^d]S Bca^ZT,55 3PcP,5 < $!#&( &; !#%'&$$; !#%'& #&(!; !!#%'&$!; !#$!#&( &; ##%'& !#&(!; !#$!!#&(!; !!#%'&!#$; !#%'& ##&(!; !#%'&$!#$; $!!#&(!; #%'& !#&(!; $!#&( & I 4HE PATH TO GET THE QUESTION MARK WILL MORE OR LESS TAKE THIS FORM +?PcW g)=P\T,8]STcTa\X]PcT<PaZ 5X[[,jBcPcXRATb^daRT?W^]TAPSX^2WTRZ1^g2WTRZ1adbWl FXScW, !&! 7TXVWc,! %!"' 2P]ePb;TUc, 2P]ePbC^_, BcaTcRW,5X[[ 3PcP,5 < """%% $" %'2 "!#%!% $%(& " %$ #&$ "(!$( #"$ 2 "!% "($!' !('"' "$$& !('"' " %!(2 !('"' !$$!( " !!' ! $ "#' $'&2 "%&'' % #!$'( $$#% ###!" !##2 #'$' &(%(#!$ $" ##(!'$ $' '"'''"!2 %!(!!"'#'$'( %$$''"'' & % %#&%&& (2 &$&&&'&!&#( &(!#'%%'#$! '!!'%%#&'2 '#''&$($%$$ '% ('&$#%$"' '% ('&#(!&!(2 '% ('&##&$# '$ ''$#%#%! '" %'""&($$2 ' #'""$##& &'"'$!"$&!% &#'&((!' &(#2 & "&!$&'% %&"!$#!"(($ %!&"!"!!'%"2 $' "(!! % &$ $"!%('! !" #' !# ! !" 2 !(% "$! !" "$&!!!'"' #!#%!; #'!''2 %("#(#!(" "# !" $! !(2 q
!ND DOES NOT SEEM APPROPRIATE TO CONTINUE WITH ALL THE POINTS CONTAINED IN IT BUT IT IS ONLY TO EXPLAIN HOW IMPORTANT IT IS FOR A DESIGNER WHO INTENDS TO CUSTOMIZE THEIR OWN STRONG INTERFACE USING A TOOL SUCH AS $ESIGN TO GET 8!-, LIKE THIS
5SAGE 4O USE THIS RECIPE USE AN ALTERNATIVE FORM TO CREATE A DICTIONARY IN WHICH YOU INSERT ALL THE EFFECTS STYLES AND TEMPLATES THAT WERE SHOWN 4HEN APPLY THEM TO &3ad\ OR SOME OTHER APPLICATION .OTE HOW IMPORTANT AND CLEVER IT IS AS A DESIGNER TO CREATE YOUR OWN DICTIONARY OF EFFECTS WHILE ALWAYS TRYING TO IMPROVE THE GRAPHICS RENDERING TO KEEP IN TOUCH IN THE CREATION OF AN APPLICATION !ND IF YOURE A DEVELOPER YOU CAN DO THE SAME THING IF YOU WANT TO DO WITHOUT A DESIGNER YOUR OTHE APPLICATION
CHAPTER ■■■
Gestures 7ITH THE INTRODUCTION OF THE TOUCH SCREEN ON PHONES THE WAY USERS INTERACT WITH THESE DEVICES HAS RADICALLY CHANGED AS COMPARED TO TRADITIONAL MOUSE USAGE ON PERSONAL COMPUTERS 4HE SAME IS TRUE FOR THE PEN STYLUS INPUT DEVICE USED FOR EXAMPLE WITH "LACK"ERRY PHONES HOWEVER ALTHOUGH THE PEN STYLUS EMULATES THE MOUSE IT DOESNT OFFER ANY NEW WAY TO INTERACT WITH THE DEVICE 4HE INPUT INTERFACE REVOLUTION WAS BORN WITH THE I0HONE AND I0OD 4OUCH DEVICES ON WHICH YOU CAN USE YOUR FINGERS TO ZOOM IN OR ZOOM OUT ON PICTURES SCROLL TEXT AND MUCH MORE 7INDOWS 0HONE INHERITS I0HONE INPUT INTERFACE DIRECTIVES ENABLING SIMILAR GESTURES TO ACCOMPLISH USER INTERACTION WITH THE PHONE )N THIS CHAPTER YOU WILL LEARN WHICH GESTURES ARE PROVIDED BY 7INDOWS 0HONE AND HOW TO USE THEM IN YOUR APPLICATION 4HE RECIPES IN THIS CHAPTER DESCRIBE HOW TO DO THE FOLLOWING v
-ANAGE GESTURES IN A 3ILVERLIGHT 7INDOWS 0HONE APPLICATION
v
!DD GESTURES MANAGEMENT TO 2[XRZ LESS 3ILVERLIGHT CONTROLS
v
(ANDLE GESTURES IN A GRAPHICAL CONTEXT SUCH AS A GAME MENU
v
-ANAGE GESTURES FROM THE 3ILVERLIGHT FOR 7INDOWS 0HONE TOOLKIT
-ANAGING 'ESTURES IN A 3ILVERLIGHT 7INDOWS 0HONE !PPLICATION 0ROBLEM 9OU NEED TO UNDERSTAND WHAT GESTURES ARE AND HOW TO USE THEM IN YOUR 3ILVERLIGHT 7INDOWS 0HONE APPLICATION
3OLUTION 6ARIOUS TECHNIQUES ARE AVAILABLE FOR ENABLING YOU TO KNOW WHERE A USER TOUCHED THE SCREEN AND HOW MANY FINGERS WERE USED 9OU CAN USE THE C^dRW STATIC CLASS WHICH PROVIDES THE 5aP\TAT_^acTS EVENT ROSE WHEN THE SCREEN IS TOUCHED !LONG WITH THE C^dRW STATIC CLASS YOU CAN USE THE 6TcC^dRW?^X]cb METHOD FROM THE C^dRW5aP\T4eT]c0aVb ARGUMENT PROVIDED BY THE 5aP\TAT_^acTS EVENT HANDLER 4HE
6TcC^dRW?^X]cb METHOD RETURNS A C^dRW?^X]c2^[[TRcX^] COLLECTION FILLED WITH C^dRW?^X]c OBJECTS REPRESENTING TOUCHED SCREEN POINTS "UT USING THE C^dRW?^X]c2^[[TRcX^] TO UNDERSTAND GESTURES IS NOT SO EASY 9OU HAVE TO STUDY THE COLLECTION TO UNDERSTAND HOW THE USERS FINGERS HAVE MOVED ON THE SCREEN AND WHAT THAT USERS INTENTIONS COULD BE 9OU SHOULD USEALONG WITH THE C^dRW5aP\TAT_^acTS EVENT HANDLERTHE C^dRW?P]T[ CLASS INCLUDED IN THE 8.! FRAMEWORK 4HE C^dRW?P]T[ CLASS ALONG WITH THE 6TbcdaTBP\_[T STRUCTURE REALLY SIMPLIFIES THE RECOGNITION OF GESTURES BY YOUR APPLICATION SEE &IGURE FOR DIAGRAMS OF THESE CLASSES
&IGURE #LASS DIAGRAM FOR GESTURE CLASSES
(OW )T 7ORKS 'ESTURES ARE OPERATIONS CARRIED OUT WITH ONE OR MORE FINGERS ON THE PHONES TOUCH SCREEN 7INDOWS 0HONE SUPPORTS HAVING AT LEAST FOUR FINGERS ON THE SCREEN ! FINGER CAN TOUCH THE SCREEN AND IMMEDIATELY RISE UP OR IT CAN TOUCH THE SCREEN AND MOVE IN ANY DIRECTION WHILE REMAINING PRESSED ON THE SCREEN %ACH OPERATION THAT THE USERS FINGERS PERFORM ON THE TOUCH SCREEN REPRESENTS A GESTURE )N 4ABLE YOU CAN SEE THE LIST OF SUPPORTED GESTURES 4HE MOST USED ARE 4AP $OUBLE 4AP 0INCH AND &LICK -OST 3ILVERLIGHT CONTROLS PROVIDE 2[XRZ AND 3^dQ[T 2[XRZ EVENT HANDLERS WHEN THE USER TAPS AND DOUBLE TAPS ON THE CONTROL ITSELF BUT YOU MIGHT NEED OTHER GESTURES IN YOUR APPLICATION &OR EXAMPLE IMAGINE A BOOK READER APPLICATION IN WHICH THE USER NEEDS TO SCROLL THROUGH PAGES QUICKLY )MPLEMENTING A 4AP GESTURE TO SCROLL PAGE BY PAGE WOULD BE FRUSTRATING FOR THE USER -UCH BETTER THE &LICK GESTURE WHICH RETURNS FINGER MOVING SPEED WITH THE 3T[cP PROPERTY PROVIDED BY THE 6TbcdaTBP\_[T STRUCTURE 9OU COULD USE THIS ETRc^a! VALUE RETURNED BY THE 3T[cP PROPERTY TO ENABLE THE USER TO MOVE FASTER ACROSS THE BOOK PAGES 4ABLE !LL THE GESTURES PROVIDED BY THE 6TbcdaTCh_T ENUMERATION
Gesture
Description
4AP
4HE FINGER TOUCHES AND IMMEDIATELY RISES UP FROM THE TOUCH SCREEN
$OUBLE 4AP
4HE SAME AS THE 4AP GESTURE BUT TOUCHING AND RISING TWO TIMES ONE RIGHT AFTER THE OTHER
(ORIZONTAL $RAG
4HE FINGER TOUCHES THE SCREEN CONTINUES TO PRESS IT AND MOVES HORIZONTALLY
6ERTICAL $RAG
4HE SAME AS (ORIZONTAL $RAG BUT THE MOVEMENT IS VERTICAL
&REE $RAG
4HE FINGER TOUCHES THE SCREEN CONTINUES TO PRESS IT AND MOVES FREELY
$RAG #OMPLETE
4HE FINGER STARTS A DRAG GESTURE AND COMPLETES IT BY RAISING THE FINGER
&LICK
4HE FINGER TOUCHES THE SCREEN AND MOVES EITHER UP OR DOWN VERY FAST 4HIS IS THE GESTURE USED TO QUICKLY REMOVE THE LOCK SCREEN
0INCH
4WO FINGERS TOUCH THE SCREEN MOVING EITHER APART OR TOGETHER 4HIS IS THE GESTURE USED TO EITHER ZOOM INTO OR ZOOM OUT FROM AN IMAGE
0INCH #OMPLETE
4WO FINGERS START THE 0INCH GESTURE AND COMPLETE IT BY RAISING BOTH FINGERS
(OLD
4HE FINGER TOUCHES THE SCREEN AND CONTINUES TO PRESS IT WITHOUT MOVING
4O USE GESTURES IN YOUR APPLICATION YOU FIRST NEED TO COMPLETE THE FOLLOWING STEPS
!DD A REFERENCE TO BOTH THE <XRa^b^UcG]P5aP\Tf^aZS[[ AND <XRa^b^UcG]P5aP\Tf^aZ8]_dcC^dRWS[[ ASSEMBLIES
$EFINE A 5aP\TAT_^acTS EVENT HANDLER
$EFINE ALL THE GESTURES YOU WANT TO TRAP IN YOUR APPLICATION BY SPECIFYING THEM IN THE 4]PQ[TS6TbcdaTb PROPERTY FROM THE C^dRW?P]T[ CLASS SEPARATED BY THE >A LOGICAL OPERATOR
)N THE 5aP\TAT_^acTS EVENT HANDLER CHECK WHETHER A GESTURE IS AVAILABLE BY USING THE 8b6TbcdaT0ePX[PQ[T PROPERTY FROM THE C^dRW?P]T[ CLASS
$EFINE A 6TbcdaTBP\_[T OBJECT THAT RECEIVES GESTURES FROM THE ATPS6TbcdaT METHOD PROVIDED BY THE C^dRW?P]T[ CLASS
5SE THE GESTURE ACCORDINGLY IN YOUR APPLICATION
4HE #ODE 4O DEMONSTRATE EVERY GESTURE PROVIDED BY THE PHONE WE HAVE CREATED A SIMPLE APPLICATION THAT WRITES THE GESTURE TYPE ON THE PAGE TITLE 3TART 6ISUAL 3TUDIO AND CREATE A NEW 3ILVERLIGHT 7INDOWS 0HONE APPLICATION CALLED 6TbcdaTb3T\^ )N THE
■ .OTE 7E HAVE ADDED AN IMAGE CONTROL JUST TO GIVE TO THE APPLICATION A BETTER LOOK BUT THE IMAGE CONTROL IS NOT NECESSARY TO RETRIEVE GESTURES 4HE C^dRW5aP\TAT_^acTS EVENT IS THE ONLY ONE THAT CATCHES GESTURES BECAUSE IT IS IMPLEMENTED INTO THE ?W^]T0__[XRPcX^]5aP\T CLASS
4HE
4]PQ[TS6TbcdaTb PROPERTY -OREOVER THE 5aP\TAT_^acTS EVENT IS DEFINED AND MANAGED BY THE C^dRW 5aP\TAT_^acTS EVENT HANDLER 2^]bcadRc^a _dQ[XR
5SAGE )N THIS RECIPE YOU NEED A PHYSICAL DEVICE TO TEST THE APPLICATION )NDEED THE EMULATOR IS NOT ABLE TO INTERCEPT MULTI TOUCH GESTURES SUCH AS THE 0INCH
#ONNECT YOUR UNLOCKED DEVICE SEE 2ECIPE FOR MORE INFORMATION ON HOW TO UNLOCK DEVICES AND RUN THE APPLICATION FROM 6ISUAL 3TUDIO ENSURING THAT THE OUTPUT TARGET IS SET TO 7INDOWS 0HONE $EVICE 4HE APPLICATION WILL START SHOWING THE OUTPUT IN &IGURE
&IGURE 4HE 6TbcdaTb3T\^ APPLICATION IN ACTION
!T THIS POINT YOU CAN START PLAYING WITH YOUR PHONE )N &IGURE WE PERFORMED A VERY RAPID &LICK AS DEMONSTRATED BY THE PAGE TITLE SHOWING THE GESTURE TYPE AND THE 3T[cP PROPERTY VALUE
&IGURE 4HE PAGE TITLE SHOWS THAT A &LICK GESTURE HAS OCCURRED
!DDING 'ESTURES -ANAGEMENT TO #LICK LESS 3ILVERLIGHT #ONTROLS 0ROBLEM 9OU NEED TO ADD GESTURES TO THE CONTROLS THAT DONT PROVIDE THE 2[XRZ EVENT
3OLUTION 9OU NEED TO USE THE 1TWPeX^a CLASS DEFINED IN THE BhbcT\FX]S^fb8]cTaPRcXeXchS[[ ASSEMBLY
(OW )T 7ORKS !LMOST ALL 3ILVERLIGHT CONTROLS IN 7INDOWS 0HONE HAVE THE 4AP AND $OUBLE 4AP GESTURES ASSOCIATED TO THE 2[XRZ AND 3^dQ[T 2[XRZ EVENTS "Y THE WAY THERE ARE CONTROLS SUCH AS 6aXS WHICH INHERITS FROM THE ?P]T[ CONTROL THAT PROVIDE NEITHER THE 2[XRZ NOR 3^dQ[T 2[XRZ EVENTS %XAMINING THE PARENT CLASSES FROM WHICH THE ?P]T[ CLASS DERIVES WE ARRIVE AT THE D84[T\T]c CLASS THAT PROVIDES MOUSE EVENTS /BVIOUSLY A 7INDOWS 0HONE DOESNT HAVE A MOUSE BUT THE EVENTS ARE FIRED THE SAME WHEN A FINGER TOUCHES THE SCREEN 9OU CAN MANAGE <^dbT;TUc1dcc^]3^f] AND <^dbT;TUc1dcc^]D_ EVENTS TO SIMULATE THE 4AP OR THE $OUBLE 4AP GESTURES ON CONTROLS THAT DERIVE FROM THE D84[T\T]c CLASS )N YOUR CODE YOU HAVE TO SPECIFY THE RESPONSE TO MOUSE EVENTS FOR EACH CONTROL YOU NEED TO MANAGE 4HIS IS NOT THE BEST APPROACH TO HAVE WHEN YOU NEED TO ADD GESTURES TO ELEMENTS THAT DONT PROVIDE THEM )T WOULD BE NICE TO HAVE GENERIC AND REUSABLE CODE THAT COULD BE APPLIED IN 8!-, CODE TO EVERY CONTROL THAT NEEDS IT 4HIS CAN BE CREATED BY USING THE 1TWPeX^a CLASS 4HE 1TWPeX^a CLASS SEE ITS CLASS DIAGRAM IN &IGURE PROVIDES THE METHODS TO CREATE A BEHAVIOR THAT IS APPLICABLE TO CONTROLS %ACH CONTROL THAT DERIVES FROM THE CLASS SPECIFIED AS GENERIC TYPE DURING THE BEHAVIOR DEFINITION WILL HAVE THAT BEHAVIOR )T PROVIDES THE >]0ccPRWTS METHOD WHERE YOU CAN SPECIFY THE EVENT HANDLERS THAT YOU WANT TO TRAP 9OU CAN RELEASE THOSE EVENT HANDLERS IN THE >]3TcPRWX]V METHOD PROVIDED BY THE 1TWPeX^a CLASS
&IGURE 4HE 1TWPeX^a CLASS DIAGRAM
4HE #ODE )N THE CODE FOR THIS RECIPE YOU ARE GOING TO ADD BOTH THE 4AP AND (OLD GESTURES TO THE 6aXS CONTROL ,ETS CREATE A NEW 3ILVERLIGHT 7INDOWS 0HONE APPLICATION CALLED 0SS6TbcdaT3T\^ FROM 6ISUAL 3TUDIO 4HE FIRST OPERATION YOU ARE GOING TO PERFORM IS TO ADD A NEW CLASS TO THE PROJECT CALLED 0SSCP_ 9OU CAN ACCOMPLISH THIS STEP FROM 6ISUAL 3TUDIO BY CHOOSING 0ROJECT ➤ !DD #LASS 4HE SKELETON OF 0SSCP_ CLASS IS GENERATED 4HE NEXT THING TO DO IS TO ADD A REFERENCE TO THE BhbcT\FX]S^fb8]cTaPRcXeXchS[[ ASSEMBLY &ROM THE 3OLUTION %XPLORER RIGHT CLICK THE PROJECT NAME AND SELECT !DD 2EFERENCE FROM THE CONTEXT MENU &ROM THE !DD 2EFERENCE DIALOG BOX SELECT THE .%4 TAB AND SEARCH FOR BhbcT\FX]S^fb8]cTaPRcXeXch .OW YOU CAN ADD THE dbX]V DIRECTIVE IN THE 0SSCP_ CLASS TO POINT TO THE BhbcT\FX]S^fb8]cTaPRcXeXch NAMESPACE )N THAT WAY YOU CAN DERIVE THE 0SSCP_ CLASS FROM THE 1TWPeX^a+D84[T\T]c- CLASS .EXT YOU OVERRIDE THE >]0ccPRWTS AND >]3TcPRWX]V METHODS &OR THE FORMER YOU ARE GOING TO DEFINE EVENT HANDLERS FOR THE <^dbT;TUc1dcc^]3^f] AND <^dbT;TUc1dcc^]D_ EVENTS &OR THE LATTER YOU WILL DETACH THEM 9OU WILL USE THE <^dbT;TUc1dcc^]3^f] EVENT TO STORE THE TICKS FROM THE 3PcTCX\T=^f PROPERTY 4HOSE TICKS WILL BE SUBTRACTED FROM THE TICKS PICKED IN THE <^dbT;TUc1dcc^]D_ EVENT AND COMPARED TO THE TICKS EQUAL TO SECOND )N THIS WAY YOU CAN TELL WHEN THE USER TAPS THE SCREEN BUTTON DOWN AND UP IN LESS THAN SECOND OR WHEN USER HOLDS A FINGER ON THE SCREEN BUTTON DOWN AND UP IN MORE THAN SECOND 3O IN THE FORMER CASE THE 3^CP_ EVENT WILL BE RAISED AND IN THE LATTER CASE THE 3^7^[S EVENT WILL BE FIRED
■ .OTE 7E CHOSE SECOND AS THE TIME LIMIT TO DISTINGUISH A 4AP GESTURE FROM A (OLD GESTURE BUT YOU CAN CHANGE THIS VALUE SIMPLY BY CHANGING THE CX\TB_P]CXRZb?TaBTR^]S VALUE IN THE XU CONDITION WITHIN THE 0bb^RXPcTS>QYTRc <^dbT;TUc1dcc^]D_ EVENT HANDLER
dbX]V BhbcT\FX]S^fb8]cTaPRcXeXch* ]P\Tb_PRT 0SS6TbcdaT3T\^ j _dQ[XR R[Pbb 0SSCP_ ) 1TWPeX^a+D84[T\T]cj _dQ[XR TeT]c 4eT]c7P]S[Ta CP_* _dQ[XR TeT]c 4eT]c7P]S[Ta 7^[S* _aXePcT Q^^[ 8b<^dbT?aTbbTS* _aXePcT CX\TB_P] \^dbT;TUc1dcc^]3^f]CX\T* _a^cTRcTS ^eTaaXST e^XS >]0ccPRWTS j cWXb0bb^RXPcTS>QYTRc<^dbT;TUc1dcc^]3^f] , ]Tf <^dbT1dcc^]4eT]c7P]S[Ta0bb^RXPcTS>QYTRc <^dbT;TUc1dcc^]3^f]* cWXb0bb^RXPcTS>QYTRc<^dbT;TUc1dcc^]D_ , ]Tf <^dbT1dcc^]4eT]c7P]S[Ta0bb^RXPcTS>QYTRc <^dbT;TUc1dcc^]D_* QPbT>]0ccPRWTS* l _a^cTRcTS ^eTaaXST e^XS >]3TcPRWX]V j cWXb0bb^RXPcTS>QYTRc<^dbT;TUc1dcc^]3^f] , 0bb^RXPcTS>QYTRc <^dbT;TUc1dcc^]3^f]* cWXb0bb^RXPcTS>QYTRc<^dbT;TUc1dcc^]D_ , 0bb^RXPcTS>QYTRc <^dbT;TUc1dcc^]D_* QPbT>]3TcPRWX]V* l e^XS 0bb^RXPcTS>QYTRc <^dbT;TUc1dcc^]3^f]^QYTRc bT]STa <^dbT1dcc^]4eT]c0aVb T j 8b<^dbT?aTbbTS , cadT* \^dbT;TUc1dcc^]3^f]CX\T , CX\TB_P]5a^\CXRZb3PcTCX\T=^fCXRZb* l e^XS 0bb^RXPcTS>QYTRc <^dbT;TUc1dcc^]D_^QYTRc bT]STa <^dbT1dcc^]4eT]c0aVb T j CX\TB_P] T[P_bTSCX\T , CX\TB_P]5a^\CXRZb3PcTCX\T=^fCXRZb ~ \^dbT;TUc1dcc^]3^f]CX\T*
XU 8b<^dbT?aTbbTS 3^CP_* T[bT 3^7^[S*
T[P_bTSCX\TCXRZb + CX\TB_P]CXRZb?TaBTR^]S
8b<^dbT?aTbbTS , UP[bT* l e^XS 3^CP_ j XU CP_ , ]d[[ CP_0bb^RXPcTS>QYTRc 4eT]c0aVb4\_ch* l e^XS 3^7^[S j XU 7^[S , ]d[[ 7^[S0bb^RXPcTS>QYTRc 4eT]c0aVb4\_ch* l l l )N THE
+2^]cT]c?P]T[ _[PRT PSSXcX^]P[ R^]cT]c WTaT+6aXS g)=P\T,2^]cT]c?P]T[ 6aXSA^f, <PaVX], ! ! 1PRZVa^d]S,FWXcT+X)8]cTaPRcX^]1TWPeX^ab+cP_)0SSCP_ CP_,0SSCP_ CP_ 7^[S,0SSCP_ 7^[S+X)8]cTaPRcX^]1TWPeX^ab+6aXS+6aXS&INALLY WHEN THE CP_ AND 7^[S EVENTS ARE RAISED YOU SIMPLY SHOW A
5SAGE 0RESS #TRL& FROM 6ISUAL 3TUDIO AND BE SURE TO SELECT THE 7INDOWS 0HONE %MULATOR AS THE OUTPUT TARGET 4HE EMULATOR WILL START BRIEFLY SHOWING THE APPLICATION AS YOU CAN SEE IN &IGURE
&IGURE 4HE 0SS6TbcdaT APPLICATION SHOWS A WHITE BACKGROUND FOR THE CONTENT GRID
.OW PRESS AND THEN RAPIDLY RELEASE THE LEFT MOUSE BUTTON OVER THE WHITE ZONE ! MESSAGE BOX SHOWING 9OU TAPPED THE GRID IS SHOWN .OW PRESS AND HOLD FOR MORE THAN SECOND THE LEFT MOUSE BUTTON OVER THE WHITE ZONE AND THEN RELEASE IT ! MESSAGE BOX SHOWING (OLD GESTURE IN THE GRID APPEARS
(ANDLING 'ESTURES IN A 'RAPHICAL #ONTEXT 3UCH AS A 'AME -ENU 0ROBLEM 9OU HAVE AN IMAGE WITH SENSIBLE TOUCH ZONESFOR EXAMPLE A GRAPHICAL GAME MENUAND YOU NEED TO MANAGE GESTURES ONLY WHEN THEY OCCUR IN THOSE ZONES
3OLUTION 9OU CAN CREATE A MASK IMAGE AND USE THE FaXcTPQ[T1Xc\P_ CLASS TO RETRIEVE THE CHOSEN PIXEL COLOR )N YOUR CODE YOU ASSOCIATE A COLOR TO AN OPERATION
(OW )T 7ORKS )N THIS RECIPE WE ARE GOING FURTHER WITH THE &3ad\ APPLICATION DEVELOPED THROUGHOUT THIS BOOK )N THIS CASE YOU ARE GOING TO EXAMINE THE VIRTUAL DRUMMING FUNCTIONALITY !N IMAGE OF A DRUM KIT IS SHOWN ON THE SCREEN AND THE USER CAN TAP THE DRUM COMPONENTS AND HEAR THE RELATED SOUNDS "ECAUSE DRUM COMPONENTS HAVE DIFFERENT SIZES AND SHAPES MEMORIZING THEIR POSITIONS ON THE SCREEN IS NOT REALLY THE BEST THING TO DO 9OU CAN RETRIEVE THE POSITION OF THE TAP BUT THEN YOU HAVE TO CHECK WHICH DRUM COMPONENT HAS THOSE COORDINATES "ECAUSE A DRUM COMPONENT CANNOT HAVE A LINEAR SHAPE THIS IS REALLY A BAD APPROACH 9OU CAN USE THE FaXcTPQ[T1Xc\P_ CLASS WHICH PROVIDES THE ?XgT[b ARRAY USED TO RETRIEVE A PIXEL TO A PROVIDED X AND Y COORDINATE 9OU CAN CREATE A MASK IMAGE FROM THE ORIGINAL IMAGE LOAD IT IN MEMORY WITHOUT SHOWING IT IN YOUR APPLICATION AND USE THE ?XgT[b ARRAY TO RETRIEVE THE COLOR OF THE CHOSEN PIXEL )N YOUR CODE YOU HAVE ASSOCIATED A COLOR TO AN OPERATION OR A MENU ITEM SO YOU KNOW WHAT TO DO )N OUR CASE THE DRUM KIT MASK IMAGE CONTAINS DIFFERENT COLORED ZONES RELATED TO DRUM COMPONENTS SEE &IGURE 4HE DRUM KIT IMAGE SHOWN TO THE USER IS DEFINITIVELY MUCH BETTER SEE &IGURE
&IGURE 4HE DRUM KIT MASK IMAGE
&IGURE 4HE DRUM KIT SHOWN TO THE USER
7HEN THE USER TAPS THE SNARE THE CODE RETRIEVES THE PIXEL WITH BLUE COLOR AND PLAYS THE SNARE SOUND SEE 2ECIPE TO READ MORE ON PLAYING SOUND
■ .OTE 4O PRODUCE THE MASK IMAGE WE USED THE 0AINT.%4 FREE DRAWING TOOL YOU CAN DOWNLOAD IT FROM fffVTc_PX]c]Tc 9OU LOAD THE MAIN IMAGE IN THE TOOL AND ADD A NEW LAYER 9OU START TO DRAW OVER THE SENSITIVE PICTURE ZONES GIVING EACH A DIFFERENT COLOR 9OU REMOVE THE LAYER THE BACKGROUND IN THIS CASE WHERE YOU SET THE ORIGINAL IMAGE REMAINING WITH THE MASK &INALLY YOU HAVE TO SAVE THE MASK IMAGE IN EITHER A OR COLOR BITMAP FORMAT SO THAT OIXELS USE SOLID COLORS
4HE #ODE 4O DEMONSTRATE THIS TECHNIQUE WE HAVE ADDED THE VIRTUAL DRUMMING FUNCTIONALITY TO THE &3ad\ APPLICATION /PEN THE &3ad\ PROJECT AND ADD A 7INDOWS 0HONE ,ANDSCAPE 0AGE CALLED EXacdP[3ad\gP\[ #REATE AN IMAGES FOLDER WITH THE ORIGINAL IMAGE AND THE RELATED MASK IMAGE 3ELECT THE 2^]cT]c VALUE FROM THE 1dX[S 0RcX^] PROPERTY IN THE 0ROPERTY WINDOW )N THIS WAY IMAGES WILL BE ADDED TO THE FINAL 8!0 FILE AS DISTINCT FILES AND NOT INSERTED AS RESOURCES 4HIS IS DONE SO THAT IN THE 8\PVT CONTROL YOU CAN SET THE B^daRT ATTRIBUTE TO THE IMAGES RELATIVE PATH +_W^]T)?W^]T0__[XRPcX^]?PVT g)2[Pbb, &3ad\EXacdP[3ad\ g\[]b,Wcc_)bRWT\Pb\XRa^b^UcR^\fX]Ug!%gP\[_aTbT]cPcX^] g\[]b)g,Wcc_)bRWT\Pb\XRa^b^UcR^\fX]Ug!%gP\[ g\[]b)_W^]T,R[a]P\Tb_PRT)<XRa^b^Uc?W^]T2^]ca^[b*PbbT\Q[h,<XRa^b^Uc?W^]T g\[]b)bWT[[,R[a]P\Tb_PRT)<XRa^b^Uc?W^]TBWT[[*PbbT\Q[h,<XRa^b^Uc?W^]T g\[]b)S,Wcc_)bRWT\Pb\XRa^b^UcR^\Tg_aTbbX^]Q[T]S!' g\[]b)\R,Wcc_)bRWT\Pb^_T]g\[U^a\Pcb^aV\PaZd_R^\_PcXQX[Xch!% \R)8V]^aPQ[T,S S)3TbXV]FXScW,' S)3TbXV]7TXVWc,#' 5^]c5P\X[h,jBcPcXRATb^daRT ?W^]T5^]c5P\X[h=^a\P[l 5^]cBXiT,jBcPcXRATb^daRT ?W^]T5^]cBXiT=^a\P[l 5^aTVa^d]S,jBcPcXRATb^daRT ?W^]T5^aTVa^d]S1adbWl Bd__^acTS>aXT]cPcX^]b,;P]SbRP_T >aXT]cPcX^],;P]SbRP_T bWT[[)BhbcT\CaPh8bEXbXQ[T,5P[bT+8\PVT g)=P\T,X\V3ad\ B^daRT,X\PVTb3ad\ :Xc #'g'Y_V FXScW,' 7TXVWc,#' +_W^]T)?W^]T0__[XRPcX^]?PVT)N THE EXacdP[3ad\gP\[Rb FILE YOU USE THE CONSTRUCTOR CODE TO LOAD THE MASK IMAGE AND ADD THE 5aP\TAT_^acTS EVENT HANDLER 2^]bcadRc^a _dQ[XR EXacdP[3ad\ j 8]XcXP[XiT2^\_^]T]c* Q\_
Q\_
_aXePcT BhbcT\FX]S^fb
5SAGE 4HIS MAY BE ONE OF THE MOST FUN v5SAGEv SECTIONS OF THE ENTIRE BOOK 7E CAN MAKE A LOT OF NOISE WITH A VIRTUAL DRUM &ROM 6ISUAL 3TUDIO PRESS #TRL& AND WAIT A FEW MOMENTS UNTIL THE EMULATOR STARTS CHECK THAT 7INDOWS 0HONE %MULATOR IS THE CURRENT OUTPUT TARGET &ROM THE MAIN MENU CHOOSE 4AKE 9OUR 'ROOVE 4HE DRUM KIT APPEARS AS SHOWN IN &IGURE
&IGURE 4HE VIRTUAL DRUM IN ACTION .OW YOU CAN TAP ON ONE OR MORE DRUM COMPONENTS TO HEAR THE RELATED SOUND
-ANAGING 'ESTURES FROM THE 3ILVERLIGHT FOR 7INDOWS 0HONE 4OOLKIT 0ROBLEM 9OU NEED TO IMPLEMENT DRAG AND DROP IN YOUR 3ILVERLIGHT 7INDOWS 0HONE APPLICATION
3OLUTION 9OU HAVE DIFFERENT OPTIONS HERE INCLUDING USING THE GESTURES AND TECHNIQUES EXPLAINED IN THE PREVIOUS RECIPES (OWEVER THIS TIME WE SUGGEST ANOTHER SOLUTION TO ACCOMPLISH DRAG AND DROP OR OTHER GESTURES MANAGEMENT 6TbcdaT;XbcT]Ta PROVIDED BY THE 3ILVERLIGHT FOR 7INDOWS 0HONE TOOLKIT
(OW )T 7ORKS !S YOU SAW IN #HAPTER YOU CAN DOWNLOAD THE 3ILVERLIGHT FOR 7INDOWS 0HONE TOOLKIT FROM #ODE0LEX AT Wcc_)bX[eTa[XVWcR^ST_[TgR^\ 4HIS TOOLKIT PROVIDES THE 6TbcdaTBTaeXRT CLASS WHICH EXPOSES THE 6TbcdaT;XbcT]Ta PROPERTY 9OU CAN USE THIS PROPERTY TO SPECIFY THE GESTURE YOU WANT TO MANAGE IN YOUR APPLICATION )NDEED 6TbcdaT;XbcT]Ta PROVIDES A PUBLIC EVENT FOR EACH GESTURE SUPPORTED BY THE PHONE PLUS TWO MORE EVENTS INDICATING WHEN THE GESTURE BEGINS AND WHEN THE GESTURE IS COMPLETED
4HE #ODE 4O DEMONSTRATE THE DRAG AND DROP FUNCTION IN A 3ILVERLIGHT 7INDOWS 0HONE APPLICATION WE HAVE CREATED THE 6TbcdaTbFXcWC^^[ZXc PROJECT 9OU ARE GOING TO CREATE AN APPLICATION IN WHICH A RECTANGLE CAN BE DRAGGED AROUND THE SCREEN 7HEN THE DRAG IS COMPLETED THE CODE CHECKS WHETHER THE RECTANGLE HAS BEEN DROPPED OVER ANOTHER RECTANGLE #REATE A NEW 6ISUAL 3TUDIO 3ILVERLIGHT 7INDOWS 0HONE APPLICATION CALLED 6TbcdaTbFXcWC^^[ZXc !DD A REFERENCE TO THE <XRa^b^Uc?W^]T2^]ca^[bC^^[ZXc ASSEMBLY 9OU SHOULD FIND IT IN THE ?a^VaP\K K<XRa^b^Uc B3:bKFX]S^fb ?W^]TKe&KC^^[ZXcK=^e K1X] DIRECTORY )N
4HEN YOU HAVE TO ADD THE 6TbcdaTBTaeXRT TAG BETWEEN THE TAGS OF THE CONTROL USED TO MANAGE THE GESTURES &OR EXAMPLE WE ADDED THOSE TAGS TO THE ATRcP]V[T CONTROL DEFINED INSIDE 2P]ePb 4HE 6TbcdaT;XbcT]Ta TAG ENABLES US TO DEFINE WHICH GESTURES CAN BE MANAGED BY OUR APPLICATION SPECIFYING WHICH IS THE RELATED EVENT HANDLER 7E HAVE SPECIFIED TO RETRIEVE 3aPVBcPacTS 3aPV3T[cP AND 3aPV2^\_[TcT EVENTS 4HE TWO RECTANGLES ARE PLACED INTO A 2P]ePb CONTROL AT FIXED POSITIONS 4HE DRAGABLE RECTANGLE HAS THE I8]STg PROPERTY GREATER THAN THE OTHER RECTANGLE SO IT WILL NOT DISAPPEAR UNDER THE DRAGGED RECTANGLE WHEN THEY OVERLAP +2^]cT]c?P]T[ _[PRT PSSXcX^]P[ R^]cT]c WTaT+2P]ePb g)=P\T,2^]cT]c?P]T[ <PaVX], ! !+ATRcP]V[T 5X[[,ATS g)=P\T,aB^daRT FXScW, 7TXVWc, 6aXSA^f, 2P]ePb;TUc, 2P]ePbC^_, % 2P]ePbI8]STg, +c^^[ZXc)6TbcdaTBTaeXRT6TbcdaT;XbcT]Ta+c^^[ZXc)6TbcdaT;XbcT]Ta 3aPVBcPacTS,6TbcdaT;XbcT]TaN3aPVBcPacTS 3aPV3T[cP,6TbcdaT;XbcT]TaN3aPV3T[cP 3aPV2^\_[TcTS,6TbcdaT;XbcT]TaN3aPV2^\_[TcTS +c^^[ZXc)6TbcdaTBTaeXRT6TbcdaT;XbcT]Ta+ATRcP]V[T+ATRcP]V[T 5X[[,HT[[^f g)=P\T,aCPaVTc 7TXVWc, FXScW,#% 2P]ePb;TUc, 2P]ePbC^_,%% 2P]ePbI8]STg, +2P]ePb )N THE
aTRcBTcEP[dT2P]ePb;TUc?a^_Tach S^dQ[TaTRc6TcEP[dT2P]ePb;TUc?a^_Tach T7^aXi^]cP[2WP]VT* l l &INALLY IN THE 6TbcdaT;XbcT]Ta 3aPV2^\_[TcTS EVENT HANDLER WE INFORM THE APPLICATION THAT THE DRAG OPERATION HAS ENDED -OREOVER WE CHECK WHETHER THE TWO RECTANGLES HAVE COLLIDED BY CALLING THE 2^[[XbX^]3TcTRcTS METHOD )F THE RECTANGLES HAVE COLLIDED WE WILL SHOW A
5SAGE &ROM 6ISUAL 3TUDIO PRESS #TRL& AND WAIT FOR THE EMULATOR TO START 4HE APPLICATION SHOWN IN &IGURE DISPLAYS
&IGURE 4HE 6TbcdaTFXcWC^^[ZXc APPLICATION SHOWS THE RED RECTANGLE READY TO BE DRAGGED OVER THE YELLOW ONE .OW YOU CAN PRESS AND HOLD THE LEFT MOUSE BUTTON AND START TO MOVE IT AROUND THE SCREEN EMULATOR 7HEN YOU DROP THE RED RECTANGLE OVER THE YELLOW ONE YOU WILL SEE A MESSAGE APPEAR ONSCREEN AS SHOWN IN &IGURE
&IGURE 4HE COLLISION BETWEEN THE RED AND YELLOW RECTANGLE HAS BEEN DETECTED
CHAPTER ■■■
Sensors 4HIS CHAPTER COVERS THE USE OF SENSORS ON 7INDOWS 0HONE 4HE BASE REQUIREMENTS FOR MANUFACTURERS ARE THE ACCELEROMETER COMPASS PROXIMITY SENSOR LIGHT AND ! '03 )N THIS VERSION OF THE 3$+ FROM YOUR CODE YOU CAN HAVE ACCESS ONLY TO THE ACCELEROMETER AND ! '03 "UT DONT WORRYEVEN WITH THESE TWO THINGS YOU CAN CREATE HIGH IMPACT APPLICATIONS FOR THE USER !N ACCELEROMETER MEASURES ACCELERATION FORCES FOR EXAMPLE GRAVITY OR MOVEMENT 4HE ACCELEROMETER !0) IS BUILT ON TOP OF THE SENSOR FRAMEWORK SO WHEN WE WILL HAVE ACCESS TO THE OTHER SENSORS EXPOSED BY THE !0) WE WILL USE THEM ALL AT THE SAME WAY 4HE ACCELEROMETER DATA ARE EXPOSED BY THE 0RRT[Ta^\TcTaATPSX]V4eT]c0aVb CLASS WHICH EXPOSES THREE PROPERTIES FOR THE X Y AND Z AXIS THAT ASSUME VALUES BETWEEN n AND THE SIGN OF VALUE IS USED TO INTERPRET THE DIRECTION OF THE VECTOR OF FORCE 4HE ! '03 IS PART OF THE ,OCATION 3ERVICE NWHICH ENABLES US TO OBTAIN THE POSITION OF THE PHONE ON THE PLANET 4O FIND THE POSITION THE DEVICE CAN USE '03 7I &I AND CELLULAR RADIO EACH OF THEM WITH A DIFFERENT LEVEL DECREASING OF PRECISION BALANCED BY THE PHONE ACCORDING TO THE STATE OF BATTERY AND PRECISION REQUIRED BY THE APPLICATION 4HE RECIPES IN THIS CHAPTER DESCRIBE HOW TO DO THE FOLLOWING v
2ESETTING A FORM BY SHAKING THE PHONE
v
#REATE A SEISMOGRAPH
v
)NDICATE THE USERS POSITION ON A MAP
v
$ISPLAY THE TIME OF SUNRISE AND SUNSET
v
)NDICATE THE USERS POSITION WITH COORDINATES
v
5SE THE RADIO
2ESETTING A FORM BY SHAKING THE PHONE &OR THIS FIRST RECIPE WE CHOSE TO CREATE A COOL USER INTERACTION IN ORDER TO PROVIDE A BETTER USER EXPERIENCE 58 7HEN THE DEVICE IS SHAKEN WE WANT ALL THE TEXT IN THE TEXT BOXES TO BE ERASED !S YOU KNOW PEOPLE ARE FASCINATED BY FEATURES THAT MAKE A DEVICES FUNCTIONALITY MORE INTERESTING )N THIS EXAMPLE YOU WILL USE A DATA FORM BUT YOU COULD TAKE THIS CODE AND PUT IT FOR EXAMPLE IN A 3UDOKU GAME )N THAT CASE CREATING A NEW SCHEMA WHEN SHAKING THE PHONE WOULD BE SIMPLE AND REQUIRES ONLY A CHANGE OF THE ALGORITHM INSIDE THE METHOD THAT RESETS THE TEXT BOXES
0ROBLEM 9OU NEED TO DETECT THE SHAKING OF THE DEVICE ALONG THE X AXIS
3OLUTION 9OU MUST USE THE 0RRT[Ta^\TcTa CLASS SUBSCRIBE TO THE EVENT ATPSX]V2WP]VTS AND MANAGE THE PHONES MOVEMENTS
(OW )T 7ORKS !N ACCELEROMETER IS AN INSTRUMENT CAPABLE OF DETECTING ANDOR MEASURING ACCELERATION 4HE ACCELEROMETER OF 7INDOWS 0HONE IS ACCESSIBLE THANKS TO THE 0RRT[Ta^\TcTa CLASS WHICH SIMPLY EXPOSES METHODS TO BEGIN BcPac AND END Bc^_ THE USE OF THE ACCELEROMETER AND THE EVENT THAT WILL NOTIFY YOU THAT THE VALUES READ FROM THE DEVICE HAVE CHANGED ! FUNDAMENTAL THING TO BE TAKEN INTO CONSIDERATION IS THE SCALE OF VALUES THAT CAN BE REPORTED BY THE INSTRUMENT ALONG THE X Y AND Z AXIS WHICH HAVE A LOWER LIMIT OF n AND AN UPPER LIMIT OF
4HE #ODE )TS USELESS TO TELL YOU ONE MORE TIME HOW TO CREATE A NEW PROJECT AT THIS POINT IN THE BOOK AND SO WELL START DIRECTLY WITH THE CODE THAT INTERESTS US THEN START CREATING A NEW 3ILVERLIGHT APPLICATION FOR 7INDOWS 0HONE &OR THE USER INTERFACE 5) YOU WILL HAVE ONLY A SET OF FOUR TEXT BOXES THAT CONTAIN INFORMATION FOR .AME 3URNAME 3TREET AND #ITY +6aXS g)=P\T,2^]cT]c?P]T[ 6aXSA^f, <PaVX], ! 6aXSA^fB_P],%+6aXSA^f3TUX]XcX^]b+A^f3TUX]XcX^] 7TXVWc,'+A^f3TUX]XcX^] 7TXVWc,' +A^f3TUX]XcX^] 7TXVWc,' +A^f3TUX]XcX^] 7TXVWc,' +A^f3TUX]XcX^] 7TXVWc,' +A^f3TUX]XcX^] 7TXVWc, +6aXSA^f3TUX]XcX^]b+CTgc1^g =P\T,=P\TCTgc1^g CTgc,CTgc1[^RZ +CTgc1^g =P\T,Bda]P\TCTgc1^g CTgc,CTgc1[^RZ 6aXSA^f, +CTgc1^g =P\T,BcaTTcCTgc1^g CTgc,CTgc1[^RZ 6aXSA^f,! +CTgc1^g =P\T,2XchCTgc1^g CTgc,CTgc1[^RZ 6aXSA^f," +CTgc1[^RZ CTgc,BWPZT c^ aTbTc 6aXSA^f,# ETacXRP[0[XV]\T]c,2T]cTa 7^aXi^]cP[0[XV]\T]c,2T]cTa+6aXS4HE FIRST CLASS THAT YOU MUST KNOW ABOUT IS 0RRT[Ta^\TcTa WHICH ALLOWS YOU TO ACCESS THE FUNCTIONALITY THAT YOU NEED )TS IMPORTANT TO SAY HOW THE MOVEMENTS ARE INTERPRETED BY THE DEVICE !SSUMING THAT YOU HAVE YOUR 7INDOWS 0HONE IN YOUR HAND IN PORTRAIT POSITION THE MOVEMENT ALONG THE X AXIS IS CONSIDERED POSITIVE IF YOU MOVE THE PHONE TO THE RIGHT AND NEGATIVE IF YOU MOVE THE PHONE TO THE LEFT -OVEMENT ALONG THE Y AXIS IS RELATIVE TO MOVING THE PHONE UP IN A POSITIVE DIRECTION AND
DOWN IN A NEGATIVE DIRECTION -OVEMENT ALONG THE Z AXIS OCCURS WHEN YOU MOVE THE PHONE TOWARD YOU POSITIVE AND AWAY FROM YOU NEGATIVE
■ .OTE 4HE 0RRT[Ta^\TcTa CLASS WHICH GIVES YOU ACCESS TO ACCELEROMETER FUNCTIONALITY IS CONTAINED IN THE NAMESPACE <XRa^b^Uc3TeXRTBT]b^ab AND TO USE IT YOU MUST ADD A REFERENCE TO THE <XRa^b^Uc3TeXRT BT]b^ab ASSEMBLY
!S YOU CAN SEE FROM THE CLASS DIAGRAM SHOWN IN &IGURE THERE IS AN EVENT TO BE SUBSCRIBED TO ATPSX]V2WP]VTS 4HIS EVENT IS TRIGGERED EVERY TIME THE REFERENCE VALUES OF THE ACCELEROMETER CHANGE AND BASED ON THE ACCELEROMETERS HIGH DEGREE OF ACCURACY THOSE VALUES WILL CHANGE OFTEN !T THE CLASS LEVEL YOU NEED TO DECLARE THESE MEMBERS 0RRT[Ta^\TcTa PRRT[Ta^\TcTa , ]d[[* aT_aTbT]cb cWT cX\T ^U cWT UXabc bXV]XUXRP]c \^eT\T]c 3PcTCX\T>UUbTc \^eT\T]c<^\T]c , ]Tf 3PcTCX\T>UUbTc* S^dQ[T UXabcBWPZTBcT_ , * aT_aTbT]cb cWT eP[dT ^U cWT UXabc bXV]XUXRP]c \^eT\T]c 9OU WILL SEE SOON WHY YOU NEED THESE TWO MEMBERS .EXT YOU WILL WRITE A PRIVATE METHOD NAMED INIT!CCELEROMETER THAT YOU WILL CALL JUST AFTER 8]XcXP[XiT2^\_^]T]cb IN THE PAGE CONSTRUCTOR 4HIS METHOD WILL BE RESPONSIBLE FOR INITIALIZING ALL YOU NEED FOR THE ACCELEROMETER SUCH AS THE SUBSCRIPTION TO THE ATPSX]V2WP]VTS EVENT _aXePcT e^XS X]Xc0RRT[Ta^\TcTa j PRRT[Ta^\TcTa , ]Tf 0RRT[Ta^\TcTa* PRRT[Ta^\TcTaATPSX]V2WP]VTS , ]Tf 4eT]c7P]S[Ta+0RRT[Ta^\TcTaATPSX]V4eT]c0aVb-0RRT[Ta^\TcTaNATPSX]V2WP]VTS* PRRT[Ta^\TcTaBcPac* cWXb RP] QT S^]T X] P Qdcc^]NR[XRZ l 4HE PRECEDING CODE IS SELF EXPLANATORY BUT NOTE THAT WITH THE LAST LINE YOU ACTUALLY STARTED THE USE OF THE ACCELEROMETER "UT LETS SHOW IN DETAIL WHAT YOU WILL DO WITH THIS ACCELEROMETER BY USING THE EVENT HANDLER e^XS 0RRT[Ta^\TcTaNATPSX]V2WP]VTS^QYTRc bT]STa 0RRT[Ta^\TcTaATPSX]V4eT]c0aVb T j _dc WTaT cWT R^ST c^ STcTRc P bWPZT l
&IGURE $IAGRAM OF CLASSES USED BY THE ACCELEROMETER !SSUMING THAT BY SHAKE WE MEAN A FAST MOVEMENT LARGE ENOUGH ALONG THE X AXIS THE CODE THAT ALLOWS US TO IDENTIFY A MOVEMENT OF THIS TYPE MAKES USE OF A PRECISE TIMESTAMP IN ORDER TO ACCESS THE ACTUAL POSITION RELATIVE TO THE STARTING POINT OF THE PHONE AT ALL TIMES 4HIS CODE IS AS FOLLOWS e^XS 0RRT[Ta^\TcTaNATPSX]V2WP]VTS^QYTRc bT]STa 0RRT[Ta^\TcTaATPSX]V4eT]c0aVb T j XU cWT \^eT\T]c cPZTb [Tbb cWP] $ \X[[XbTR^]Sb XU TCX\TbcP\_BdQcaPRc\^eT\T]c<^\T]c3daPcX^]C^cP[<X[[XbTR^]Sb +, $ j XU TG +, kk TG -, UXabcBWPZTBcT_ +,
!LL THIS CODE IS BASED ON A MATHEMATICAL CALCULATION TO DETERMINE THE MAGNITUDE OF MOVEMENT ALONG THE X AXIS YOU CAN TEST IT MOVING THE PHONE ALONG THE Y AND Z AXIS "UT WHY DO YOU NEED TO WRITE 3T_[^h\T]c2daaT]c3Xb_PcRWTa1TVX]8]e^ZT ,- ATbTcCTgc1^g )TS SIMPLE v
,- ATbTcCTgc1^g REPRESENTS A DELEGATE TO THE ATbTcCTgc1^g METHOD
v
3T_[^h\T]c2daaT]c3Xb_PcRWTa1TVX]8]e^ZT IS USED TO EXECUTE 0RcX^] ON THE SAME THREAD OF THE 5) )F YOU TRY TO CALL A METHOD THAT WORKS ON 5) ELEMENTS WITHOUT THIS METHODOLOGY YOU WILL RECEIVE AN h)NVALID CROSS THREAD ACCESSv ERROR
&INALLY YOU MUST IMPLEMENT THE ATbTcCTgc1^g METHOD _aXePcT e^XS ATbTcCTgc1^g j cWXb=P\TCTgc1^gCTgc , * cWXbBda]P\TCTgc1^gCTgc , * cWXbBcaTTcCTgc1^gCTgc , * cWXb2XchCTgc1^gCTgc , * l 4HERE IS SOMETHING IMPORTANT TO NOTE ABOUT THIS CODE 7ITH THIS CODE YOU STARTED TO USE THE ACCELEROMETER BUT YOU NEVER STOPPED IT 4HAT MEANS YOU WILL BE USING THIS SENSOR FOR THE ENTIRE TIME THAT YOUR APPLICATION IS WORKING 4HIS IS A BAD PRACTICE BECAUSE THE APPLICATION WILL CONSUME TOO MUCH BATTERY POWER )T IS BECOMING INCREASINGLY IMPORTANT TO OFFER THE BEST USER EXPERIENCE POSSIBLE )F THE USER THINKS THAT THE APPLICATION REQUIRES AN EXCESSIVE USE OF RESOURCES THAT USER MIGHT SIMPLY DELETE IT
5SAGE )N THIS RECIPE YOU NEED A PHYSICAL DEVICE TO TEST THE APPLICATION )NDEED YOU CANNOT USE THE EMULATOR TO TEST THE ACCELEROMETER #ONNECT YOUR UNLOCKED DEVICE SEE 2ECIPE FOR MORE INFORMATION ON HOW TO UNLOCK DEVICES AND RUN THE APPLICATION FROM 6ISUAL 3TUDIO -AKE SURE THAT THE TARGET OUTPUT IS SET TO 7INDOWS 0HONE $EVICE 7RITE SOMETHING IN THE TEXT BOXES SHAKE THE PHONE AND THEN CHECK THAT YOUR FORM HAS BEEN ERASED
#REATING A 3EISMOGRAPH 0ROBLEM 9OU WANT TO CREATE A SEISMOGRAPH BY MERGING INTO A SINGLE PROJECT THE USE OF -ICROSOFT 8.! DRAWING CAPABILITIES WITH THE SENSITIVITY OF THE ACCELEROMETER 4HE ACCELEROMETER HAS A LIMITED RANGE FROM n TO ON THE SCALE OF VALUES ON THE AXIS BUT HAVE A HIGH PRECISION OF FLOATING POINT NUMBERS BEYOND THE POINT
3OLUTION 9OU NEED TO USE THE ACCELEROMETER CAPABILITIES IN ASSOCIATION WITH THE 8.! FRAMEWORK
(OW )T 7ORKS 4HE USE OF THE ACCELEROMETER IN OUR APPLICATIONS IS A STANDARD NOW 5SERS REQUIRE GREATER INTERACTION WITH DEVICES 4HINK OF THESE DEVICES AS TRENDY CONSOLES ON WHICH USERS WANT MORE CONTROL AND PARTICIPATION THEY ARE NO LONGER THE OLD #OMMODORE JOYSTICKS 3HAKES AND FINGER GESTURES ARE JUST SOME OF THE INTERACTIONS THAT USERS WANT IN ORDER TO FEEL AT THE HEART OF WHAT THEY ARE DOING 4HEREFORE IT IS TIME TO ADAPT OUR APPLICATIONS TO KEEP IN SYNC WITH THE TIMES AND PROVIDE A RICHER USER EXPERIENCE /KAY ITS TIME TO GET SERIOUS )N THIS EXAMPLE YOU WILL LEARN HOW TO ACCESS AND USE THE ACCELEROMETER IN YOUR GAMES TO PROVIDE USER INTERACTION "Y FOLLOWING THE CONCEPTS USED IN THESE RECIPES YOU CAN MAKE HIGH INTERACTION GAMES FOR A BETTER EXPERIENCE FOR YOUR GAMERS 3O THAT WE DONT LOSE TOO MUCH TIME IN EXPLAINING WHAT GAMES YOU CAN CREATE AND HOW YOU CAN USE YOUR OWN IDEAS 3O ENOUGH WITH THE TALK ,ETS START TO WRITE CODE
4HE #ODE 4HIS SECTION DOES NOT EXPLAIN THE BASICS FOR WORKING WITH 8.! BECAUSE DOING SO WOULD REQUIRE ANOTHER ENTIRE BOOK )NSTEAD IT EXPLAINS WHAT YOU NEED TO DO IN ORDER TO READ THE OSCILLATIONS OF THE PHONE AND TO TURN THOSE OSCILLATIONS INTO A LINE ON THE SCREEN /BVIOUSLY THAT READ DATA CAN BE APPLIED TO EVERY OTHER ASPECT OF ANY OTHER APPLICATION THAT YOU WANT TO WRITE 3O LETS GO !S A FIRST STEP ADD A NEW B_aXcT5^]c IN THE PROJECT OF THE CONTENTS AUTOMATICALLY CREATED BY PROJECT TEMPLATE WHICH WITH HIS DEFAULT CONTENT MUST BE GOOD ENOUGH +G]P2^]cT]c g\[]b)6aP_WXRb,<XRa^b^UcG]P5aP\Tf^aZ2^]cT]c?X_T[X]T6aP_WXRb+0bbTc Ch_T,6aP_WXRb)5^]c3TbRaX_cX^]+ <^SXUh cWXb bcaX]V c^ RWP]VT cWT U^]c cWPc fX[[ QT X\_^acTS +5^]c=P\T-BTV^T D8 <^]^+5^]c=P\T+ BXiT Xb P U[^Pc eP[dT \TPbdaTS X] _^X]cb <^SXUh cWXb eP[dT c^ RWP]VT cWT bXiT ^U cWT U^]c +BXiT- #+BXiT+ B_PRX]V Xb P U[^Pc eP[dT \TPbdaTS X] _XgT[b <^SXUh cWXb eP[dT c^ RWP]VT cWT P\^d]c ^U b_PRX]V X] QTcfTT] RWPaPRcTab +B_PRX]V-+B_PRX]V+ DbT:Ta]X]V R^]ca^[b cWT [Ph^dc ^U cWT U^]c 8U cWXb eP[dT Xb cadT ZTa]X]V 8]U^a\PcX^] fX[[ QT dbTS fWT] _[PRX]V RWPaPRcTab
+DbT:Ta]X]V-cadT+DbT:Ta]X]V+ Bch[T R^]ca^[b cWT bch[T ^U cWT U^]c EP[XS T]caXTb PaT ATVd[Pa 1^[S 8cP[XR P]S 1^[S 8cP[XR P]S PaT RPbT bT]bXcXeT +Bch[T-ATVd[Pa+Bch[T+ 2WPaPRcTaATVX^]b R^]ca^[ fWPc [TccTab PaT PePX[PQ[T X] cWT U^]c 4eTah RWPaPRcTa Ua^\ BcPac c^ 4]S fX[[ QT QdX[c P]S \PST PePX[PQ[T U^a SaPfX]V CWT STUPd[c aP]VT Xb Ua^\ "! 0B288 b_PRT c^ !% m R^eTaX]V cWT QPbXR ;PcX] RWPaPRcTa bTc CWT RWPaPRcTab PaT ^aSTaTS PRR^aSX]V c^ cWT D]XR^ST bcP]SPaS +2WPaPRcTaATVX^]b+2WPaPRcTaATVX^]+BcPac-"!*+BcPac+4]S- !%*+4]S+2WPaPRcTaATVX^]+2WPaPRcTaATVX^]b+0bbTc+G]P2^]cT]c!FTER CREATING THIS FONT THE OTHER CONTENT YOU NEED IS A ¾ PIXEL IMAGE THAT WILL BE THE TEXTURE OF YOUR LINE !T THIS POINT THERE IS NOTHING IN THE DESIGN OF #ONTENTS SO GO TO THE HEART OF THE ACTION TO THE CODE IN THE Rb FILE OF OUR GAME &IRST OF ALL REMEMBER TO RESOLVE <XRa^b^Uc3TeXRTbBT]b^ab AND THEN ADD ALWAYS AT THE CLASS LEVEL A MEMBER OF TYPE 0RRT[Ta^\TcTa THAT WILL BE THE DATA PROVIDER 4HIS TIME YOU HAVE AN AVAILABLE METHOD THAT IS CALLED 8]XcXP[XiT WHICH IS THE IDEAL PLACE TO DO ALL YOUR INITIALIZATIONS PRRT[Ta^\TcTa , ]Tf 0RRT[Ta^\TcTa* PRRT[Ta^\TcTaATPSX]V2WP]VTS , ]Tf 4eT]c7P]S[Ta+0RRT[Ta^\TcTaATPSX]V4eT]c0aVb-PRRT[Ta^\TcTaNATPSX]V2WP]VTS* PRRT[Ta^\TcTaBcPac* )N THE EVENT HANDLER THE FIRST THING YOU DO IS CALCULATE THE MAGNITUDE OF OSCILLATION INCREASING BY THE SCALE BECAUSE AS YOU REMEMBER THE ACCELEROMETER IS EXTREMELY SENSITIVE BUT ASSUMES VALUES FROM n TO FOR EACH AXIS THAT COMPARED TO THE SCREEN RESOLUTION ARE LITTLE THING e^XS PRRT[Ta^\TcTaNATPSX]V2WP]VTS^QYTRc bT]STa 0RRT[Ta^\TcTaATPSX]V4eT]c0aVb T j S^dQ[T \PV]XcdST ,
*
"UT WHAT YOU DO WITH THIS MAGNITUDE AFTER IT IS CALCULATED 7ELL ITgS CLEAR )T WILL BE THE VALUE OF REFERENCE FOR YOUR SWING "UT BEFORE USING IT TO DRAW YOU NEED TO TAKE A FEW PRELIMINARY STEPS &IRST AT THE CLASS LEVEL DEFINE SOME MEMBERS AS FOLLOWS ETacTg1dUUTa eTacTg1dUUTa , ]d[[* CTgcdaT!3 _^X]cCTgcdaT , ]d[[* ;Xbc+ETacTg?^bXcX^]2^[^a- eTacXRTb , ]d[[* B_aXcT5^]c U^]c , ]d[[* S^dQ[T PRcdP[G* S^dQ[T PRcdP[H* S^dQ[T PRcdP[I* U[^Pc \Pg
h?^bXcX^] THAT REPRESENTS THE OFFSET RELATIVE TO THE Y AXIS OF THE GRAPH /THERWISE YOU WOULD HAVE A CHART THAT STAYS TOO HIGH ON THE SCREEN
v
eTacTg1dUUTa IS YOUR hSUMMITSv BUFFER WHERE YOU WILL LOAD THE VERTICES TO BE DRAWN
v
eTacXRTb IS THE VERTEX LIST THAT YOUgLL DRAW +EEP IN MIND THAT YOU COULD USE AN ARRAY FOR GREATER CONSISTENCY WITH THE METHODS USED BUT WE ARE MORE COMFORTABLE WORKING WITH A LIST AND THEN CONVERTING THE ARRAY WHEN NECESSARY
v
_^X]cCTgcdaT AND U^]c ARE PART OF THE TOPICS THAT ARE NOT COVERED IN THIS CHAPTER IN DETAIL 9OU NEED TO KNOW ONLY THAT THE CLASS WILL BE USED TO LOAD THE TEXTURE CREATED EARLIER IN #ONTENTS PROJECT AND TO LOAD THE PRECEDING FONTS
4HE OTHER FIELDS WE WOULD DARE CALL THEM DIAGNOSTIC AND YOU NEED THEM TO SEE THE ONSCREEN INFORMATION ABOUT THE STATUS OF THE ACCELEROMETER AS YOU GO FORWARD IN THE EXECUTION .EXT WITH ALL THESE ELEMENTS SET TO NULL SOMETHING IN THE INITIALIZATION METHOD MUST BE CHANGED AS FOLLOWS eTacTg1dUUTa , ]Tf ETacTg1dUUTaVaP_WXRb6aP_WXRb3TeXRT ch_T^UETacTg?^bXcX^]2^[^a 1dUUTaDbPVT=^]T* eTacXRTb , ]Tf ;Xbc+ETacTg?^bXcX^]2^[^a-* 4HERE ARE STILL LOADS OF FONTS AND TEXTURES 4HE BEST PLACE FOR THEM IS THE ;^PS2^]cT]c METHOD _^X]cCTgcdaT , cWXb2^]cT]c;^PS+CTgcdaT!3-_^X]c* U^]c , cWXb2^]cT]c;^PS+B_aXcT5^]c-BXb\^5^]c*
!ND THE CODE OF THE EVENT HANDLER BECOMES SOMEWHAT MORE FULL BODIED e^XS PRRT[Ta^\TcTaNATPSX]V2WP]VTS^QYTRc bT]STa 0RRT[Ta^\TcTaATPSX]V4eT]c0aVb T j S^dQ[T \PV]XcdST ,
*
ETacTg?^bXcX^]2^[^a eTacTg , ]Tf ETacTg?^bXcX^]2^[^a]Tf ETRc^a" h?^bXcX^] U[^Pc\PV]XcdST 2^[^aFWXcT* eTacXRTb0SSeTacTg* PRcdP[G , TG* PRcdP[H , TH* PRcdP[I , TI* ;Xbc+ETacTg?^bXcX^]2^[^a- ]TfETacXRTb , ]Tf ;Xbc+ETacTg?^bXcX^]2^[^a-* U^a X]c X , * X + eTacXRTb2^d]c* X j ETacTg?^bXcX^]2^[^a eTa , eTacXRTbJXL* eTa?^bXcX^]G , * ]TfETacXRTb0SSeTa* l eTacXRTb , ]TfETacXRTb* XU eTacXRTb2^d]c - &(( eTacXRTbAT\^eT0c* l 3TEP BY STEP WHAT YOU DO IS AS FOLLOWS
#ALCULATE AS BEFORE THE MAGNITUDE OF THE VIBRATION
#HECK IF IT IS GREATER THAN THE EVENT OCCURRED AND IF YOU KEEP IT IN THE VARIABLE
#REATE A NEW VERTEX WITH X AND Y MAGNITUDE YOUR OFFSET
3ET THE FIELDS WITH THE VALUES OF THE DISCLOSURES MADE BY THE ACCELEROMETER
#REATE A LIST OF THE SAME TYPE OF SUMMITS WHERE ITEMS POURING OF THE ORIGINAL LIST INCREASING WITH EVERY ELEMENTS OF THE VALUE ON THE X AXIS AND BY ALLOCATING AND REPLACES THE ORIGINAL LIST
7ITH THE LAST YOU ENSURE THAT YOU WILL NEVER HAVE MORE VERTICES NEEDED TO SHOW THE INFORMATION ONSCREEN IN THIS CASE WE ARE NOT AT ALL INTERESTED IN HAVING A HISTORY OF WHAT HAPPENED
3O FAR YOU HAVE CALCULATED THE POSITION OF THE VARIOUS SUMMITS AND THIS MEANS THAT NOW THE VERTICES ARE READY TO BE DRAWN !S YOU KNOW 8.! IS BASED ON TWO METHODS D_SPcT AND 3aPf THAT ARE INVOKED CYCLICALLY ABOUT TIMES PER SECOND )N THE D_SPcT METHOD YOU WILL PREPARE THE DATA IN THE BUFFER TO BE DRAW WHILE 3aPf WILL CONCRETELY DO WORK OF SHOW VERTEXES ON VIDEO
_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* U^aRT aTPSX]V PRRT[Ta^\TcTa SPcP PRRT[Ta^\TcTaNATPSX]V2WP]VTS]d[[ ]d[[* XU eTacXRTb2^d]c - eTacXRTb2^d]c + ' eTacTg1dUUTaBTc3PcP+ETacTg?^bXcX^]2^[^a-eTacXRTbC^0aaPh* * QPbTD_SPcTVP\TCX\T* l 4HIS IS NOT COMPLICATED TO UNDERSTAND YOU ARE SETTING DATA IN eTacTg1dUUTa TAKING THEM FROM THE eTacXRTb COLLECTION 7HILE THINGS GET COMPLICATED BUT SHORT IN THE 3aPf METHOD _a^cTRcTS ^eTaaXST e^XS 3aPf6P\TCX\T VP\TCX\T j 6aP_WXRb3TeXRT2[TPa2^[^a1[PRZ* b_aXcT1PcRW1TVX]* XU eTacXRTb2^d]c - j U^a X]c X , * X + eTacXRTb2^d]c * X j ETacTg?^bXcX^]2^[^a e , eTacXRTbJXL* ETacTg?^bXcX^]2^[^a e! , eTacXRTbJX L* SaPf;X]T ]Tf ETRc^a!e ?^bXcX^]G e!?^bXcX^]G ]Tf ETRc^a!e ?^bXcX^]H e!?^bXcX^]H e 2^[^a* l b_aXcT1PcRW3aPfBcaX]VU^]c bcaX]V5^a\Pc2^d]c) jleTacXRTb2^d]c ]Tf ETRc^a!! ! 2^[^aATS* b_aXcT1PcRW3aPfBcaX]VU^]c bcaX]V5^a\PcG)jl PRcdP[G ]Tf ETRc^a!! # 2^[^a?TPRW?dUU* b_aXcT1PcRW3aPfBcaX]VU^]c bcaX]V5^a\PcH)jl PRcdP[H ]Tf ETRc^a!! % 2^[^a?TPRW?dUU* b_aXcT1PcRW3aPfBcaX]VU^]c bcaX]V5^a\PcI)jl PRcdP[I ]Tf ETRc^a!! ' 2^[^a?TPRW?dUU* b_aXcT1PcRW3aPfBcaX]VU^]c bcaX]V5^a\Pc
!GAIN STEP BY STEP HERE IS WHAT YOU DO IN THIS METHOD
#LEAN THE OLD SCREEN
$RAW THE OPERATIONS
)F YOU HAVE MORE THAN ONE VERTEX SCROLL THE ARRAY OF VERTICES PASSING EVERY VERTICE AS A PARAMETER TO THE SaPf;X]T METHOD THE COORDINATES OF THE CURRENT POINT AND OF THE POINT IMMEDIATELY AFTER 4HATgS THE REASON WHY YOU DO THIS IF YOU HAVE MORE THAN ONE VERTEX
3HOW ON VIDEO THANKS TO THE 3aPfBcaX]V METHOD DISPLAYING THE INFORMATION THAT YOU HAVE FOUND FOR DIAGNOSTIC PURPOSES
#LOSE THE BATCH DATA PREPARATION AND PAINT EVERYTHING 0b h^d RP] bTT fT RP[[ P \TcW^S ]P\TS SaPf;X]T cWPc cWT R^ST Xb QT[^f e^XS SaPf;X]TETRc^a! e ETRc^a! e! 2^[^a R^[^a j U[^Pc [T]VWc , ETRc^a!3XbcP]RTe e!* b_aXcT1PcRW3aPf_^X]cCTgcdaT ]Tf ATRcP]V[TX]ce G X]ce!G R^[^a* l
4HE SaPf;X]T METHOD DOES NOTHING MORE THAN CREATE MANY SMALL RECTANGLES ¾ PIXELS AT A POSITION IDENTIFIED BY THE VECTORS THAT CONSTITUTE YOUR LINE
5SAGE &ROM 6ISUAL 3TUDIO PRESS #TRL& AND WAIT FOR THE APPLICATION TO BE DEPLOYED AND STARTS ON YOUR DEVICE 0UT THE PHONE ON YOUR TABLE"EGIN TO SIMULATE AN EARTHQUAKE BY HITTING THE TABLE BE CAREFUL DONT HIT TOO HARD YOU MIGHT GET HURT
)NDICATING THE 5SERS 0OSITION 0ROBLEM 9OU WANT AN APPLICATION OR GAME THAT GIVES INFORMATION ABOUT THE AREA WHERE YOUR USER IS LOCATED &OR A GAME YOU COULD CHOOSE TO LET THE USER PLAY IN THE CITY WHERE THE USER IS LOCATED AGAINST OTHER PLAYERS AROUND THERE
3OLUTION 4O SOLVE THIS PROBLEM YOULL USE A CONTROL THAT USES "ING -APS TAILORED FOR 70 BUT MUCH MORE IMPORTANT OF HOW YOU WILL SHOW DATA IS HOW YOU WILL GET THEM THANKS TO THE 6T^2^^aSX]PcTFPcRWTa CLASS CONTAINED IN THE NAMESPACE BhbcT\3TeXRT;^RPcX^]
(OW )T 7ORKS 4HE 6T^2^^aSX]PcTFPcRWTa CLASS PROVIDES LOCATION DATA BASED ON COORDINATES OF LATITUDE AND LONGITUDE ,IKE OTHER SENSORS THE CYCLE IS DEFINED BY THE BcPac METHOD WHICH ENABLES YOU TO ACCESS TO THE ?^bXcX^] PROPERTY AND ENABLE THE ?^bXcX^]2WP]VTS EVENT AND Bc^_ WHICH PREVENTS 6T^2^^aSX]PcTFPcRWTa FROM PROVIDING EVENTS AND DATA ON THE POSITION
4HE #ODE !S YOU CAN SEE IN &IGURE THE CONSTRUCTOR HAS AN OVERLOAD THAT ENABLES YOU TO SPECIFY THE DEGREE OF ACCURACY THAT YOU WANT IN DETERMINING THE USERS LOCATION THE PROPERTY 3TbXaTS0RRdaPRh IS READ ONLY )F YOU SET THE ACCURACY TO 7XVW YOU WILL HAVE A MORE PRECISE LOCATION OF THE USER BUT THIS REQUIRES MORE RESOURCES THAT WILL EASILY DISCHARGE THE BATTERY 4HEREFORE USE THIS SETTING ONLY IF NEEDED BECAUSE YOU DONT WANT TO RISK THE USER REJECTING YOUR APPLICATION BECAUSE IT IS TOO RESOURCE INTENSIVE
&IGURE #LASS DIAGRAM OF 6T^2^^aSX]PcTFPcRWTa
4HERE ARE TWO IMPORTANT EVENTS THAT YOU MUST TAKE INTO CONSIDERATION v v
?^bXcX^]2WP]VTS BcPcdb2WP]VTS
4HEN WE START TO SEE THE PRIVATE METHOD THAT INITIALIZE THE 6T^2^^aSX]PcTFPcRWTa AND SUBSCRIBES THE TWO EVENTS WITH OUR HANDLERS _aXePcT e^XS 8]XcFPcRWTa j VT^FPcRWTa , ]Tf 6T^2^^aSX]PcTFPcRWTa6T^?^bXcX^]0RRdaPRh7XVW* VT^FPcRWTa?^bXcX^]2WP]VTS , ]Tf 4eT]c7P]S[Ta+6T^?^bXcX^]2WP]VTS4eT]c0aVb+6T^2^^aSX]PcT--VT^FPcRWTaN?^bXcX^]2WP]VTS* VT^FPcRWTaBcPcdb2WP]VTS , ]Tf 4eT]c7P]S[Ta+6T^?^bXcX^]BcPcdb2WP]VTS4eT]c0aVb-VT^FPcRWTaNBcPcdb2WP]VTS* l 4HE RESPECTIVE HANDLER IS AS FOLLOWS e^XS VT^FPcRWTaNBcPcdb2WP]VTS^QYTRc bT]STa 6T^?^bXcX^]BcPcdb2WP]VTS4eT]c0aVb T j 7P]S[T WTaT cWT RWP]VT ^U bcPcdb l e^XS VT^FPcRWTaN?^bXcX^]2WP]VTS^QYTRc bT]STa 6T^?^bXcX^]2WP]VTS4eT]c0aVb+6T^2^^aSX]PcT- T j 7P]S[T WTaT cWT RWP]VT ^U _^bXcX^] l ,ET US EXPLAIN THE PURPOSE OF THESE THOW EVENT HANDLERS v
VT^FPcRWTaNBcPcdb2WP]VTS TAKES CARE OF NOTIFYING THAT THE STATUS OF 6T^2^^aSX]PcTFPcRWTa HAS CHANGED
v
VT^FPcRWTaN?^bXcX^]2WP]VTS IS THE MOST IMPORTANT 4HE EVENT HANDLER IS CALLED WHEN THE ?^bXcX^]2WP]VTS EVENT OCCURS AND COMMUNICATES VIA 6T^2^^aSX]PcT THE NEW LOCATION
4HE 6T^2^^aSX]PcT CLASS HAS SEVERAL INTERESTING FIELDS THAT PROVIDE IMPORTANT INFORMATION AS YOU CAN SEE IN FIGURE SUCH AS ALTITUDE LATITUDE AND LONGITUDE IDENTIFYING THE POSITION THAT WILL BE SET TO =0= UNTIL THE 7ATCHER STATUS WILL NOT BECOME aTPSh !NOTHER INTERESTING PROPERTY IS THE SPEED WHICH WOULD BE USEFUL IF YOU WANTED TO CREATE A NAVIGATION SYSTEM
!LL YOU NEED TO DO TO RESOLVE YOUR PROBLEM QUICKLY IS TO WRITE THIS CODE e^XS VT^FPcRWTaN?^bXcX^]2WP]VTS^QYTRc bT]STa 6T^?^bXcX^]2WP]VTS4eT]c0aVb+6T^2^^aSX]PcT- T j 1X]V
&IGURE #LASSES USED TO HANDLE 6T^2^^aSX]PcT
7HAT IF YOU DONT WANT TO USE "ING -APS TO SHOW THE USERS POSITION ON A MAP 9OU CAN USE -ICROSOFT 2ESEARCH -APS AVAILABLE AT Wcc_)\ba\P_bR^\STUPd[cPb_g )N THIS CHAPTER YOU WILL NOT SEE HOW TO INTERACT WITH THIS SERVICE LOOK FOR THAT INFORMATION IN #HAPTER )NSTEAD YOUR FOCUS WILL BE DIRECTED TO THE DATA BOTH AT HOW TO GET IT FROM ,OCATION 3ERVICES AND AT HOW TO USE IT TO FIND THE USERS EXACT SPOT !FTER YOU ADD A REFERENCE TO THE SERVICE AVAILABLE FROM Wcc_)\ba\P_bR^\CTaaPBTaeXRT!Pb\g WE WILL EXPLAIN THE CONFIGURATION LATER YOU CAN BEGIN TO LOOK AT THE CODE 4HE STRUCTURE OF THE 5) WILL LOOK LIKE THIS +6aXS g)=P\T,;Ph^dcA^^c 1PRZVa^d]S,CaP]b_PaT]c+6aXSA^f3TUX]XcX^]b+A^f3TUX]XcX^] 7TXVWc,0dc^+A^f3TUX]XcX^] 7TXVWc,+6aXSA^f3TUX]XcX^]b+CXc[T?P]T[ R^]cPX]b cWT ]P\T ^U cWT P__[XRPcX^] P]S _PVT cXc[T+BcPRZ?P]T[ g)=P\T,CXc[T?P]T[ 6aXSA^f, <PaVX], ! &!'+BcPRZ?P]T[ >aXT]cPcX^],7^aXi^]cP[+CTgc1[^RZ CTgc,;^RPcX^] BTaeXRT Bch[T,jBcPcXRATb^daRT ?W^]TCTgc=^a\P[Bch[Tl+CTgc1[^RZ g)=P\T,;^RPcX^]BcPcdbCTgc1^g CTgc, Bch[T,jBcPcXRATb^daRT ?W^]TCTgc=^a\P[Bch[Tl+BcPRZ?P]T[+BcPRZ?P]T[+2^]cT]c?P]T[ _[PRT PSSXcX^]P[ R^]cT]c WTaT+6aXS g)=P\T,2^]cT]c?P]T[ 6aXSA^f, +6aXS+6aXS4HERES SOMETHING OBVIOUSLY STRANGE IN THIS INTERFACE AT FIRST GLANCE 4HE 6aXS 2^]cT]c?P]T[ IS EMPTY BUT ONLY BECAUSE INSIDE THE CODE YOU WILL CREATE A KIND OF MOSAIC )N THE CODE BEHIND YOU WILL NEED A SERIES OF dbX]V STATEMENTS dbX]V BhbcT\3TeXRT;^RPcX^]* dbX]V BhbcT\FX]S^fb
8]XcXP[XiT2^\_^]T]c* 8]XiXP[XiTBTaeXRTb* ;^PSTS , ]Tf A^dcTS4eT]c7P]S[Ta
v
FIRING THE EVENT VT^FPcRWTaN?^bXcX^]2WP]VTS WILL MAKE A REQUEST BY CALLING THE METHOD 6Tc0aTP5a^\?c IN THE PROXY
v
WHETHER SUCCESSFUL OR UNSUCCESSFUL WILL FIRE _a^ghN6Tc0aTP5a^\?c2^\_[TcTS EVENT
v
WHICH IN THE CASE OF A CORRECT ANSWER WILL CALL THE 6TcCX[T METHOD OF THE PROXY WITH THE CONSEQUENT TRIGGER OF THE EVENT _a^gh N 6TcCX[T2^\_[TcTS
4HEN WE START FROM THE FIRST STEP IMPLEMENTING VT^FPcRWTaN?^bXcX^]2WP]VTS e^XS VT^FPcRWTaN?^bXcX^]2WP]VTS^QYTRc bT]STa 6T^?^bXcX^]2WP]VTS4eT]c0aVb+6T^2^^aSX]PcT- T j XU T?^bXcX^];^RPcX^]8bD]Z]^f] j _a^gh6Tc0aTP5a^\?c cWT 0RcdP[?^bXcX^] ]Tf CTaaPBTaeXRT;^];Pc?c j ;Pc , T?^bXcX^];^RPcX^];PcXcdST ;^] , T?^bXcX^];^RPcX^];^]VXcdST l cWT ch_T ^U \P_ cWT bRP[T ^U X\PVT aTRTXeTS CTaaPBTaeXRTBRP[TBRP[T!Z\ X]c2^]cT]c?P]T[0RcdP[FXScW X]c2^]cT]c?P]T[0RcdP[7TXVWc* l l 4HE PURPOSE OF THIS RECIPE WAS TO SHOW YOU HOW THE ,OCATION 3ERVICE BASED ON A UNIVERSAL STANDARD FOR LOCALIZATION ENABLES YOU TO ACCESS WITHOUT TOO MUCH TROUBLE INFORMATION ABOUT THE DEVICES POSITION IN THE WORLD
5SAGE &ROM 6ISUAL 3TUDIO PRESS #TRL& 7AIT FOR THE APPLICATION TO START ON THE PHONE AND THEN WAIT THAT THE POSITION IS AVAILABLE THEN LOOK THAT THE POSITION ON THE MAP CHANGES RELATING YOUR ACTUAL POSITION
$ISPLAYING 3UNSET AND 3UNRISE 0ROBLEM 9OUR AIM IS TO OBTAIN AN APPLICATION THAT IS ABLE TO TELL THE USER WHAT TIME THE SUN WILL RISE AND SET TODAY IN THE USERS LOCATION
3OLUTION 4HERE ARE SEVERAL WAYS TO FIND OUT THE TIME OF SUNRISE AND SUNSET FOR EXAMPLE THROUGH WEB SERVICES LIBRARIES AND COMPLEX CALCULATIONS 4HIS RECIPE SHOWS HOW TO ACCESS AND USE A CERTAIN PROPERTY IN ORDER TO EXPLORE THE POTENTIAL OF ,OCATION 3ERVICES 4HERE ARE SEVERAL WAYS TO CALCULATE THE TIMES FROM LATITUDE AND LONGITUDE VALUES AND WE WILL LET YOU CHOOSE WHICH BEST SUITS YOUR NEEDS
(OW )T 7ORKS 9OU WILL USE INFORMATION ABOUT THE USERS POSITION OBTAINED FROM THE DEVICE TO CALCULATE THE TIME OF SUNRISE AND SUNSET SIMULATING WITH A HELPER CLASS THE BEHAVIOR OF A SERVICE TO CALCULATE THEM
4HE #ODE 4O START WRITING CODE FOR THIS RECIPE WE NEED TWO MEMBERS FIELD 6T^2^^aSX]PcTFPcRWTa VT^ , ]Tf 6T^2^^aSX]PcTFPcRWTa* Bd]cX\Tb7T[_Ta bbR , ]Tf Bd]cX\Tb7T[_Ta* Bd]cX\Tb7T[_Ta IS A CLASS WRITTEN BY US WHOSE CODE IS BASED ON ALGORITHMS THAT ARE EASILY AVAILABLE ON THE )NTERNET 4HIS CLASS EXPOSES TWO METHODS CALLED 6TcBd]AXbT AND 6TcBd]BTc AS YOU CAN SEE IN &IGURE
&IGURE #LASS DIAGRAM OF Bd]cX\Tb7T[_Ta e^XS VT^N?^bXcX^]2WP]VTS^QYTRc bT]STa 6T^?^bXcX^]2WP]VTS4eT]c0aVb+6T^2^^aSX]PcT- T j XU T?^bXcX^];^RPcX^]8bD]Z]^f] j Q^^[ XbBd]aXbT , UP[bT* Q^^[ XbBd]bTc , UP[bT* 3PcTCX\T bd]aXbT , Bd]cX\Tb7T[_Ta6TcBd]AXbTT?^bXcX^];^RPcX^];PcXcdST T?^bXcX^];^RPcX^];^]VXcdST 3PcTCX\T=^f ^dc XbBd]aXbT* 3PcTCX\T bd]bTc , Bd]cX\Tb7T[_Ta6TcBd]BTcT?^bXcX^];^RPcX^];PcXcdST T?^bXcX^];^RPcX^];^]VXcdST 3PcTCX\T=^f ^dc XbBd]bTc* VT^Bc^_ l l )T IS IMPORTANT WHEN WORKING WITH THE POSITION TO POINT OUT THAT THE APPLICATIONS USED FOR LOCALIZING CONSUME BATTERY POWER !LTHOUGH WE MAY SOUND REPETITIVE IT IS IMPORTANT TO PROVIDE THE BEST POSSIBLE USER INTERACTION IN OUR APPLICATIONS 4HEREFORE REMEMBER TO STOP THE USE OF 6T^2^^aSX]PcTFPcRWTa WHEN YOU DONT NEED IT ANYMORE
5SAGE &ROM 6ISUAL 3TUDIO DEPLOY THE APPLICATION TO A PHYSICAL DEVICE AND WATCH IT CALCULATING SUNRISE AND SUNSET FROM YOUR POSITION
)NDICATING THE 5SERS 0OSITION VIA #OORDINATES 0ROBLEM !T APPLICATION STARTUP YOU WANT TO LOCALIZE BY POSITION OF THE PHONE TO SEE WHERE IN THE WORLD IS AND WHAT IS THE RELATIVE ADDRESS
3OLUTION 4HE SOLUTION TO THIS PROBLEM IS VERY SIMPLE IF YOU USE CLASSES AVAILABLE IN 7INDOWS 0HONE (OWEVER THE OFFICIAL SOLUTION IS UNUSABLE AT THIS TIME BECAUSE 2XeXR0SSaTbbATb^[eTa WAS SCHEDULED TO BE INCLUDED IN 3ILVERLIGHT FOR 7INDOWS 0HONE AND USING 2XeXR0SSaTbbATb^[eTa YOU CAN DISCLOSE TO OBTAIN A 2XeXR0SSaTbb BY USING THE GEO COORDINATES 4HIS METHOD HAS NOT YET BEEN IMPLEMENTED (OWEVER IN THIS SECTION WE WILL SHOW YOU WHAT TO DO SO WHEN THE METHOD IS IMPLEMENTED YOU WILL BE READY TO INTEGRATE FEATURES THAT CAN USE IT -EANWHILE WE WILL SHOW YOU AN ALTERNATIVE IMPLEMENTATION OF THIS SERVICE
(OW )T 7ORKS !S IN THE PREVIOUS RECIPE RETRIEVING THE USERS POSITION ON THE MAP BASED ON GEO COORDINATES WILL BE SIMPLE 9OU WILL USE CERTAIN CLASSES IN THE NAMESPACE ASSOCIATED WITH THE CIVIC BhbcT\3TeXRT;^RPcX^] TO RETRIEVE COORDINATES THAT WE ARE PROVIDING
4HE #ODE !S YOU CAN SEE IN &IGURE THE 2XeXR0SSaTbbATb^[eTa CLASS IMPLEMENTS THE 82XeXR0SSaTbbATb^[eTa INTERFACE 4HEREFORE EVEN IF THE SERVICE IS NOT IMPLEMENTED YET YOU MIGHT THINK THE REALIZATION OF OUR RESOLVER RATHER THAN WAIT FOR SUBSEQUENT IMPLEMENTATIONS JUST AS YOU WILL DO SHORTLY "UT LETS PROCEED STEP BY STEP
&IGURE #LASS DIAGRAM FOR 2XeXR0SSaTbbATb^[eTa AND ITS RESPECTIVE DATA CLASS &IRST DECLARE AT THE CLASS LEVEL THESE TWO MEMBERS 6T^2^^aSX]PcTFPcRWTa VT^FPcRWTa , ]d[[* 82XeXR0SSaTbbATb^[eTa RXeXRATb^[eTa , ]d[[* .EXT CREATE TWO PRIVATE VOID METHODS DEDICATED TO INITIALIZE THE PRECEDING MEMBERS v
8]XcFPcRWTa
v
8]XcATb^[eTa
4HE NAMES THAT WE CHOOSEN IS SELF EXPLAINING SAYS US ALL THAT YOU WILL DO IN THEIR IMPLEMENTATION THAT YOU CAN SEE BELOW _aXePcT e^XS 8]XcATb^[eTa j U^a ]^f fT fX[[ dbT cWT STUPd[c X\_[T\T]cPcX^] RXeXRATb^[eTa , ]Tf 2XeXR0SSaTbbATb^[eTa* RXeXRATb^[eTaATb^[eT0SSaTbb2^\_[TcTS , ]Tf 4eT]c7P]S[Ta+ATb^[eT0SSaTbb2^\_[TcTS4eT]c0aVb-RXeXRATb^[eTaNATb^[eT0SSaTbb2^\_[TcTS* l
_aXePcT e^XS 8]XcFPcRWTa j VT^FPcRWTa , ]Tf 6T^2^^aSX]PcTFPcRWTa6T^?^bXcX^]0RRdaPRh7XVW* VT^FPcRWTa?^bXcX^]2WP]VTS , ]Tf 4eT]c7P]S[Ta+6T^?^bXcX^]2WP]VTS4eT]c0aVb+6T^2^^aSX]PcT--VT^FPcRWTaN?^bXcX^]2WP]VTS* VT^FPcRWTaBcPcdb2WP]VTS , ]Tf 4eT]c7P]S[Ta+6T^?^bXcX^]BcPcdb2WP]VTS4eT]c0aVb-VT^FPcRWTaNBcPcdb2WP]VTS* VT^FPcRWTaBcPac* l 4HE USE OF 8]XcFPcRWTa IS CLEAR BECAUSE YOU HAVE SEEN IT IN PREVIOUS RECIPES 8]XcATb^[eTa INDICATES THAT THE CLASS 2XeXR0SSaTbbATb^[eTa WILL MAKE A CALL TO SOME EXTERNAL SERVICE AND WILL RAISE THE >]ATb^[eT0SSaTbb2^\_[TcTS EVENT WHEN IT HAS FINISHED FINDING THE INFORMATION YOU NEED e^XS VT^FPcRWTaN?^bXcX^]2WP]VTS^QYTRc bT]STa 6T^?^bXcX^]2WP]VTS4eT]c0aVb+6T^2^^aSX]PcT- T j ePa RXeXR , RXeXRATb^[eTaATb^[eT0SSaTbbT?^bXcX^];^RPcX^]* l e^XS RXeXRATb^[eTaNATb^[eT0SSaTbb2^\_[TcTS^QYTRc bT]STa ATb^[eT0SSaTbb2^\_[TcTS4eT]c0aVb T j S^ b^\TcWX]V fXcW aTb^[eTS PSSaTbb WTaT h^d RP] bTT cWT _a^_TacXTb cWPc h^d RP] PRRTbb T0SSaTbb0SSaTbb;X]T T0SSaTbb0SSaTbb;X]T! T0SSaTbb1dX[SX]V T0SSaTbb2Xch T0SSaTbb2^d]cahATVX^] T0SSaTbb5[^^a;TeT[ T0SSaTbb?^bcP[2^ST T0SSaTbbBcPcT?a^eX]RT l 4HIS IS ALL YOU NEED TO DO TO USE 2XeXR0SSaTbbATb^[eTa )TS SIMPLE TO USE THIS CLASS BUT IS ALSO USELESS BECAUSE BEHIND OF THIS CLASS THERE IS NO IMPLEMENTATION 4HEREFORE WE HAVE GIVEN YOU A WAY TO IMPLEMENT A SERVICE SIMILAR TO WHAT -ICROSOFT HAS PLANNED BUT hHOMEMADEv 9OU WILL NEED TO USE A "ING -APS SERVICE FROM Wcc_)\bS]\XRa^b^UcR^\T]db[XQaPah RR(%%&"'Pb_g AND THEN ADD A SERVICE REFERENCE TO THE 'EOCODE 3ERVICE IF YOU DONT KNOW HOW TO DO THAT LOOK AT #HAPTER &IRST ADD A NEW CLASS TO YOUR PROJECT AND CALL IT 2dbc^\2XeXRATb^[eTa _dQ[XR R[Pbb 2dbc^\0SSaTbbATb^[eTa ) 82XeXR0SSaTbbATb^[eTa j _dQ[XR 2XeXR0SSaTbb ATb^[eT0SSaTbb6T^2^^aSX]PcT R^^aSX]PcT j q l
_dQ[XR e^XS ATb^[eT0SSaTbb0bh]R6T^2^^aSX]PcT R^^aSX]PcT j q l _dQ[XR TeT]c 4eT]c7P]S[Ta+ATb^[eT0SSaTbb2^\_[TcTS4eT]c0aVb- ATb^[eT0SSaTbb2^\_[TcTS* j l 9OU WILL IMPLEMENT ONLY ATb^[eT0SSaTbb0bh]R SIMPLY BECAUSE YOU ARE USING 3ILVERLIGHT FOR 7INDOWS PHONE AND SO ARE NOT INTERESTED IN THE SYNCHRONOUS PATTERN 9OU DECLARE AT THE GLOBAL CLASS LEVEL THE PROXY FOR THE SERVICE 6T^R^STBTaeXRT6T^R^STBTaeXRT2[XT]c _a^gh , ]d[[* !ND YOU MUST WRITE THE CONSTRUCTOR OF THE CLASS WHERE YOU WILL INSTANTIATE THE PROXY AND SUBSCRIBE TO THE EVENT >]ATeTabT6T^R^ST2^\_[TcTS _dQ[XR 2dbc^\0SSaTbbATb^[eTa j _a^gh , ]Tf 6T^R^STBTaeXRT6T^R^STBTaeXRT2[XT]c1PbXR7cc_1X]SX]VN86T^R^STBTaeXRT* _a^ghATeTabT6T^R^ST2^\_[TcTS , ]Tf 4eT]c7P]S[Ta+6T^R^STBTaeXRTATeTabT6T^R^ST2^\_[TcTS4eT]c0aVb- _a^ghNATeTabT6T^R^ST2^\_[TcTS* l 4HEN ITS TIME TO PREPARE YOUR REQUEST TO THE SERVICE AND PREPARE YOUR SERVICE TO RESPOND TO THE REQUEST THAT WILL COME FROM THE OUTSIDE _dQ[XR e^XS ATb^[eT0SSaTbb0bh]R6T^2^^aSX]PcT R^^aSX]PcT j _a^ghATeTabT6T^R^ST0bh]R ]Tf 6T^R^STBTaeXRTATeTabT6T^R^STAT`dTbc j ;^RPcX^] , ]Tf <XRa^b^Uc?W^]T2^]ca^[b
e^XS _a^ghNATeTabT6T^R^ST2^\_[TcTS^QYTRc bT]STa 6T^R^STBTaeXRTATeTabT6T^R^ST2^\_[TcTS4eT]c0aVb T j ATb^[eT0SSaTbb2^\_[TcTS bT]STa ]Tf ATb^[eT0SSaTbb2^\_[TcTS4eT]c0aVb ]Tf 2XeXR0SSaTbb j 0SSaTbb;X]T , TATbd[cATbd[cbJL0SSaTbb0SSaTbb;X]T 0SSaTbb;X]T! , TATbd[cATbd[cbJL0SSaTbb5^a\PccTS0SSaTbb 1dX[SX]V , 2Xch , TATbd[cATbd[cbJL0SSaTbb;^RP[Xch 2^d]cahATVX^] , TATbd[cATbd[cbJL0SSaTbb2^d]cahATVX^] 5[^^a;TeT[ , ?^bcP[2^ST , TATbd[cATbd[cbJL0SSaTbb?^bcP[2^ST BcPcT?a^eX]RT , TATbd[cATbd[cbJL0SSaTbb?^bcP[C^f] l T4aa^a T2P]RT[[TS TDbTaBcPcT* l 7HEN THE ATeTabT6T^R^ST2^\_[TcTS FIRES YOU ALSO FIRE THE EVENT ATb^[eT0SSaTbb2^\_[TcTS MEMBER OF THE 82XeXR0SSaTbbATb^[eTa INTERFACE THAT WILL BE TRIGGERED BY WHO USES THIS CLASS !S YOU CAN SEE YOU CANT ADD SOME INFORMATION IN 2XeXR0SSaTbb SUCH AS 1dX[SX]V AND 5[^^a;TeT[ BUT IF YOU ARENT WRITING AN APPLICATION TO TRACK THE POSITION OF A COURIER WE THINK YOU CAN DO WELL WITHOUT THIS INFORMATION AND IT IS STILL BETTER THAN NOT HAVING THE ABILITY TO RETRIEVE INFORMATION
5SAGE &ROM 6ISUAL 3TUDIO START THE APPLICATION 7AIT FOR YOUR POSITION TO BECOME AVAILABLE AND THEN LOOK FOR RETRIEVED ADDRESSES WHILE YOU MOVE AROUND THE GLOBE 2EMEMBER IN ORDER TO USE 0OSITION IN YOUR APPLICATION YOU MUST ACTIVATE IT IN THE SETTINGS OR YOU WILL NEVER HAVE CORRECT INFORMATION TO WORK FROM
5SING THE 2ADIO 0ROBLEM 9OU WANT TO CREATE A COMPLETE &-2ADIO APPLICATION THAT IS DIFFERENT FROM THE STANDARD RADIO INCLUDED IN THE 7INDOWS 0HONE -USIC HUB
3OLUTION 9OU MUST USE THE 5<APSX^ CLASS INCLUDED IN 7INDOWS 0HONE TO ACCESS RADIO FUNCTIONALITIES )N JUST A FEW STEPS YOU CAN HAVE A COMPLETE RADIO THAT YOU CAN TUNE INTO VARIOUS STATIONS
(OW )T 7ORKS 4HE <XRa^b^Uc3TeXRTbAPSX^ NAMESPACE CONTAINS THE CLASS 5<APSX^ WHICH IMPLEMENTS THE SINGLETON PATTERN )N THIS WAY THERE IS ONLY ONE POINT OF ACCESS TO THE RADIO !0) 4O TUNE THE RADIO YOU MUST CHANGE THE FREQUENCY PROPERTY OF 5<APSX^8]bcP]RT AND IF YOU WANT TO IMPLEMENT A SEEK FUNCTIONALITY YOU MUST CHECK FOR 3IGNAL 3TRENGTH ALSO KNOWN AS A 2ECEIVED 3IGNAL 3TRENGTH )NDICATOR OR 233)
4HE #ODE #REATE A PROJECT FOR 7INDOWS 0HONE BY USING 6ISUAL 3TUDIO AND CALL IT %NHANCED 2ADIO !FTER THE TEMPLATE IS CREATED ADD A FOLDER NAMED )MAGES TO THE SOLUTION !S YOU CAN IMAGINE IN THIS FOLDER YOU WILL ADD SOME PICTURES TO CREATE THE USER INTERFACE )N THIS CASE YOU HAVE THE FOUR PICTURES SHOWN IN &IGURE !FTER THIS PRELIMINARY OPERATION YOU WILL NEED TO ADD A REFERENCE TO THE 7INDOWS 0HONE 4OOLKIT ASSEMBLY TO USE THE C^VV[TBfXcRW CONTROL
&IGURE /UR IMAGES !T THE TOP OF YOUR APPLICATION INSIDE CXc[T?P]T[ YOU NEED TWO COLUMNS )N THE FIRST COLUMN WILL BE A TOGGLE BUTTON THAT STARTS AND STOPS THE RADIO OF COURSE IF THE RADIO IS ALREADY STARTED THE TOGGLE MUST BE SELECTED )N THE SECOND COLUMN IS A SLIDER THAT REPRESENTS THE SIGNAL STRENGTH INDICATOR 4O CREATE THIS USER INTERFACE YOU WILL USE THE FOLLOWING 8!-, +6aXS g)=P\T,CXc[T?P]T[ 6aXSA^f, <PaVX], ! &!'+6aXS2^[d\]3TUX]XcX^]b+2^[d\]3TUX]XcX^] FXScW,!$ +2^[d\]3TUX]XcX^] FXScW, 6aXS2^[d\]3TUX]XcX^]b+B[XSTa 6aXS2^[d\], g)=P\T,BXV]P[B[XSTa 5^aTVa^d]S,jBcPcXRATb^daRT ?W^]T0RRT]c1adbWl
+1dcc^] 7^aXi^]cP[0[XV]\T]c,AXVWc 7TXVWc,'% FXScW, % =P\T,1PRZfPaS1dcc^] 2[XRZ,1PRZfPaS1dcc^]N2[XRZ+8\PVT B^daRT,8\PVTb1PRZfPaS_]V +1dcc^]+1dcc^] 7^aXi^]cP[0[XV]\T]c,AXVWc 7TXVWc,'% FXScW, % =P\T,5^afPaS1dcc^] 2[XRZ,5^afPaS1dcc^]N2[XRZ+8\PVT B^daRT,8\PVTb5^afPaS_]V +1dcc^]+1dcc^] 7^aXi^]cP[0[XV]\T]c,AXVWc 7TXVWc,'% FXScW, % =P\T,5Pbc5^afPaS1dcc^] 2[XRZ,5Pbc5^afPaS1dcc^]N2[XRZ+8\PVT B^daRT,8\PVTb5Pbc5^afPaS_]V +1dcc^]+BcPRZ?P]T[+BcPRZ?P]T[!S YOU CAN SEE YOU ARE CREATING IMAGE BUTTONS BY USING THE PROCESS YOU LEARNED IN #HAPTER 4HE ONLY THING TO EXPLAIN IN THIS 8!-, IS THE USE OF THE STYLE FOR THE 5aT`dT]RhCTgc1[^RZ ANOTHER THING THAT YOU CAN SEE IN #HAPTER 4HAT IS COMPOSED BY THE FOLLOWING 8!-, +Bch[T g):Th,5aT`dT]RhCTgc1[^RZBch[T CPaVTcCh_T,CTgc1[^RZ+BTccTa ?a^_Tach,5^]cBXiT EP[dT,$%+BTccTa ?a^_Tach,5^]c5P\X[h EP[dT,
_dQ[XR
!S YOU CAN SEE YOU HAVE INTRODUCED A METHOD TO MANAGE WHAT TO DO WHEN THE RADIO IS NOT AVAILABLE )N THIS CASE YOU SHOW A MESSAGE BOX (OWEVER IT IS USEFUL TO DO THIS CALLING A METHOD BECAUSE YOU WILL MANAGE THE EXCEPTION THAT CAN COME FROM ALL METHODS IN ONLY ONE POINT OF YOUR CODE 'IVEN THAT YOU CAN CHANGE THE ACTUAL FREQUENCY OF THE RADIO IN SEVERAL PLACES WITH DIFFERENT BUTTONS AND YOU HAVE TO VERIFY THE CORRECTNESS OF ANY MODIFICATION WE PREFER TO USE A METHOD TO DO IT FOR EVERYONE !ND THIS IS CALLED
_aXePcT Q^^[ 8b5aT`dT]Rh2^aaTRcS^dQ[T UaT`dT]Rh j bcaX]V bT_PaPc^a , 2d[cdaT8]U^2daaT]c2d[cdaT=d\QTa5^a\Pc=d\QTa3TRX\P[BT_PaPc^a* Q^^[ Xb2^aaTRc , UP[bT* bcaX]V UaT`dT]Rh0bBcaX]V ,
RPcRW APSX^3XbPQ[TS4gRT_cX^] Tg j
5SAGE &ROM 6ISUAL 3TUDIO START THE APPLICATION BY PRESSING & 3TART USING THE RADIO CHANGING THE FREQUENCY SEEKING A STRONG SIGNAL AND THEN TRYING TO SEE HOW WILL CHANGE THE SIGNAL STRENGTH IF YOU MOVE ALL AROUND
CHAPTER ■■■
Media Management )N THIS CHAPTER YOU WILL FIND RECIPES DEDICATED TO MEDIA MANAGEMENT )NDEED AUDIO AND VIDEO ARE TWO OF THE BEST RESOURCES PROVIDED BY YOUR PHONE AND AS A DEVELOPER THERE ARE SO MANY COOL TRICKS AND TIPS YOU SHOULD KNOW IN ORDER TO PRODUCE BOTH EAR CATCHING AND EYE CATCHING APPLICATIONS v
4HE RECIPES IN THIS CHAPTER DESCRIBE HOW TO DO THE FOLLOWING 4AKE A PHOTO FROM YOUR PHONE CAMERA AND UPLOAD IT TO THE &LICKR SITE
v
0ICK A PHOTO FROM YOUR MEDIA LIBRARY AND UPLOAD IT TO THE &LICKR SITE
v
5SE 7INDOWS -EDIA 0LAYER TO SHUFFLE SONGS IN YOUR MEDIA LIBRARY
v
5SE THE MICROPHONE IN THE &UNNY 2EPEATER APPLICATION
v
5SE THE
v
!DD INTEGRATION WITH THE -USIC 6IDEOS HUB
4AKING A 0HOTO FROM 9OUR 0HONE #AMERA 0ROBLEM 9OU NEED TO TAKE A PHOTO FROM YOUR APPLICATION WITHOUT PRESSING THE HARDWARE #AMERA BUTTON PROVIDED BY THE PHONE
3OLUTION 9OU HAVE TO USE THE 2P\TaP2P_cdaTCPbZ CHOOSER WHICH PROVIDES THE BW^f METHOD USED TO PROGRAMMATICALLY SHOW THE SAME CAMERA APPLICATION THAT IS EXECUTED BY THE HARDWARE #AMERA PHONE BUTTON
(OW )T 7ORKS !S YOU LEARNED IN #HAPTER CHOOSERS ARE USED TO RUN EXTERNAL NATIVE 7INDOWS 0HONE APPLICATIONS OR TASKS 4HE MAIN DIFFERENCE AS COMPARED TO LAUNCHERS IS THAT CHOOSERS RETURN DATA TO YOUR PROGRAM /N THE CONTRARY A CHOOSER SUCH AS 2P\TaP2P_cdaTCPbZ OPENS THE PHOTO CAMERA ON THE DEVICE AND RETURNS THE PHOTO TAKEN FROM THE CAMERA TO YOUR APPLICATION 4HE 2P\TaP2P_cdaTCPbZ CLASS PROVIDES THE BW^f METHOD WHICH IS RESPONSIBLE FOR RUNNING THE EXTERNAL APPLICATION THAT ENABLES YOU TO TAKE A PICTURE FROM THE CAMERA AND TO SET SOME OPTIONS SUCH AS FLASH ONOFF AND ZOOM !FTER THE PICTURE IS TAKEN 2P\TaP2P_cdaTCPbZ RAISES THE 2^\_[TcTS EVENT THAT YOUR APPLICATION CAN HOOK IN ORDER TO HAVE INFORMATION ON THE PHOTO )NDEED THE ?W^c^ATbd[c EVENT ARGUMENT PROVIDED BY THIS EVENT CONTAINS VERY IMPORTANT INFORMATION ABOUT THE PHOTO SUCH AS THE TEMPORARY PATH WHERE IT HAS BEEN STOREDTHE >aXVX]P[5X[T=P\T PROPERTYAND THE STREAM CONTAINING THE DATA OF THE PHONETHE 2W^bT]?W^c^ PROPERTY
4HE #ODE 4O DEMONSTRATE THE USE OF THE PHOTO CAMERA WE HAVE CREATED AN APPLICATION THAT ENABLES US TO TAKE A PICTURE AND UPLOAD IT TO AN ACCOUNT ON THE &LICKR SITE 9OU HAVE ALREADY SEEN PART OF THIS APPLICATION IN ACTION IN #HAPTER 2ECIPE ABOUT ANIMATING A SPLASH SCREEN /PEN 6ISUAL 3TUDIO AND LOAD THE 5[XRZa?W^c^0[Qd\ APPLICATION )N THE
e^XS RP\TaPN2^\_[TcTS^QYTRc bT]STa ?W^c^ATbd[c T j 0__ P__ , 0__[XRPcX^]2daaT]c Pb 0__* XU TCPbZATbd[c ,, CPbZATbd[c>: j QhcTJL SPcP* dbX]V ePa Qa , ]Tf 1X]PahATPSTaT2W^bT]?W^c^ SPcP , QaATPS1hcTbX]cT2W^bT]?W^c^;T]VcW* P__bTccX]Vb8\PVT , ]Tf
■ .OTE )N THE PRECEDING CODE YOU CAN SEE THE 0__ CLASS HAVING THE bTccX]Vb PROPERTY 4HIS PROPERTY POINTS TO AN OBJECT FROM THE BTccX]Vb CLASS THAT WE ADDED TO CONTAIN USEFUL INFORMATION TO BE SHARED WITH ALL THE PAGES WITHIN THE APPLICATION
)N THE
■ .OTE "ECAUSE !0) AND SECURITY KEYS ARE PRIVATE YOU WILL NOT FIND OURS IN THE CODE 9OU HAVE TO REGISTER YOUR APPLICATION ON &LICKR AND USE YOURS IN THE &LICKR CLASSS CONSTRUCTOR
_dQ[XR _PacXP[ R[Pbb 0__ ) 0__[XRPcX^] j +bd\\Pah ?a^eXSTb TPbh PRRTbb c^ cWT a^^c UaP\T ^U cWT ?W^]T 0__[XRPcX^] +bd\\Pah +aTcda]b-CWT a^^c UaP\T ^U cWT ?W^]T 0__[XRPcX^]+aTcda]b_dQ[XR ?W^]T0__[XRPcX^]5aP\T A^^c5aP\T j VTc* _aXePcT bTc* l _aXePcT 5[XRZa=Tc5[XRZa NU[XRZa* _dQ[XR 5[XRZa=Tc5[XRZa 5[XRZaBTaeXRT j VTc j aTcda] NU[XRZa*
l l
NU[XRZa , ]Tf 5[XRZa=Tc5[XRZaP_X:Th bTRdaT:Th* "ECAUSE YOUR APPLICATION WILL BE USED BY DIFFERENT USERS WHO WANT TO UPLOAD PHOTOS ON THEIR ACCOUNTS THE FIRST THING YOU NEED TO DO IN YOUR CODE IS TO AUTHENTICATE THE USER 4HIS IS ACCOMPLISHED ADDING A FTQ1a^fbTa CONTROL TO THE
T[bT j PbTccX]Vb5a^Q , aATbd[c* bcaX]V da[ , U[XRZa0dcW2P[RDa[PbTccX]Vb5a^Q 0dcW;TeT[FaXcT* DaX daX , ]Tf DaXda[* fQ1a^fbTa=PeXVPcTdaX* l l* l* l 4HE NEXT STEP IS RETRIEVING THE AUTHENTICATION TOKEN AFTER THE USER IS AUTHENTICATED AT THE &LICKR SITE 4HE 0dcW6TcC^ZT]0bh]R METHOD ACCEPTS THE 5a^Q IDENTIFIER AND LIKE 0dcW6Tc5a^Q0bh]R ACCEPTS A CALLBACK FUNCTION THAT IS CALLED BY THIS ASYNC METHOD AFTER THE AUTHORIZATION PROCESS IS FINISHED %VEN IN THIS METHOD WE USED A LAMBDA EXPRESSION AS AN INLINE CALLBACK FUNCTION )F NO ERRORS OCCUR SOME BUTTONS ARE ENABLED AND THE AUTHORIZATION TOKEN KEY IS STORED IN THE APPLICATION SETTINGS _aXePcT e^XS Qc]0dcWT]cXRPcTN2[XRZ^QYTRc bT]STa A^dcTS4eT]c0aVb T j 0__ P__ , 0__[XRPcX^]2daaT]c Pb 0__* P__5[XRZaBTaeXRT0dcW6TcC^ZT]0bh]RP__bTccX]Vb5a^Q a ,j 3Xb_PcRWTa1TVX]8]e^ZT ,j XU a7Pb4aa^a j
_aXePcT e^XS 1dcc^]N2[XRZ^QYTRc bT]STa A^dcTS4eT]c0aVb T j XU cgc=P\TCTgc ,, bcaX]V4\_ch j
5SAGE 7ITH 6ISUAL 3TUDIO OPENED SET THE TARGET OUTPUT TO 7INDOWS 0HONE %MULATOR AND PRESS #TRL& 4HE EMULATOR STARTS BRIEFLY SHOWING THE ANIMATED SPLASH SCREEN -EANWHILE THE APPLICATION IS REQUIRING THE 5a^Q IDENTIFIER AND USES IT TO CALCULATE THE 52, 7HEN THIS PROCESS IS ACCOMPLISHED THE MAIN PAGE IS SHOWN WITH THE FTQ1a^fbTa CONTROL FILLED WITH THE &LICKR PAGE SEE &IGURE
&IGURE 4HE 5[XRZa?W^c^0[Qd\ APPLICATION IN ACTION !FTER INSERTING YOUR &LICKR CREDENTIALS AND ACCEPTING THAT THE 5[XRZa?W^c^0[Qd\ APPLICATION CAN ACCESS YOUR ACCOUNT YOU CAN PRESS THE !UTHENTICATE BUTTON )F THE PROCESS DOESNT RETURN ERRORS THE 4AKE ! 0ICTURE BUTTON WILL BE ENABLED 0RESS THIS BUTTON AND YOU WILL SEE THE EMULATOR SIMULATING THE 7INDOWS 0HONE #AMERA APPLICATION SEE &IGURE 4HE EMULATOR WILL SHOW A MOVING SQUARE SIMULATING A MOVING TARGET "Y PRESSING THE TOP RIGHT ICON YOU CAN TAKE A PHOTO SHOT
■ .OTE )F YOU ARE USING THE 7INDOWS 0HONE DEVICE WITH :UNE RUNNING AND CONNECTED YOU WILL NOT BE ABLE TO ACCOMPLISH THIS STEP BECAUSE :UNE SOFTWARE LOCKS THE CAMERA 9OU HAVE TO SHUT :UNE DOWN AND USE THE 70#ONNECT TOOL THAT YOU CAN FIND IN THE ?a^VaP\ 5X[TbK<XRa^b^Uc B3:bKFX]S^fb ?W^]TKe&K C^^[bKF?2^]]TRc PATH 4HIS TOOL IS AVAILABLE ONLY AFTER HAVING INSTALLED THE 7INDOWS 0HONE $EVELOPER 4OOLS *ANUARY 5PDATE
&IGURE 4HE CAMERA EMULATED BY THE 7INDOWS 0HONE %MULATOR
!FTER TAKING THE PICTURE AND ACCEPTING IT YOU CAN SEE THAT THE 5PLOAD BUTTON IS ENABLED "Y PRESSING THE 5PLOAD BUTTON THE 5PLOAD PAGE IS SHOWN (ERE YOU HAVE TO FILL SOME TEXT BOXES WITH THE PICTURES NAME DESCRIPTION AND TAG SEE &IGURE 0RESS THE 5PLOAD BUTTON MAYBE YOU CANT SEE IT BECAUSE IT IS TOO SMALL TO START THE UPLOAD PROCESS
&IGURE 4HE 5PLOAD PAGE CONTAINS TEXT BOXES USED TO SPECIFY THE PHOTOS NAME DESCRIPTION AND TAG
$EPENDING ON YOUR )NTERNET CONNECTION SPEED AND ITS TRAFFIC AFTER A FEW SECONDS YOU WILL BE INFORMED BY A DIALOG BOX THAT THE UPLOAD HAS BEEN ACCOMPLISHED SEE &IGURE
&IGURE 4HE UPLOAD IS DONE
0ICKING A 0HOTO FROM 9OUR -EDIA ,IBRARY 0ROBLEM 9OU NEED TO PICK A PHOTO FROM YOUR MEDIA LIBRARY AND UPLOAD IT TO THE &LICKR SITE
3OLUTION 9OU HAVE TO USE THE ?W^c^2W^^bTaCPbZ CHOOSER
(OW )T 7ORKS 4HE ?W^c^2W^^bTaCPbZ CHOOSER CLASS PROVIDES THE BW^f METHOD WHICH SHOWS THE PICTURE LIBRARY AND LETS YOU TO PICK A PHOTO FROM IT 7HEN THE PHOTO HAS BEEN CHOSEN THE 2^\_[TcTS EVENT IS RAISED 4HIS EVENT PROVIDES A ?W^c^ATbd[c OBJECT AS A PARAMETER BY USING ITS PROPERTIES YOU CAN RETRIEVE THE STREAM DATA COMPOSING THE PHOTO BY USING THE 2W^bT]?W^c^ PROPERTY OBTAIN THE PATH AND FILENAME OF THE IMAGE BY USING THE >aXVX]P[5X[T=P\T PROPERTY AND THE GET THE RESULT OF THE PHOTO PICKING OPERATION BY USING THE CPbZATbd[c PROPERTY
4HE #ODE 4O DEMONSTRATE THIS RECIPE WE HAVE ENHANCED THE APPLICATION WRITTEN IN 2ECIPE THE 5[XRZa?W^c^0[Qd\ 7E ADDED THE ,OAD BUTTON TO THE
+1dcc^] g)=P\T,Qc]D_[^PS 6aXSA^f,# 2^]cT]c,D_[^PS 2[XRZ,Qc]D_[^PSN2[XRZ 8b4]PQ[TS,5P[bT +6aXS+6aXS)N THE
l &INALLY IN THE Qc];^PSN2[XRZ EVENT HANDLER WE CALL THE BW^f METHOD PROVIDED BY THE ?W^c^2W^^bTaCPbZ CLASS _aXePcT e^XS Qc];^PSN2[XRZ^QYTRc bT]STa A^dcTS4eT]c0aVb T j RW^^bTaBW^f* l
5SAGE 4HE APPLICATION USAGE IS SIMILAR TO 2ECIPE !FTER HAVING AUTHENTICATED TO THE &LICKR SITE AND AUTHORIZED OUR APPLICATION TO ACCESS THE USERS LIBRARY THE ,OAD BUTTON WILL BE ENABLED 0RESS THE ,OAD BUTTON AND THE APPLICATION WILL SHOW THE PICTURES LIBRARY ON YOUR PHONE )N THE EMULATOR YOU CAN ACCESS THE LIBRARY WITH SOME PHOTOS INSIDE AS SHOWN IN &IGURE
&IGURE 4HE PICTURE LIBRARY ON THE EMULATOR .OW SELECT A PICTURE OF YOUR CHOICE AND YOU WILL SEE IT IN THE 5[XRZa?W^c^0[Qd\ APPLICATION AS A PREVIEW 4HE 5PLOAD BUTTON BECOMES ENABLED 0RESS THE 5PLOAD BUTTON AS YOU DID IN 2ECIPE AND THE PICTURE LOADS INTO THE &LICKR SITE AS SHOWN IN &IGURE
&IGURE 4HE PHOTO HAS BEEN UPLOADED TO THE &LICKR SITE
5SING -EDIA 0LAYER TO 3HUFFLE 3ONGS IN 9OUR -EDIA ,IBRARY 0ROBLEM 9OU NEED TO RETRIEVE SONGS FROM THE MEDIA LIBRARY OF YOUR 7INDOWS 0HONE DEVICE AND PLAY THEM IN SHUFFLE MODE
3OLUTION 9OU HAVE TO USE THE
(OW )T 7ORKS 4HE 8.! &RAMEWORK PROVIDES THE
&IGURE 4HE
4HE #ODE 4O DEMONSTRATE THIS RECIPE WE HAVE CREATED THE BWdUU[T
INTERFACE HAS TWO METHOD DEFINITIONS TO START AND TO STOP THE SERVICE )N THE RELATED METHODS YOU ARE GOING TO START AND STOP A 3Xb_PcRWTaCX\Ta TIMER OBJECT 4HIS TIMER HAS AN INTERVAL SET TO TIMES PER SECOND IN WHICH IT RAISES THE CXRZ EVENT "Y DEFINING THE CXRZ EVENT HANDLER YOU CAN CALL THE D_SPcT STATIC METHOD PERIODICALLY _dQ[XR R[Pbb G=03Xb_PcRWTaBTaeXRT ) 80__[XRPcX^]BTaeXRT j _aXePcT 3Xb_PcRWTaCX\Ta UaP\Tf^aZ3Xb_PcRWTaCX\Ta* _dQ[XR e^XS BcPacBTaeXRT0__[XRPcX^]BTaeXRT2^]cTgc R^]cTgc j cWXbUaP\Tf^aZ3Xb_PcRWTaCX\TaBcPac* l _dQ[XR e^XS Bc^_BTaeXRT j cWXbUaP\Tf^aZ3Xb_PcRWTaCX\TaBc^_* l _dQ[XR G=03Xb_PcRWTaBTaeXRT j cWXbUaP\Tf^aZ3Xb_PcRWTaCX\Ta , ]Tf 3Xb_PcRWTaCX\Ta* cWXbUaP\Tf^aZ3Xb_PcRWTaCX\Ta8]cTaeP[ , CX\TB_P]5a^\CXRZb""""""* cWXbUaP\Tf^aZ3Xb_PcRWTaCX\TaCXRZ , UaP\Tf^aZ3Xb_PcRWTaCX\TaNCXRZ* 5aP\Tf^aZ3Xb_PcRWTaD_SPcT* l e^XS UaP\Tf^aZ3Xb_PcRWTaCX\TaNCXRZ^QYTRc bT]STa 4eT]c0aVb T j 5aP\Tf^aZ3Xb_PcRWTaD_SPcT* l l )N THE 0__gP\[ FILE YOU CAN ADD THE NAMESPACE THAT CONTAINS THE G]P3Xb_PcRWTaBTaeXRT CLASS AND INCLUDE A TAG SO THAT THE APPLICATION ITSELF WILL START AND STOP THE TIMER AUTOMATICALLY +0__[XRPcX^] g)2[Pbb,BWdUU[T
+0__[XRPcX^]0__[XRPcX^];XUTcX\T>QYTRcb+AT`dXaTS ^QYTRc cWPc WP]S[Tb [XUTcX\T TeT]cb U^a cWT P__[XRPcX^]+bWT[[)?W^]T0__[XRPcX^]BTaeXRT ;Pd]RWX]V,0__[XRPcX^]N;Pd]RWX]V 2[^bX]V,0__[XRPcX^]N2[^bX]V 0RcXePcTS,0__[XRPcX^]N0RcXePcTS 3TPRcXePcTS,0__[XRPcX^]N3TPRcXePcTS+[^RP[)G=03Xb_PcRWTaBTaeXRT +0__[XRPcX^]0__[XRPcX^];XUTcX\T>QYTRcb+0__[XRPcX^]4HE BWdUU[T
)T MUST CONTINUE TO PLAY AND SHUFFLE SONGS EVEN WHEN THE SCREEN IS LOCKED
v
7HEN ONE SONG IS OVER A NEW ONE MUST BE PLAYED AND IT SHOULDNT BE THE SAME
v
7HEN THE APPLICATION IS TOMBSTONED IT MUST SAVE THE SONGS PROPERTIES SUCH AS ITS TITLE AND ALBUM COVER
v
7HEN THE APPLICATION IS REACTIVATED FROM A TOMBSTONE IT MUST NOT STOP THE CURRENT PLAYED SONG AND MUST AGAIN DISPLAY THE SONGS PROPERTIES
v
7HEN THE HARDWARE "ACK BUTTON IS PRESSED THE APPLICATION MUST STOP PLAYING THE SONG
,ETS EXAMINE THE CODE AND THE SOLUTIONS FOUND TO ADDRESS THOSE POINTS !S YOU SAW IN #HAPTER YOU CAN SET THE 0__[XRPcX^]8S[T3TcTRcX^]<^ST PROPERTY TO 8S[T3TcTRcX^]<^ST3XbPQ[TS SO THAT YOUR APPLICATION DOESNT STOP WORKING WHEN THE SCREEN IS LOCKED CWT bWdUU[T a^dcX]T WPb c^ f^aZ TeT] fWT] cWT bRaTT] Xb [^RZTS ?W^]T0__[XRPcX^]BTaeXRT2daaT]c0__[XRPcX^]8S[T3TcTRcX^]<^ST , 8S[T3TcTRcX^]<^ST3XbPQ[TS* 3ADLY THE
CWT bWdUU[T a^dcX]T WPb c^ f^aZ TeT] fWT] cWT bRaTT] Xb [^RZTS ?W^]T0__[XRPcX^]BTaeXRT2daaT]c0__[XRPcX^]8S[T3TcTRcX^]<^ST , 8S[T3TcTRcX^]<^ST3XbPQ[TS* l e^XS cX\TaNCXRZ^QYTRc bT]STa 4eT]c0aVb T j ?[PhB^]V* l 7HEN THE APPLICATION IS TOMBSTONEDFOR EXAMPLE BY THE USER PRESSING THE HARDWARE 3TART BUTTONTHE APPLICATION MUST STORE IMPORTANT DATA SUCH THE ALBUM COVER AND THE SONGS AUTHOR AND TITLE 3ADLY THE B^]V CLASS IS NOT SERIALIZABLE AND THE SAME IS TRUE FOR THE 1Xc\P_8\PVT CLASS FOR THE ALBUM COVER 9OU NEED TO CREATE THE 0__BTccX]Vb SERIALIZABLE CLASS WITH SPECIFIC INFORMATION SUCH AS THE CXc[T PROPERTY TO STORE THE APPLICATIONS TITLE AND THE 0[Qd\8\PVT BYTES ARRAY TO STORE THE IMAGE ALBUM 4HE LATTER IS THE WAY WE FOUND TO SERIALIZE AN IMAGE )N THE 8bC^\Qbc^]TS PROPERTY YOU SET WHEN THE APPLICATION IS TOMBSTONED &INALLY IN THE B^]V=d\QTa PROPERTY YOU STORE THE SONGS NUMBER GENERATED BY THE SHUFFLE ROUTINE _dQ[XR R[Pbb 0__BTccX]Vb j _dQ[XR Q^^[ 8bC^\Qbc^]TS j VTc* bTc* l _dQ[XR bcaX]V CXc[T j VTc* bTc* l _dQ[XR QhcTJL 0[Qd\8\PVT j VTc* bTc* l _dQ[XR X]c B^]V=d\QTa j VTc* bTc* l l
■ .OTE 9OU COULD STORE ONLY THE B^]V=d\QTa VALUE DURING THE TOMBSTONING AND USE IT TO RETRIEVE THE SONG WHEN THE APPLICATION IS REACTIVATED (OWEVER IN THIS WAY YOU CAN LEARN DIFFERENT TECHNIQUES TO MANAGE IMAGES SERIALIZATION
!N OBJECT FROM THE 0__BTccX]Vb CLASS IS STORED IN THE 0__ APPLICATION CLASS AND YOU CAN RETRIEVE IT BY USING THE RELATED bTccX]Vb PROPERTY _dQ[XR _PacXP[ R[Pbb 0__ ) 0__[XRPcX^] j +bd\\Pah ?a^eXSTb TPbh PRRTbb c^ cWT a^^c UaP\T ^U cWT ?W^]T 0__[XRPcX^] +bd\\Pah +aTcda]b-CWT a^^c UaP\T ^U cWT ?W^]T 0__[XRPcX^]+aTcda]b_dQ[XR ?W^]T0__[XRPcX^]5aP\T A^^c5aP\T j VTc* _aXePcT bTc* l _dQ[XR 0__BTccX]Vb bTccX]Vb j VTc* bTc* l
-OREOVER IN THE 0__ CLASS YOU DEFINE THE EVENT HANDLERS TO MANAGE THE TOMBSTONING 2^ST c^ TgTRdcT fWT] cWT P__[XRPcX^] Xb [Pd]RWX]V TV Ua^\ BcPac CWXb R^ST fX[[ ]^c TgTRdcT fWT] cWT P__[XRPcX^] Xb aTPRcXePcTS _aXePcT e^XS 0__[XRPcX^]N;Pd]RWX]V^QYTRc bT]STa ;Pd]RWX]V4eT]c0aVb T j bTccX]Vb , ]Tf 0__BTccX]Vb* bTccX]Vb8bC^\Qbc^]TS , UP[bT* l 2^ST c^ TgTRdcT fWT] cWT P__[XRPcX^] Xb PRcXePcTS Qa^dVWc c^ U^aTVa^d]S CWXb R^ST fX[[ ]^c TgTRdcT fWT] cWT P__[XRPcX^] Xb UXabc [Pd]RWTS _aXePcT e^XS 0__[XRPcX^]N0RcXePcTS^QYTRc bT]STa 0RcXePcTS4eT]c0aVb T j XU ?W^]T0__[XRPcX^]BTaeXRT2daaT]cBcPcT2^]cPX]b:ThbTccX]Vb j bTccX]Vb , ?W^]T0__[XRPcX^]BTaeXRT2daaT]cBcPcTJbTccX]VbL Pb 0__BTccX]Vb* bTccX]Vb8bC^\Qbc^]TS , cadT* l l 2^ST c^ TgTRdcT fWT] cWT P__[XRPcX^] Xb STPRcXePcTS bT]c c^ QPRZVa^d]S CWXb R^ST fX[[ ]^c TgTRdcT fWT] cWT P__[XRPcX^] Xb R[^bX]V _aXePcT e^XS 0__[XRPcX^]N3TPRcXePcTS^QYTRc bT]STa 3TPRcXePcTS4eT]c0aVb T j ?W^]T0__[XRPcX^]BTaeXRT2daaT]cBcPcTJbTccX]VbL , bTccX]Vb* l 4HE OTHER PROPERTIES PROVIDED BY THE 0__BTccX]Vb CLASS ARE SET IN THE ?[PhB^]V METHOD 4HE FIRST OPERATION IN THIS METHOD CALLS THE 3^BWdUU[T METHOD WHICH RETURNS A B^]V OBJECT 4HIS OBJECT IS COMPARED TO A PREVIOUS B^]V OBJECT STORED AS N[PbcB^]V VARIABLE )F THE OBJECTS ARE EQUAL THE ?[PhB^]V METHOD IS CALLED AGAIN UNTIL A NEW B^]V OBJECT IS RETRIEVED )F THE USER HAS ONLY ONE SONG IN HER LIBRARY THE SONG IS REPEATED EACH TIME UNTIL THE APPLICATION IS CLOSED
■ .OTE 9OU COULD USE THE B^]V=d\QTa PROPERTY TO CHECK WHETHER THE 3^BWdUU[T METHOD PICKED THE SAME SONG BUT WE USED A B^]V OBJECT TO DEMONSTRATE THAT THIS CLASS SUPPORTS OBJECT COMPARISON
4HE ?[PhB^]V METHOD CONTAINS A COUPLE OF INTERESTING CODE SNIPPETS 4HE 7Pb0ac PROPERTY IS CHECKED TO SEE WHETHER THE SONG HAS AN ASSOCIATED ALBUM COVER )F IT DOES THE 6Tc0[Qd\0ac METHOD IS USED TO RETRIEVE THE STREAM DATA OF THE IMAGE /NE WAY TO USE THE BcaTP\ OBJECT WITH THE 8\PVT CONTROLAND SPECIFICALLY ITS B^daRT PROPERTYIS TO CREATE A FaXcTPQ[T1Xc\P_ OBJECT WITH THE STATIC 3TR^ST9_TV METHOD FROM THE ?XRcdaT3TR^STa CLASS DEFINED IN THE <XRa^b^Uc?W^]T NAMESPACE )F THE SONG DOES NOT HAVE AN ASSOCIATED ALBUM COVER A .O #OVER IMAGE IS RETRIEVED FROM THE IMAGE FOLDER WITHIN THE BWdUU[T
4HE 0[Qd\8\PVT BYTES ARRAY DEFINED IN THE SETTINGS IS FILLED WITH THE 6Tc0[Qd\0ac DATA THANKS TO THE 1X]PahATPSTa CLASS AND ITS ATPS1hcTb METHOD &INALLY THE 3daPcX^] PROPERTY FROM THE B^]V CLASS IS USED TO SET THE 8]cTaeP[ PROPERTY OF THE TIMER AND THEN THE TIMER IS STARTED _aXePcT e^XS ?[PhB^]V j B^]V b , 3^BWdUU[T* XU b , ]d[[ b , N[PbcB^]Vkk[XQaPahB^]Vb2^d]c ,, j 0__ P__ , 0__[XRPcX^]2daaT]c Pb 0__*
N[PbcB^]V , b* cQ0dcW^aCTgc , b0acXbc=P\T ) b=P\T* P__bTccX]VbCXc[T , cQ0dcW^aCTgc* XU b0[Qd\7Pb0ac j FaXcTPQ[T1Xc\P_ fQX\V , ?XRcdaT3TR^STa3TR^ST9_TVb0[Qd\6Tc0[Qd\0ac* X\V2^eTaB^daRT , fQX\V* dbX]V ePa Qa , ]Tf 1X]PahATPSTab0[Qd\6Tc0[Qd\0ac P__bTccX]Vb0[Qd\8\PVT , QaATPS1hcTbX]cb0[Qd\6Tc0[Qd\0ac;T]VcW* l T[bT j P__bTccX]Vb0[Qd\8\PVT , ]d[[* X\V2^eTaB^daRT , ]Tf 1Xc\P_8\PVT]Tf DaXX\PVTb]^R^eTa_]V DaX:X]SAT[PcXeT* l
REPRODUCTION TIME "Y SUBTRACTING THIS VALUE FROM THE SONGS DURATION YOU OBTAIN THE NEW 8]cTaeP[ VALUE OF THE TIMER _aXePcT e^XS ?W^]T0__[XRPcX^]?PVTN;^PSTS^QYTRc bT]STa A^dcTS4eT]c0aVb T j 0__ P__ , 0__[XRPcX^]2daaT]c Pb 0__* XU P__bTccX]Vb8bC^\Qbc^]TS ?[PhB^]V* T[bT j cQ0dcW^aCTgc , P__bTccX]VbCXc[T* XU P__bTccX]Vb0[Qd\8\PVT , ]d[[ j
4HE LAST REQUIREMENT WE HAVE IMPOSED ON OURSELVES IS THAT THE APPLICATION MUST END WHEN THE HARDWARE "ACK BUTTON IS PRESSED )N THE ?W^]T0__[XRPcX^]?PVT CLASS YOU DEFINE THE >]1PRZ:Th?aTbb METHOD WHICH YOU CAN OVERRIDE SO AS TO ADD YOUR CODE BEFORE THE BACK FUNCTIONALITY IS ACCOMPLISHED )N THIS CASE YOU STOP THE SONG THAT IS PLAYING AND YOU STOP THE TIMER _a^cTRcTS ^eTaaXST e^XS >]1PRZ:Th?aTbbBhbcT\2^\_^]T]c<^ST[2P]RT[4eT]c0aVb T j
■ .OTE !CTUALLY AT WRITING TIME THE
5SAGE &ROM 6ISUAL 3TUDIO SELECT THE OUTPUT TARGET AS 7INDOWS 0HONE %MULATOR AND PRESS #TRL& 4HE EMULATOR STARTS BRIEFLY SHOWING THE APPLICATION AS IN &IGURE 4HE SONG YOU PLAY COULD BE DIFFERENT FROM THE ONE SHOWN IN &IGURE BECAUSE OF THE SHUFFLE MODE 4HE EMULATOR PROVIDES THREE SONGS WITH NO COVERS SO IF YOU WANT TO SEE THE APPLICATION WITH ALBUM COVERS AS WELL YOU SHOULD RUN IT ON A PHYSICAL DEVICE
&IGURE 4HE BWdUU[T
5SING THE -ICROPHONE IN THE &UNNY 2EPEATER !PPLICATION 0ROBLEM 9OU NEED TO USE THE 7INDOWS 0HONE MICROPHONE TO REGISTER YOUR VOICE AND REPRODUCE IT IN A FUNNY WAY
3OLUTION 9OU CAN USE THE <XRa^_W^]T CLASS FROM THE <XRa^b^UcG]P5aP\Tf^aZS[[ ASSEMBLY AND THE ?[Ph METHOD PROVIDED BY THE B^d]S4UUTRc CLASS
(OW )T 7ORKS )N THE <XRa^b^UcG]P5aP\Tf^aZ0dSX^ NAMESPACE THE <XRa^_W^]T CLASS IS DEFINED THIS CLASS PROVIDES ACCESS TO THE DEVICES MICROPHONE 4HE <XRa^_W^]T CLASS SEE &IGURE FOR THE CLASS DIAGRAM HAS THE 1dUUTaATPSh EVENT THAT IS RAISED AT REGULAR INTERVALS DEPENDING ON THE 1dUUTa3daPcX^] SETTING 7ITHIN THE 1dUUTaATPSh EVENT HANDLER YOU CAN CALL THE 6Tc3PcP METHOD PROVIDED BY THE <XRa^_W^]T CLASS IN ORDER TO RETRIEVE A PORTION OF THE REGISTERED AUDIO BUFFER 4HIS BUFFER HAS A FIXED SIZE THAT YOU CAN CALCULATE BY CALLING THE 6TcBP\_[TBXiT8]1hcTb METHOD FROM THE <XRa^_W^]T CLASS
&IGURE 4HE <XRa^_W^]T CLASS DIAGRAM 4HE MICROPHONE IS STARTED BY USING THE BcPac METHOD FROM THE <XRa^_W^]T CLASS AND IS STOPPED BY THE Bc^_ METHOD 4HE <XRa^_W^]T CLASS IS SEALED SO YOU CANNOT CREATE AN INSTANCE FROM IT YOU HAVE TO CALL THE STATIC 3TUPd[c PROPERTY FROM THE <XRa^_W^]T CLASS WHICH RETURNS AN INSTANCE OF THE <XRa^_W^]T OBJECT REPRESENTING THE DEFAULT MICROPHONE 4O PLAY THE RECORDED AUDIO YOU HAVE TO USE THE ?[Ph METHOD PROVIDED BY THE B^d]S4UUTRc CLASS "EFORE USING THIS METHOD YOU NEED TO CREATE AN OBJECT FROM THE B^d]S4UUTRc CLASS BY USING ONE OF THE TWO PROVIDED CONSTRUCTORS 4HE FIRST CONSTRUCTOR ACCEPTS THE AUDIO BUFFER AS A BYTES ARRAY THE AUDIO SAMPLE RATE AND THE NUMBER OF AUDIO CHANNELS TO USE DURING THE AUDIO PLAYING 4HE SECOND CONSTRUCTOR ACCEPTSIN ADDITION TO THOSE THREE PARAMETERS AN OFFSET VALUE INDICATING FROM WHERE THE AUDIO PLAY HAS TO START THE COUNT REPRESENTING THE AMOUNT OF DATA TO PLAY AND LOOPS PARAMETERS TO REPRODUCE A LOOPING SOUND 4HE B^d]S4UUTRc CLASS PROVIDES A MIX OF STATIC AND INSTANCE METHODS !MONG THE STATIC METHODS WORTH NOTING IS THE 5a^\BcaTP\ METHOD WHICH RETRIEVES A B^d]S4UUTRc OBJECT FROM A STREAM !MONG THE INSTANCE METHODS WORTH NOTING IS THE 2aTPcT8]bcP]RT METHOD WHICH RETURNS A B^d]S4UUTRc8]bcP]RT
OBJECT "EFORE CALLING THE ?[Ph METHOD YOU CAN USE THE 2aTPcT8]bcP]RT METHOD TO RETURN A B^d]S4UUTRc8]bcP]RT OBJECT AND SET ITS OWN $ AUDIO SPACE PARAMETERS -OREOVER YOU CAN USE THE B^d]S4UUTRc8]bcP]RT OBJECT TO SET AUDIO PITCH VOLUME AND PAN
4HE #ODE 4O DEMONSTRATE USING THE MICROPHONE AND REPRODUCING SOUND WE HAVE CREATED THE 5d]]hAT_TPcTa 3ILVERLIGHT FOR 7INDOWS 0HONE APPLICATION !S YOU ALREADY LEARNED IN 2ECIPE THE 3ILVERLIGHT APPLICATION DOESNT HAVE SUPPORT FOR AUDIO RECORDING SO YOU HAVE TO REFERENCE THE <XRa^b^UcG]P5aP\Tf^aZS[[ ASSEMBLY -OREOVER BECAUSE THE ?[Ph METHOD NEEDS REPEATED UPDATES TO THE FRAMEWORK DISPATCHER YOU ADD THE G]P3Xb_PcRWTaBTaeXRT WHICH IMPLEMENTS THE 80__[XRPcX^]BTaeXRT INTERFACE AS SEEN IN 2ECIPE )N THE
1dUUTa3daPcX^] PROPERTY TO MILLISECONDSSO THAT THE 1dUUTaATPSh EVENT IS RAISED EVERY MILLISECONDS 4HEN YOU PREPARE THE BYTES ARRAY BUFFER TO RECEIVE AUDIO DATA 4HIS ARRAY WILL HAVE A CAPACITY EQUAL TO THE VALUE RETURNED BY THE 6TcBP\_[TBXiT8]1hcTb METHOD PROVIDED BY THE <XRa^_W^]T CLASS 4HE 6TcBP\_[TBXiT8]1hcTb METHOD ACCEPTS A CX\TB_P] OBJECT SET EQUAL TO THE 1dUUTa3daPcX^] PROPERTY VALUE ! FRESH NEW
5SAGE 9OU CAN USE THIS APPLICATION BOTH IN THE EMULATOR AND THE PHYSICAL DEVICE )F YOU CHOOSE THE FORMER THE 0#S MICROPHONE WILL BE USED &ROM 6ISUAL 3TUDIO PRESS #TRL& SO THAT THE APPLICATION IS STARTED )F YOU CHOOSE THE EMULATOR THE APPLICATION WILL LOOK LIKE &IGURE
&IGURE 4HE &UNNY 2EPEATER APPLICATION RUNNING IN THE EMULATOR
.OW YOU CAN PRESS THE 2ECORD BUTTON AND START TO SAY WHAT YOU WOULD LIKE TO SAY 0RESS THE 3TOP BUTTON AND HOPEFULLY YOU WILL HEAR YOUR VOICE REPEATING YOUR SPEECH BUT IN A FUNNY WAY
5SING THE -EDIA%LEMENT #ONTROL TO 0LAY "OTH -USIC AND 6IDEO 0ROBLEM 9OU NEED TO PLAY MUSIC SUCH AS -0 AND 7-! FILES AND VIDEOS BY USING THE SAME 3ILVERLIGHT CONTROL
3OLUTION 9OU CAN USE THE
(OW )T 7ORKS 7ITHIN THE 3ILVERLIGHT FOR 7INDOWS 0HONE CONTROLS LIBRARY IS THE
■ .OTE )N THE FOLLOWING -3$. ARTICLE YOU CAN READ ABOUT ALL MEDIA FORMATS COMPATIBLE WITH THE
/THER THAN THE CLASSIC METHODS TO START STOP AND PAUSE THE MEDIA PLAYING
4HE 0dc^?[Ph PROPERTY ENABLES YOU TO AUTOMATICALLY START PLAYING THE MEDIA WHEN ITS VALUE IS SET TO cadT (OWEVER THE -ARKETPLACE CERTIFICATION REQUIREMENTS 3ECTION INDICATE THAT YOU CANT INTERRUPT MUSIC THAT IS ALREADY PLAYING SO IT IS BETTER TO START WITH THIS VALUE SET TO UP[bT AND THEN CHECK WHETHER MUSIC IS ALREADY PLAYING ON YOUR DEVICE 4HIS CAN BE ACCOMPLISHED BY CALLING THE 6P\T7Pb2^]ca^[ METHOD PROVIDED BY THE
4HE #ODE 4O DEMONSTRATE THE
_dQ[XR _PacXP[ R[Pbb
e^XS \TEXST^N1dUUTaX]V?a^VaTbb2WP]VTS^QYTRc bT]STa A^dcTS4eT]c0aVb T j cQ1dUUTaX]VCTgc , bcaX]V5^a\Pc1dUUTaX]Vj)?l \TEXST^1dUUTaX]V?a^VaTbb* l 4HE 2daaT]cBcPcT2WP]VTS EVENT IS MANAGED BY THE RELATED EVENT HANDLER IN ORDER TO CHANGE THE 0LAY ICON BUTTON INTO THE 0AUSE ICON BUTTON WHEN 2daaT]cBcPcT IS EQUAL TO ?[PhX]V e^XS \TEXST^N2daaT]cBcPcT2WP]VTS^QYTRc bT]STa A^dcTS4eT]c0aVb T j XU \TEXST^2daaT]cBcPcT ,,
5SAGE &ROM 6ISUAL 3TUDIO SELECT THE 7INDOWS 0HONE %MULATOR AS THE TARGET OUTPUT AND PRESS #TRL& TO START THE APPLICATION SHOWN IN &IGURE
&IGURE 4HE
!DDING )NTEGRATION WITH THE -USIC 6IDEOS (UB 0ROBLEM 9OU NEED TO INTEGRATE YOUR APPLICATION WITH THE -USIC 6IDEOS HUB IN YOUR 7INDOWS 0HONE DEVICE
3OLUTION 9OU HAVE TO USE METHODS AND PROPERTIES PROVIDED BY
(OW )T 7ORKS 4HE -USIC 6IDEOS HUB IS AN AGGREGATOR APPLICATION AVAILABLE FROM THE 7INDOWS 0HONE OPERATING SYSTEM )T GROUPS ALL THE APPLICATIONS INSTALLED ON THE PHONE THAT REPRODUCE MEDIA FILES SUCH AS MUSIC AND VIDEOS 4HE -USIC 6IDEOS HUB IS COMPOSED OF FOUR SECTIONS :UNE #ONTAINS LINKS TO MUSIC VIDEO PODCASTS RADIO AND THE -ARKETPLACE (ISTORY #ONTAINS RECENTLY PLAYED MEDIA AND CONTENT FROM THIRD PARTY PROVIDERS .EW #ONTAINS RECENT MEDIA EITHER UPLOADED TO THE PHONE OR DOWNLOADED FROM THE -ARKETPLACE -ARQUEE #ONTAINS THE LIST OF APPLICATIONS THAT MANAGE MEDIA 3O THE LAST SECTION IS VERY INTERESTING (OW CAN YOUR APPLICATION BE INCLUDED IN THE -ARQUEE SECTION OF THE -USIC 6IDEOS HUB 4HE -3$. OFFICIAL DOCUMENTATION SAYS THAT THE USE OF
■ 4IP 9OU CAN MANUALLY ADD THE 7dQCh_T, ATTRIBUTE TO THE 0__ TAG IN THE F<0__
■ .OTE )N THE OFFICIAL !PP (UB FORUM THERE IS A THREAD ABOUT THE CERTIFICATION PROCESS AND THE 7dQCh_T ATTRIBUTE )T SEEMS THE OFFICIAL DOCUMENTATION IS WRONG AND YOU HAVE TO MANUALLY INSERT THE 7dQCh_T ATTRIBUTE TO HAVE THE INTEGRATION WITH THE HUB 3EE THE FOLLOWING PAGE Wcc_)U^ad\bRaTPcT\bS]R^\U^ad\b_& &(# ###("Pb_g
4HE APPLICATION MUST BE DEVELOPED TO CORRECTLY RESPOND TO THE -USIC 6IDEOS HUB INTERACTIONS 4HESE INTERACTIONS CAN BE SUMMARIZED AS FOLLOWS v
7HEN A MEDIA FILE IS PLAYED IT APPEARS AS .OW 0LAYING IN THE (ISTORY SECTION NEXT THE :UNE SECTION )T APPEARS AS A ¾ PIXEL IMAGE THAT YOU MUST PROVIDE IN YOUR SOLUTION 4HIS IMAGE SHOULD REPRESENT YOUR APPLICATION AND YOU MUST PROVIDE A TITLE FOR THE MEDIA FILE BEING PLAYED
v
7HEN ANOTHER MEDIA FILE STARTS PLAYING THE OLD ONE HAS TO BE INSERTED INTO THE (ISTORY SECTION
v
7HEN AN ITEM IS PICKED FROM THE (ISTORY SECTION YOUR APPLICATION WILL BE EXECUTED AND A @dTahBcaX]V WILL BE PROVIDED WITH THE INFORMATION YOU STORED IN THE ?[PhTa2^]cTgc COLLECTION 9OUR APPLICATION HAS TO MANAGE THIS QUERY STRING INFORMATION AND PLAY THE RELATED MEDIA
v
7HEN YOUR APPLICATION IS EXECUTED FROM THE -ARQUEE SECTION AND A MEDIA FILE IS ALREADY PLAYING THE APPLICATION HAS TO CONTINUE PLAYING THAT MEDIA
%VERYTHING NOTED IN THE PRECEDING LIST IS AVAILABLE FROM THE
■ #AUTION 4HE IMAGE CANNOT BE GREATER THAN KILOBYTES /THERWISE THE FOLLOWING EXCEPTION WILL OCCUR h3YSTEM!RGUMENT%XCEPTION IMAGE STREAM SIZE BIGGER THAN MAXIMUM ALLOWED v
4HE CXc[T PROPERTY ENABLES YOU TO SET THE STRING THAT WILL BE DISPLAYED OVER THE .OW0LAYING ICON 5SUALLY THIS WILL BE SET TO THE MEDIA NAME SUCH AS A SONGS NAME %VEN WHEN YOU SPECIFY THE ITEM IN THE (ISTORY AND THE .EW SECTIONS YOU STILL HAVE TO SET THE CXc[T PROPERTY THAT WILL BE DISPLAYED IN THE .OW 0LAYING SECTION
■ .OTE 4HERE IS ANOTHER PROPERTY CALLED B^daRT THAT THE OFFICIAL DOCUMENTATION DEFINES AS UNSUPPORTED BUT IF YOU DONT SET THIS PROPERTY TO AN EMPTY STRING YOU WILL NOT BE ABLE TO ADD THE ITEM TO THE -USIC 6IDEOS HUB
4HE #ODE 4O DEMONSTRATE THE -USIC 6IDEOS HUB INTEGRATION WE HAVE CREATED THE
ADD THE <XRa^b^UcG]P5aP\Tf^aZS[[ ASSEMBLY AND A CLASS IMPLEMENTING THE 80__[XRPcX^]BTaeXRT INTERFACE TO PERIODICALLY CALL THE D_SPcT STATIC METHOD FROM THE 5aP\Tf^aZ3Xb_PcRWTa CLASS 4HE
_aXePcT e^XS Qc]?[PhN2[XRZ^QYTRc bT]STa 4eT]c0aVb T j XU
■ .OTE 9OU CANT USE THE SAME
)N THE D_SPcT=^f?[PhX]V METHOD YOU USE ANOTHER WAY TO RETRIEVE THE STREAM DATA COMPOSING THE IMAGE THE BcaTP\ATb^daRT8]U^ CLASS !N OBJECT OF THIS CLASS IS RETURNED FROM THE 6TcATb^daRTBcaTP\ STATIC METHOD PROVIDED BY THE 0__[XRPcX^] CLASS 4HE 6TcATb^daRTBcaTP\ STATIC METHOD ACCEPTS A 52) OBJECT THAT SPECIFIES WHERE TO FIND THE RESOURCE 4HE BcaTP\ATb^daRT8]U^ CLASS PROVIDES THE BcaTP\ PROPERTY CONTAINING THE IMAGES STREAM DATA THAT YOU CAN ASSIGN TO THE 8\PVTBcaTP\ PROPERTY OF THE
■ .OTE 7E USED A *0%' IMAGE SO AS TO REDUCE THE IMAGE DEFINITION AND PROVIDE A COMPATIBLE IMAGE SIZE
&INALLY YOU SET THE B^daRT AND CXc[T PROPERTIES AND YOU ADD THE SONG INDEX TO THE ?[PhTa2^]cTgc COLLECTION SO THAT WHEN THE SONG IS REQUESTED FROM THE HUB YOUR APPLICATION CAN RETRIEVE IT FROM THE QUERY STRING 4HIS NEW OBJECT IS ASSIGNED TO THE =^f?[PhX]V PROPERTY OF THE
5SAGE &OR THIS RECIPE YOU NEED A PHYSICAL DEVICE BECAUSE THE EMULATOR DOESNT PROVIDE THE -USIC 6IDEOS HUB &ROM 6ISUAL 3TUDIO SELECT THE 7INDOWS 0HONE $EVICE TARGET OUTPUT AND THEN PRESS #TRL& 4HE APPLICATION DEPLOYS TO THE PHYSICAL DEVICE AND RUNS AS SHOWN IN &IGURE
&IGURE 4HE
&IGURE )N THE -USIC 6IDEOS HUB APPLICATION THE (ISTORY SECTION SHOWS THE LAST PLAYED SONG 0RESS THE .OW 0LAYING ICON FROM THE HUB AND THE APPLICATION EXECUTES AGAIN PLAYING THE SONG .OW PRESS THE 3TOP BUTTON AND THEN THE 0LAY BUTTON AGAIN SO THAT ANOTHER SONG IS PLAYED 3TOP THAT SONG AND THEN PRESS THE HARDWARE 3TART BUTTON 'O TO THE -USIC 6IDEOS HUB AND SEE THAT THE (ISTORY SECTION IS POPULATED WITH AN ITEM 3ADLY THERE IS NO TITLE DESCRIBING THE ITEM BUT BY CLICKING IT YOU CAN DISCOVER THAT OUR APPLICATION IS RUNNING AND THE FIRST SONG IS BEING PLAYED
CHAPTER ■■■
Isolated Storage 4HE ISOLATED STORAGE IN 3ILVERLIGHT FOR 7INDOWS 0HONE FOLLOWS IN SOME WAYS THE ARCHITECTURAL MODEL USED FOR THE DESKTOP VERSION 4HE CONCEPT OF THIS STORAGE IS TO ISOLATE THE PHYSICAL MEMORY OF ONE APPLICATION FROM ANOTHER )SOLATED STORAGE UNDOUBTEDLY HAS ITS ADVANTAGES THE APPLICATIONS DATA IS AVAILABLE ONLY TO US WHICH MEANS THAT NO ONE ELSE CAN COMPROMISE SECURITY BY ACCESSING IT 3URE YOU CAN ALSO SEE DISADVANTAGESOUR APPLICATION WILL NOT BE ABLE TO SHARE DATA EVEN PARTIALLY WITH OTHER APPS RIGHT "UT TO SOLVE PROBLEMS LIKE THIS YOU CAN JUST MOVE THE DATA TO BE SHARED hIN THE CLOUDv #ONTAINED WITHIN ISOLATED STORAGE ARE THE FILES THAT YOU CHOOSE TO CREATE AND SAVE IN YOUR APPLICATION AS WELL AS THE SETTINGS OF THE APPLICATION ITSELF 4HE RECIPES IN THIS CHAPTER DESCRIBE HOW TO DO THE FOLLOWING v
3AVE A FILE IN ISOLATED STORAGE AND LOAD IT
v
3AVE SERIALIZED DATA
v
-ODIFY SETTINGS OF YOUR APPLICATION
v
3AVE A PHOTO IN ISOLATED STORAGE
■ .OTE )F YOUR APPLICATION IS UNINSTALLED THE RELATIVE ISOLATED STORAGE IS COMPLETELY REMOVED 4HEREFORE IF THE APPLICATION IS INSTALLED ONCE AGAIN THAT INSTALLATION OCCURS AS IF IT WERE BEING DONE FOR THE FIRST TIME 4AKE CARE TO NOTIFY THE USER OF THIS ISSUE AND TO SAVE WITH PRIOR WRITTEN PERMISSION OF THE USER THE DATA THAT THE USER WANTS TO KEEP
3AVING A &ILE IN )SOLATED 3TORAGE AND ,OADING )T 0ROBLEM 9OU WANT TO CREATE A SIMPLE NOTEPAD SO THE USER CAN STORE NOTES LOCALLY AND SIMPLY RETRIEVE THEM LATER
3OLUTION 9OU MUST USE THE 8b^[PcTSBc^aPVT5X[T CLASS TO ACCESS ISOLATED STORAGE
(OW )T 7ORKS 4HE CLASS THAT PROVIDES THE ABILITY TO ACCESS DATA IN ISOLATED STORAGE IS 8b^[PcTSBc^aPVT5X[T CONTAINED IN THE NAMESPACE BhbcT\8>8b^[PcTSBc^aPVT WHICH IN TURN IS CONTAINED INSIDE THE \bR^a[XQ ASSEMBLY !S YOU CAN SEE FROM THE CLASS DIAGRAM SHOWN IN &IGURE YOU ARE ALLOWED A NUMBER OF TASKS INCLUDING CREATING DIRECTORIES )N THIS CASE FOR EXAMPLE YOU COULD ASK THE USER WHETHER TO SAVE DATA IN A FOLDER HIERARCHY
&IGURE )SOLATED STORAGES CLASS DIAGRAM
4HE #ODE 9OU START FROM AN INTERFACE THAT WILL BE COMPOSED ESSENTIALLY OF A MAIN PAGE AND TWO BUTTONS )N THE MAIN PAGE THE USER WILL INSERT THE TITLE OF THE NOTE ITSELF )N THE APPLICATION BAR YOU WILL HAVE TWO BUTTONS ONE TO SAVE THE NOTE AND ANOTHER TO DISPLAY THE PAGE THAT CONTAINS THE LIST OF NOTES ALREADY WRITTEN AND SAVED IN ISOLATED STORAGE 7HILE ON THE LIST PAGE YOU WILL HAVE ONLY A LIST BOX IN WHICH EVERY ITEM WILL BE A NOTE THAT IS ALREADY SAVED 7HEN A NOTE IS SELECTED FROM THE LIST IT WILL BE LOADED ON THE MAIN PAGE +6aXS g)=P\T,;Ph^dcA^^c 1PRZVa^d]S,CaP]b_PaT]c+6aXSA^f3TUX]XcX^]b+A^f3TUX]XcX^] 7TXVWc,0dc^+A^f3TUX]XcX^] 7TXVWc,+6aXSA^f3TUX]XcX^]b+BcPRZ?P]T[ g)=P\T,CXc[T?P]T[ 6aXSA^f, <PaVX], ! &!'+CTgc1[^RZ g)=P\T,0__[XRPcX^]CXc[T CTgc,B8;4 =>C4 0??;820C8>= Bch[T,jBcPcXRATb^daRT ?W^]TCTgc=^a\P[Bch[Tl+BcPRZ?P]T[+6aXS g)=P\T,2^]cT]c?P]T[ 6aXSA^f, <PaVX], ! !+6aXSA^f3TUX]XcX^]b+A^f3TUX]XcX^] 7TXVWc,#$ +A^f3TUX]XcX^] 7TXVWc, +6aXSA^f3TUX]XcX^]b+CTgc1^g 6aXSA^f, =P\T,5X[T]P\TCTgc1^g CTgc,=^cT=P\T +CTgc1^g 6aXSA^f, =P\T,=^cTCTgc1^g CTgc,FaXcT h^da ]^cT WTaT +6aXS+6aXS+_W^]T)?W^]T0__[XRPcX^]?PVT0__[XRPcX^]1Pa+bWT[[)0__[XRPcX^]1Pa 8bEXbXQ[T,CadT 8b
_aXePcT e^XS BPeT1dcc^]N2[XRZ^QYTRc bT]STa 4eT]c0aVb T j cah j dbX]V ePa bc^aT , 8b^[PcTSBc^aPVT5X[T6TcDbTaBc^aT5^a0__[XRPcX^] dbX]V ePa bcaTP\ , ]Tf 8b^[PcTSBc^aPVT5X[TBcaTP\5X[T]P\TCTgc1^gCTgc 5X[T<^ST2aTPcT 5X[T0RRTbbFaXcT bc^aT j BcaTP\FaXcTa faXcTa , ]Tf BcaTP\FaXcTabcaTP\* faXcTaFaXcT=^cTCTgc1^gCTgc* faXcTa2[^bT* l l RPcRW 4gRT_cX^] j
#LICK AN ITEM WITHIN THE LIST TO PASS IT AS PARAMETER OF THE MAIN PAGE VIA THE FOLLOWING CODE _aXePcT e^XS =^cTbNBT[TRcX^]2WP]VTS^QYTRc bT]STa BT[TRcX^]2WP]VTS4eT]c0aVb T j XU T0SSTS8cT\b2^d]c - =PeXVPcX^]BTaeXRT=PeXVPcT]Tf DaX bcaX]V5^a\Pc
5SAGE &ROM 6ISUAL 3TUDIO LAUNCH THE APPLICATION BY PRESSING #TRL& 4HE APPLICATION DISPLAYS AS SHOWN IN &IGURE 7RITE SOMETHING AND THEN CLICK THE BUTTON TO SAVE THE NOTE #LICK TO DISPLAY THE LIST OF SAVED NOTES AS SHOWN IN &IGURE 7E HAD ALREADY SAVED SOME #LICK ON ANOTHER NOTE THAT HAS BEEN SAVED FOR LOADING AND COMPLETE THE CYCLE OF THE APPLICATION
&IGURE -AIN PAGE OF OUR APPLICATION
&IGURE ,IST OF OUR NOTES
&IGURE %DITING A NOTE
3AVING 3ERIALIZED $ATA 0ROBLEM 9OU WANT TO SERIALIZE ON DISK THE STATE OF YOUR OBJECTS TO LOAD THEM LATER
3OLUTION 9OU MUST USE G\[BTaXP[XiTa IN COMBINATION WITH THE 8b^[PcTSBc^aPVT CLASSES TO SERIALIZE THE STATE OF YOUR OBJECTS IN A FILE
(OW )T 7ORKS 4HE G\[BTaXP[XiTa CLASS SERIALIZES AND DESERIALIZES OBJECTS TO AND FROM 8-, DOCUMENTS )N SERIALIZATION WE CONVERT AN OBJECT AND ITS PROPERTIES TO A SERIAL FORMAT IN THIS CASE 8-, THAT CAN BE STORED IN OUR CASE OR TRANSPORTED IN THE CASE OF SERVICES FOR EXAMPLE $ESERIALIZATION IS THE PROCESS OF RE CREATING THE OBJECT FROM 8-, BY DECORATING THE OBJECTS THAT CORRESPOND TO G\[4[T\T]c AND THEIR PROPERTIES THAT CORRESPOND TO G\[0ccaXQdcT
4HE #ODE &OR THIS RECIPE WE HAVE CHOSEN TO COMPLETE THE APPLICATION LOGIC OF &3ad\ BY USING THE 4gTaRXbT
&IGURE #LASS $IAGRAM OF CLASSES THAT WORKS WITH EXERCISE IN $RUM 4HE FIRST METHOD THAT YOU WANT TO CONSIDER IS BPeT 4HE CODE IS WRITTEN AS FOLLOWS _dQ[XR bcPcXR j dbX]V dbX]V dbX]V
e^XS BPeT;Xbc+4gTaRXbTBTccX]Vb- TgTaRXbTb ePa bc^aT , 8b^[PcTSBc^aPVT5X[T6TcDbTaBc^aT5^a0__[XRPcX^] ePa UX[TBcaTP\ , bc^aT2aTPcT5X[TTgTaRXbTbg\[ ePa faXcTa , ]Tf BcaTP\FaXcTaUX[TBcaTP\
j G\[BTaXP[XiTa bTa , ]Tf G\[BTaXP[XiTach_T^U;Xbc+4gTaRXbTBTccX]Vb-* bTaBTaXP[XiTfaXcTa TgTaRXbTb* faXcTa2[^bT* l l 4HIS CODE WHICH MAKES EXTENSIVE USE OF THE CONSTRUCT dbX]V BEHAVES ALMOST EXACTLY THE SAME WAY AS THE CODE OF THE PREVIOUS RECIPE )N PRACTICE YOU RETURN THE STORE ASSOCIATED WITH YOUR APPLICATION 4HEN IN THIS STORE YOU CREATE THE 8-, FILES FOR THE EXERCISES YOU ASSOCIATE THE BcaTP\FaXcTa TO THIS UX[TBcaTP\ AND FINALLY THANKS TO THE G\[BTaXP[XiTa CLASS YOU WRITE THE 8-, SERIALIZATION THAT RESULTS IN THE LIST OF EXERCISES #LOSING THE STREAM COMMITS THE CHANGES AND THE dbX]V STATEMENTS COMING AT THE END OF THE SCOPE DISPOSES THE THREE VARIABLESE faXcTa UX[TBcaTP\ AND bc^aT )N THIS WAY YOU JUST SERIALIZED INTO ISOLATED STORAGE A LIST OF 4gTaRXbTBTccX]Vb )T IS OBVIOUS THAT IF YOUR APPLICATION REQUIRES MORE THAN ONE ENTITY DOMAIN YOU WILL HAVE NO PROBLEM USING THIS CODE )F YOU HAVE ANY DOUBTS THE ONLY THING YOU NEED TO REVISE IS THE USE OF THE G\[BTaXP[XiTa CLASS 4HE OTHER METHOD TO ANALYZE NOW IS THE ;^PS METHOD WHICH WILL DESERIALIZE THE DATA FROM THE 8-, FILE IN OUR CLASS _dQ[XR bcPcXR ;Xbc+4gTaRXbTBTccX]Vb- ;^PS j ;Xbc+4gTaRXbTBTccX]Vb- TgTaRXbTb , ]Tf ;Xbc+4gTaRXbTBTccX]Vb-* dbX]V 8b^[PcTSBc^aPVT5X[T bc^aPVT , 8b^[PcTSBc^aPVT5X[T6TcDbTaBc^aT5^a0__[XRPcX^] XU bc^aPVT5X[T4gXbcbTgTaRXbTbg\[ j dbX]V 8b^[PcTSBc^aPVT5X[TBcaTP\ bcaTP\ , bc^aPVT>_T]5X[TTgTaRXbTbg\[ 5X[T<^ST>_T] j G\[BTaXP[XiTa g\[ , ]Tf G\[BTaXP[XiTach_T^U;Xbc+4gTaRXbTBTccX]Vb-* TgTaRXbTb , g\[3TbTaXP[XiTbcaTP\ Pb ;Xbc+4gTaRXbTBTccX]Vb-* bcaTP\2[^bT* l l aTcda] TgTaRXbTb* l 4HIS CODE IS NOT SO DIFFICULT TO UNDERSTAND IF YOU ANALYZE IT STEP BY STEP
#REATE A LIST OF 4gTaRXbTBTccX]Vb
2ETURN TO OUR STORE AT THIS POINT ITS CLEAR THAT IF YOU WANT TO ACCESS THE ISOLATED STORAGE THIS IS A NECESSARY STEP
)F THERE IS AN 8-, FILE CALLED TgTaRXbTb IN THE STORE DO THE FOLLOWING
/PEN A STREAM POINTING TO THE FILE
#REATE AN G\[BTaXP[XiTa CLASS TO LIST THE 4gTaRXbTBTccX]Vb
$ESERIALIZE THE STREAM IN THE LIST OF 4gTaRXbTBTccX]Vb
#LOSE THE STREAM
!T THIS POINT OUR APPLICATION &3ad\ IS READY TO SAVE AND UPLOAD LISTS OF EXERCISES TO KEEP THEM BETWEEN SESSIONS OF OUR APPLICATION
5SAGE !FTER ADDING THE IMPLEMENTATION OF THE TWO METHODS OF THE CLASS 4gTaRXbT
-ODIFYING 3ETTINGS OF 9OUR !PPLICATION 0ROBLEM 9OU WANT TO LOCALLY SAVE SOME SETTINGS ABOUT YOUR APPLICATION AND THEN RETRIEVE THOSE SETTINGS LATER
3OLUTION 9OU MUST USE THE 8b^[PcTSBc^aPVTBTccX]Vb CLASS TO ACCESS YOUR APPLICATION SETTINGS ADDING AND DELETING ZThb LIKE A SXRcX^]Pah
(OW )T 7ORKS 8b^[PcTSBc^aPVTBTccX]Vb ENABLES YOU TO EASILY AND LOCALLY STORE USER SPECIFIC DATA AS KEYVALUE PAIRS IN THE OBJECT 8b^[PcTSBc^aPVT5X[T 9OU WILL SEE THAT THE USE OF 8b^[PcTSBc^aPVTBTccX]Vb IS EQUAL TO THE USE OF A DICTIONARY +C:Th CEP[dT-
4HE #ODE &OR THIS RECIPE WE WANT TO SHOW YOU HOW TO COMPLETE ANOTHER RECIPE THAT YOU CAN FIND IN CHAPTER IN THE CLOUD BY USING PUSH NOTIFICATION THAT WILL BE DISPLAYED ! TYPE OF PUSH NOTIFICATION IS TOAST NOTIFICATION MORE INFORMATION IN CHAPTER THAT REQUIRES THAT YOUR APPLICATION TO BE ACCEPTED AND PUBLISHED ON -ARKETPLACE MUST ASK USERS WHETHER THEY WANT TO BE NOTIFIED WITH THEM 7HAT BETTER PLACE FOR YOUR APPLICATION TO STORE THE USERS CHOICE THAN IN THE APPLICATION SETTINGS 4O CREATE THIS RECIPE WE HAVE NOT FOCUSED ON THE APPLICATIONS USER INTERFACE BUT ON THE PAGE OF SETTINGS 3UPPOSE THAT OUR APPLICATION USE NOTIFICATIONS AND SOUNDS AND WE WANT TO GIVE TO YOUR USER THE POSSIBILITY TO DISABLE OR ENABLE THEM
+_W^]T)?W^]T0__[XRPcX^]?PVT0__[XRPcX^]1Pa+bWT[[)0__[XRPcX^]1Pa 8bEXbXQ[T,CadT 8b
-
4HIS 8!-, INSERTED INTO THE TEMPLATE OF YOUR PAGE WILL SHOW AN INTERFACE SIMILAR TO THAT IN &IGURE 7E SAY SIMILAR BECAUSE YOU MIGHT NOT BE USING THE SAME ICON OR THE SAME CONTROL TO CHECK THE SETTINGS &OR EXAMPLE YOU COULD HAVE CHOSEN A CHECK BOX OR TOGGLE BUTTON
■ .OTE 4HE CONTROL C^VV[TBfXcRW IS CONTAINED IN THE 7INDOWS 0HONE CONTROLS TOOLKIT WHICH IS AVAILABLE ON #ODE0LEX
&IGURE 4HE 3ETTINGS PAGE )N THE CODE BEHIND OF THE _PVT BTccX]Vb WITHIN THE CONSTRUCTOR YOU SUBSCRIBE TO THE LOADED EVENT WITH 3ETTINGS?,OADED EVENT HANDLER _dQ[XR BTccX]Vb j 8]XcXP[XiT2^\_^]T]c* cWXb;^PSTS , ]Tf A^dcTS4eT]c7P]S[TaBTccX]VbN;^PSTS* l
!ND YOU DEFINE TWO CLASS LEVEL CONSTANT STRINGS _aXePcT R^]bc bcaX]V Nc^Pbc4]PQ[TS:Th , C^Pbc4]PQ[TS* _aXePcT R^]bc bcaX]V Nb^d]Sb4]PQ[TS:Th , B^d]Sb4]PQ[TS* 7HY DO YOU DO THIS "ECAUSE BASICALLY BY ACCESSING SETTINGS THROUGH A DICTIONARY YOU WILL HAVE A NUMBER OF KEYVALUE PAIRS THAT COULD POTENTIALLY INCLUDE EVERYTHING 4HE EVENT HANDLER BTccX]VbN;^PSTS WILL RETRIEVE YOUR SETTINGS AND CHANGE THE VALUE OF THE SWITCH WITH THE FOLLOWING CODE e^XS BTccX]VbN;^PSTS^QYTRc bT]STa A^dcTS4eT]c0aVb T j XU 8b^[PcTSBc^aPVTBTccX]Vb0__[XRPcX^]BTccX]Vb2^]cPX]bNc^Pbc4]PQ[TS:Th j ePa c^Pbc , 8b^[PcTSBc^aPVTBTccX]Vb0__[XRPcX^]BTccX]VbJNc^Pbc4]PQ[TS:ThLC^BcaX]V* cWXbC^PbcBfXcRW8b2WTRZTS , Q^^[?PabTc^Pbc* l XU 8b^[PcTSBc^aPVTBTccX]Vb0__[XRPcX^]BTccX]Vb2^]cPX]bNb^d]Sb4]PQ[TSZTh j ePa b^d]Sb , 8b^[PcTSBc^aPVTBTccX]Vb0__[XRPcX^]BTccX]VbJNb^d]Sb4]PQ[TSZThLC^BcaX]V* cWXbB^d]SbBfXcRW8b2WTRZTS , Q^^[?PabTb^d]Sb* l l ,INE BY LINE WHAT HAPPENS IS AS FOLLOWS
)F THE DICTIONARY CONTAINS THE KEY THAT YOU HAVE ASSOCIATED WITH THE SETTINGS FOR THE TOAST NOTIFICATION
2ECOVER THE VALUE FROM 0__[XRPcX^]BTccX]Vb AS WITH A NORMAL DICTIONARY GETTING IT AS A STRING IN FACT THE TYPE OF VALUE IS AN OBJECT
!SSUMING YOU HAVE A "OOLEAN VALUE YOU JUST DO THE ?PabT )F YOU CANgT BE SURE ABOUT WHAT YOU WILL 'OD SAVE YOU YOU MIGHT OPT FOR A cah_PabT &INALLY YOU ASSOCIATE THE PARSED VALUE TO THE 8b2WTRZTS PROPERTY OF THE SWITCH
2EPEAT THE PRECEDING STEP FOR THE KEY THAT RELATES THE SOUNDS
)N THIS WAY YOU HAVE LOADED THE SETTINGS RELATED TO YOUR APPLICATION AND SO NOW YOU CAN SEE HOW TO SAVE THEM WITH THE HANDLER BPeTBTccX]Vb1dcc^]N2[XRZ _aXePcT e^XS BPeTBTccX]Vb1dcc^]N2[XRZ^QYTRc bT]STa 4eT]c0aVb T j 8b^[PcTSBc^aPVTBTccX]Vb0__[XRPcX^]BTccX]VbJNc^Pbc4]PQ[TS:ThL , cWXbC^PbcBfXcRW8b2WTRZTS* 8b^[PcTSBc^aPVTBTccX]Vb0__[XRPcX^]BTccX]VbJNb^d]Sb4]PQ[TSZThL , cWXbB^d]SbBfXcRW8b2WTRZTS* l
4HE ONLY THING TO DO TO SAVE A SETTING OF THE DICTIONARY IS ASSIGN A KEY AND A VALUE THEN THINKS AT ALL THE CLASS 8b^[PcTBc^aPVTBTccX]V )N ORDER TO PURSUE THIS EXERCISE FURTHER CONSIDER AT THIS POINT USING THE SETTINGS TO SAVE THE "0- OF THE METRONOME OF OUR APPLICATION &3ad\ FOR EXAMPLE
5SAGE 3TART THE TOAST NOTIFICATION APPLICATION BY PRESSING & FROM 6ISUAL 3TUDIO /PEN THE 3ETTINGS PAGE #HANGE THE SETTINGS AND SAVE THEM THEREBY PROVOKING THE TOMBSTONING OF THIS APPLICATION 3TART THE APPLICATION AGAIN AND OPEN THE 3ETTINGS PAGE TO SEE THAT YOUR SETTINGS HAVE BEEN SAVED
3AVING A 0HOTO IN )SOLATED 3TORAGE 0ROBLEM 9OU WANT TO CREATE A PHOTO CATALOG APPLICATION THAT CAPTURES FROM THE CAMERA DEVICE AND SAVES LOCALLY NOT IN THE MEDIA LIBRARY
3OLUTION 9OU MUST WORK WITH THE ?XRcdaT3TR^STa CLASS AND STORE THE DATA AS AN ARRAY OF BYTES BECAUSE AN IMAGE IS ESSENTIALLY A STREAM OF BYTES 4HEN YOU CAN USE THIS ARRAY TO WRITE DATA INSIDE AN 8b^[PcTSBc^aPVT5X[T CLASS
(OW )T 7ORKS ?XRcdaT3TR^STa IS USED TO DECODE A *0%' FILE INTO A FaXcTPQ[T1Xc\P_ THAT PROVIDES A 1Xc\P_B^daRT CONSTANT SET OF PIXELS THAT CAN BE WRITTEN
4HE #ODE )N THIS RECIPE YOU WILL PLAY WITH SOME FEATURES OF 7INDOWS 0HONE COMBINING THEM IN AN INTERESTING APPLICATION !T THIS POINT IN THE CHAPTER YOU KNOW HOW ISOLATED STORAGE WORKS AND HOW YOU CAN ADD FILES TO IT AND OPEN THEM .OW YOU WANT TO CREATE AN ORGANIZED LIST OF DIRECTORIES DIRECTORY ALBUM /UR INTERFACE IS COMPOSED OF A HOME PAGE FROM WHICH THE USER CAN START TO TAKE A PHOTO AND THE IMAGE GALLERY WHERE THE USER CAN NAVIGATE INSIDE THE STORAGE STRUCTURE 7^\T?PVTgP\[ CONTAINS THIS STRUCTURE +6aXS g)=P\T,;Ph^dcA^^c 1PRZVa^d]S,CaP]b_PaT]c+6aXSA^f3TUX]XcX^]b+A^f3TUX]XcX^] 7TXVWc,0dc^+A^f3TUX]XcX^] 7TXVWc,+6aXSA^f3TUX]XcX^]b-
+CXc[T?P]T[ R^]cPX]b cWT ]P\T ^U cWT P__[XRPcX^] P]S _PVT cXc[T+BcPRZ?P]T[ g)=P\T,CXc[T?P]T[ 6aXSA^f, <PaVX], ! &!'+CTgc1[^RZ g)=P\T,0__[XRPcX^]CXc[T CTgc,?W^c^ 0__ Bch[T,jBcPcXRATb^daRT ?W^]TCTgc=^a\P[Bch[Tl+BcPRZ?P]T[+6aXS g)=P\T,2^]cT]c?P]T[ 6aXSA^f, <PaVX], ! !+1dcc^] 2^]cT]c,2P_cdaT P ?W^c^ 7TXVWc,&! <PaVX],#&%&% =P\T,2P\TaP1dcc^] ETacXRP[0[XV]\T]c,C^_ 2[XRZ,2P\TaP1dcc^]N2[XRZ +8\PVT 7TXVWc,""& 7^aXi^]cP[0[XV]\T]c,;TUc <PaVX], !'# =P\T,X\PVT BcaTcRW,5X[[ ETacXRP[0[XV]\T]c,C^_ FXScW,#"' +CTgc1^g 7TXVWc,&! 7^aXi^]cP[0[XV]\T]c,;TUc <PaVX],##$& =P\T,5X[T=P\TCTgc1^g CTgc,CTgc1^g ETacXRP[0[XV]\T]c,C^_ FXScW,#% +CTgc1[^RZ 7TXVWc," 7^aXi^]cP[0[XV]\T]c,;TUc <PaVX],('#"" =P\T,cTgc1[^RZ CTgc,2W^^bT P ]P\T P]S P[Qd\ ETacXRP[0[XV]\T]c,C^_ FXScW,!#! +;Xbc1^g 7TXVWc,(% 7^aXi^]cP[0[XV]\T]c,;TUc <PaVX],%$!! =P\T,0[Qd\b;Xbc1^g ETacXRP[0[XV]\T]c,C^_ FXScW,### +6aXS+6aXS+_W^]T)?W^]T0__[XRPcX^]?PVT0__[XRPcX^]1Pa+bWT[[)0__[XRPcX^]1Pa 8bEXbXQ[T,CadT 8b
&IGURE ! SCREENSHOT OF THE APPLICATIONS MAIN PAGE 4HIS CODE NAVIGATES TO THE 2aTPcT0[Qd\gP\[ PAGE WHICH IS EASY TO UNDERSTAND BECAUSE ITS COMPOSED OF ONLY THREE ELEMENTS A TEXT BLOCK A TEXT BOX AND A BUTTON
+6aXS g)=P\T,2^]cT]c?P]T[ 6aXSA^f, <PaVX], ! !+CTgc1[^RZ 7TXVWc," 7^aXi^]cP[0[XV]\T]c,2T]cTa CTgc,0[Qd\ =P\T ETacXRP[0[XV]\T]c,C^_ +CTgc1^g 7TXVWc,&! 7^aXi^]cP[0[XV]\T]c,;TUc <PaVX],#! =P\T,0[Qd\=P\TCTgcQ^g CTgc,0[Qd\ ETacXRP[0[XV]\T]c,C^_ FXScW,#% +1dcc^] 2^]cT]c,2aTPcT 7TXVWc,&! 7^aXi^]cP[0[XV]\T]c,;TUc <PaVX], ! ! =P\T,2aTPcT0[Qd\1dcc^] ETacXRP[0[XV]\T]c,C^_ FXScW,#"' 2[XRZ,2aTPcT0[Qd\1dcc^]N2[XRZ +6aXS4HE MOST IMPORTANT PART OF THIS CODE IS THE EVENT HANDLER ASSOCIATED WITH THE CLICK OF 2aTPcT0[Qd\1dcc^] BECAUSE HERE YOU CREATE THE DIRECTORY THAT WILL CONTAIN THE NEW ALBUM _aXePcT e^XS 2aTPcT0[Qd\1dcc^]N2[XRZ^QYTRc bT]STa A^dcTS4eT]c0aVb T j dbX]V ePa bc^aT , 8b^[PcTSBc^aPVT5X[T6TcDbTaBc^aT5^a0__[XRPcX^] j XU bc^aT3XaTRc^ah4gXbcbcWXb0[Qd\=P\TCTgcQ^gCTgc
.OW TAKE A LOOK AT THE IMPLEMENTATION OF THE LOADED EVENT HANDLER e^XS
4HIS CODE IS RESPONSIBLE FOR CHECKING THAT THE USER HAS ACTUALLY ACCEPTED THE PHOTO FROM THE INTERFACE 4HEN YOU CREATE AN ARRAY OF BYTES AS LARGE AS THE SIZE OF THE PHOTO TAKEN AND YOU START READING THE PHOTO TAKEN INSTANTIATING THE ARRAY AND FILLING IT WITH THE IMAGE &INALLY RETURNED TO THE BEGINNING OF THE IMAGE YOU CONVERT IT TO *0%' THANKS TO THE SUPPORT CLASS ?XRcdaT3TR^STa SHOWING THE IMAGE ON THE DISPLAY 4HE USER IS READY IN YOUR CASE TO APPLY FILTERS TO THE IMAGE OR TO EDIT IT AS DESIRED IF YOU ALLOWED THAT AND THEN TO SAVE IT )N THE APPLICATION BAR YOU HAVE A BUTTON THAT DOES JUST THISSAVE THE IMAGE IN THE LIBRARY ACCORDING TO THE FOLDER AND FILENAME CHOSEN _aXePcT e^XS BPeT1dcc^]N2[XRZ^QYTRc bT]STa 4eT]c0aVb T j XU NX\PVT0b1hcT ,, ]d[[ j
4HE PAGE CONSISTS OF TWO LIST BOXES FOR ALBUMS AND OTHER IMAGES +6aXS g)=P\T,2^]cT]c?P]T[ 6aXSA^f, <PaVX], ! !+6aXSA^f3TUX]XcX^]b+A^f3TUX]XcX^] 7TXVWc, $ +A^f3TUX]XcX^] 7TXVWc, +6aXSA^f3TUX]XcX^]b+;Xbc1^g 7TXVWc, $ 7^aXi^]cP[0[XV]\T]c,;TUc =P\T,0[Qd\b;Xbc1^g ETacXRP[0[XV]\T]c,C^_ FXScW,#% BT[TRcX^]2WP]VTS,0[Qd\b;Xbc1^gNBT[TRcX^]2WP]VTS +;Xbc1^g 6aXSA^f, 7TXVWc,$#% 7^aXi^]cP[0[XV]\T]c,;TUc <PaVX],# =P\T,?W^c^;XbcQ^g ETacXRP[0[XV]\T]c,C^_ FXScW,#% +6aXS7HEN A NEW ALBUM IS SELECTED THE DIRECTORY CHANGES TO LIST THE FILES IN IT "UT FIRST YOU WANT TO SHOW ALL THE DIRECTORIES IN THE SAME WAY IN WHICH YOU SHOWED THEM ON THE MAIN PAGE e^XS 0[Qd\bN;^PSTS^QYTRc bT]STa A^dcTS4eT]c0aVb T j dbX]V 8b^[PcTSBc^aPVT5X[T bc^aT , 8b^[PcTSBc^aPVT5X[T6TcDbTaBc^aT5^a0__[XRPcX^] j cWXb0[Qd\b;Xbc1^g8cT\bB^daRT , bc^aT6Tc3XaTRc^ah=P\Tb* l l !ND WHEN AN ELEMENT OF THE LIST 0[Qd\b;Xbc1^g IS SELECTED YOU CHANGE THE DIRECTORY LISTING _aXePcT e^XS 0[Qd\b;Xbc1^gNBT[TRcX^]2WP]VTS^QYTRc bT]STa BT[TRcX^]2WP]VTS4eT]c0aVb T j dbX]V 8b^[PcTSBc^aPVT5X[T bc^aT , 8b^[PcTSBc^aPVT5X[T6TcDbTaBc^aT5^a0__[XRPcX^] j cWXb?W^c^;XbcQ^g8cT\bB^daRT , bc^aT6Tc5X[T=P\TbbcaX]V5^a\PcjlKK cWXb0[Qd\b;Xbc1^gBT[TRcTS8cT\* l l !S YOU CAN SEE YOUgVE USED A SEARCH FUNCTION WHICH WHEN USED WITH A WILDCARD COULD DISPLAY ALL THE FILES IN A SELECTED FOLDER (OWEVER YOU COULD APPLY A DIFFERENT PATTERN IN OTHER CASESFOR EXAMPLE IF THE USER WANTED TO DO A SEARCH WITHIN THE PHOTOS
5SAGE 2UN THE APPLICATION FROM 6ISUAL 3TUDIO BY PRESSING & 4HE APPLICATION CAN RUN ON EITHER THE PHYSICAL DEVICE OR THE EMULATOR (OWEVER YOU WILL NOT BE ABLE TO DEBUG THE APPLICATION ON THE PHYSICAL DEVICE IF YOU ARE CONNECTED TO :UNE BECAUSE IT STOPS THE MULTIMEDIA FUNCTIONALITIES 4O DEBUG USE 70#ONNECT 3TART THE APPLICATION CREATE AN ALBUM TAKE A PICTURE WITH THE CAMERA AND SAVE IT IN YOUR ALBUM #REATE ANOTHER ALBUM AND TAKE ANOTHER PHOTO AND SAVE THAT PHOTO IN THE SECOND ALBUM 3EARCH THROUGH THE ALBUMS IN YOUR APPLICATION TO VERIFY THE EFFECTIVE FUNCTIONING OF YOUR GALLERY 4HE PROCESS IS SHOWN IN &IGURES THROUGH TO GIVE YOU AN IDEA OF HOW THE APPLICATION WORKS .OTICE THAT THE PICTURES CREATED AND SAVED IN THIS WAY WILL BE NOT SAVED WITHIN THE MEDIA LIBRARY AND -ICROSOFT ENCOURAGES TO INTERACT WITH -EDIA HUB THEN CONSIDER A FUNCTION THAT IMPORTS THE IMAGE INSIDE MEDIA LIBRARY
&IGURE #REATING AN ALBUM
&IGURE 3ELECTING AN ALBUM
&IGURE #APTURING THE PHOTO
&IGURE #REATING ANOTHER ALBUM
&IGURE .AVIGATING THE ALBUM
&IGURE ,ISTING THE PICTURE IN THE ALBUM
CHAPTER ■■■
In the Cloud )N LAST YEARS THE MOBILE DEVICES MARKET IS INCREASED BECAUSE MODERN DEVICES COVERS MORE THAN THE SIMPLE NECESSITY TO MAKE A CALL4HIS CHAPTER COVERS INTERACTIONS WITH SERVICES hIN THE CLOUDv 9OU WILL SEE HOW 7INDOWS 0HONE IS DESIGNED TO ENABLE USERS TO ALWAYS REMAIN CONNECTED TO THE SERVICES THEY NEED 4HE RECIPES IN THIS CHAPTER DESCRIBE HOW TO DO THE FOLLOWING v
)NTERACT WITH 7#&
v
#REATE A FEED READER
v
#REATE A 'OOGLE !0)nBASED TRANSLATOR
v
5SE PUSH NOTIFICATION
)NTERACTING WITH 7#& 0ROBLEM 9OU WANT TO BUILD AN APPLICATION THAT INTERACTS WITH A SERVICE BY USING 7INDOWS #OMMUNICATION &OUNDATION 7#&
3OLUTION 9OU NEED TO CREATE YOUR SERVICE OR GET THE ADDRESS OF THE SERVICE THAT YOU WANT TO QUERY AND ADD A REFERENCE TO THAT SERVICE SO THAT YOU CAN QUERY YOUR METHODS AND ACCESS THE EXPOSED 3PcP2^]caPRc
(OW )T 7ORKS 7INDOWS 0HONE WAS CREATED TO USE SERVICES BUT YOU SHOULD ALWAYS REMEMBER ONE THING WHEN YOU WORK WITH IT SERVICE ACCESS IS ALWAYS ASYNCHRONOUS BECAUSE AS WITH THE USE OF SERVICES IN 3ILVERLIGHT FOR THE 7EB YOU MUST NOT FREEZE THE USER INTERFACE 4HE IMPLEMENTATION OF 3ILVERLIGHT FOR 7INDOWS 0HONE PROVIDES A LIMITED SET OF FEATURES TO WORK ON A NETWORK AS COMPARED TO ITS hBIG BROTHERv /NLY 7INDOWS #OMMUNICATION &OUNDATION 7cc_FTQAT`dTbc AND FTQ2[XT]c CAN BE USED WITH 3ILVERLIGHT FOR 7INDOWS 0HONE
7E WILL USE WEB SERVICES CONNECTING YOUR APPLICATION TO THE -ICROSOFT 2ESEARCH -APS SERVICE WHICH ENABLES US TO TAKE PICTURES OF THE WORLD VIA SATELLITE BASED ON 6T^2^^aSX]PcT
4HE #ODE 5NFORTUNATELY YOU CANNOT DYNAMICALLY CREATE A PROXY TO A SERVICE BY USING THE 2WP]]T[5PRc^ah+C2WP]]T[- CLASS BECAUSE IT IS NOT SUPPORTED BY THIS 7INDOWS 0HONE VERSION 4HEREFORE TO CREATE A REFERENCE YOU MUST USE THE COMMAND LINE TOOL b[beRdcX[TgT TO CREATE A PROXY FOR USE AT COMPILE TIME "ECAUSE CREATING A 7#& SERVICE IS NOT THE GOAL OF THIS BOOK )N THIS SECTION YOU WILL COMPLETE 2ECIPE FROM #HAPTER WHICH IS ABOUT THE USE OF THE -ICROSOFT 2ESEARCH -APS WEB SERVICE 4O COMPLETE THE RECIPE YOU NEED TO SEE HOW TO ADD A REFERENCE TO THE SERVICE SO THAT 6ISUAL 3TUDIO IS RUNNING ONLY THE b[beRdcX[TgT UTILITY TO CREATE A PROXY AS IN &IGURE
&IGURE !DD A SERVICE REFERENCE !S YOU LEARNED IN 2ECIPE TO USE "ING -APS YOU MUST BE REGISTERED AS A 7INDOWS 0HONE DEVELOPER 4HEREFORE YOU MIGHT PREFER TO USE THE MAP SERVICE OFFERED BY -ICROSOFT 2ESEARCH 4HEN YOU NEED TO ADD A REFERENCE CALLING IT CTaaPBTaeXRT TO THE SERVICE AVAILABLE AT Wcc_)\ba\P_bR^\CTaaPBTaeXRT!Pb\g AS SHOWN IN &IGURE !S YOU CAN SEE IN THE PICTURE THERE ARE MANY METHODS THAT YOU CAN CALL BUT WE ARE INTERESTED IN 6Tc0aTP5a^\?c AND 6TcCX[T
&IGURE 2EFERENCING A SERVICE !T THIS POINT YOU HAVE A REFERENCE TO YOUR SERVICE AND YOU CAN CALL THE METHOD THAT INTERESTS YOU )TS A BEST PRACTICE TO INSTANTIATE THE SERVER PROXY IN THE ;^PSTS EVENT HANDLER THEREBY ENSURING THAT THE APPLICATION STARTS AS SOON AS POSSIBLE AND THAT THE USER MAINTAINS CONTROL OF THE PHONE dbX]V <XRa^b^Uc?W^]T=Tc=Tcf^aZ8]U^a\PcX^]* CTaaPBTaeXRTCTaaPBTaeXRTB^P_2[XT]c _a^gh , ]d[[* 6T^2^^aSX]PcTFPcRWTa VT^FPcRWTa , ]d[[* 2^]bcadRc^a _dQ[XR
8]XiXP[XiTBTaeXRTb* ;^PSTS , ]Tf A^dcTS4eT]c7P]S[Ta
cWT 0RcdP[?^bXcX^] ]Tf CTaaPBTaeXRT;^];Pc?c j ;Pc , T?^bXcX^];^RPcX^];PcXcdST ;^] , T?^bXcX^];^RPcX^];^]VXcdST l CTaaPBTaeXRTBRP[TBRP[T!Z\ X]c2^]cT]c?P]T[0RcdP[FXScW X]c2^]cT]c?P]T[0RcdP[7TXVWc* l l
&IGURE #LASS DIAGRAM OF CLASSES USED BY 6Tc0aTP5a^\?c )N &IGURE YOU CAN SEE ALL THE CLASSES YOU NEED TO PREPARE A 6Tc0aTP5a^\?c REQUEST FOR WHOSE RESPONSE YOU MUST ANALYZE THE IMPLEMENTATION OF THE EVENT HANDLER THAT HANDLES THE RESPONSE
e^XS _a^ghN6Tc0aTP5a^\?c2^\_[TcTS^QYTRc bT]STa CTaaPBTaeXRT6Tc0aTP5a^\?c2^\_[TcTS4eT]c0aVb T j XU T4aa^a ,, ]d[[ j X]c bcPacG , TATbd[c=^acWFTbcCX[T
4O FURTHER CLARIFY THE USE OF THIS SERVICE PRESENTS SOME PROS AND CONS 0ROS 4HE SERVICE ALLOWS YOU TO RETRIEVE MAPS FOR EDUCATIONAL PURPOSES WITHOUT WORRYING ABOUT RECORD IN ANY PLACE LIKE HAPPENS WHEN YOU USE BING MAPS BUT SIMPLY MAKING REQUESTS 4HE SERVICE RESPONSES ARE RAPID AND THE SERVICE CAN BE INTERROGATED VIA DIFFERENT PROTOCOLS #ONS 4HE SERVICE PROVIDES NO SUPPORT FOR MAPS OUTSIDE THE 5NITED 3TATES
5SAGE .ORMALLY THIS APPLICATION NEEDS TO RUN ON A PHYSICAL DEVICE SO CHANGE YOUR OUTPUT TARGET TO 7INDOWS 0HONE $EVICE AND START THE APPLICATION PRESSING & THAN WAIT THAT YOUR APPLICATION BECOME AVAILABLE AND LOOK THAT THE MAP CHARGES
#REATING A &EED 2EADER 0ROBLEM 9OU WANT TO CREATE A FEED READER ABOUT A SERVICE AND FOLLOW THE LINK ATTACHED TO EVERY NEWS TO SEE THE DESTINATION INSINDE THE BROWSER
3OLUTION 9OU MUST USE AN OBJECT OF THE FTQ2[XT]c CLASS AND OPEN THE LINK BY USING FTQ1a^fbTaCPbZ
(OW )T 7ORKS &OR OUR APPLICATION WE CHOSE AN !TOM FEED MADE AVAILABLE BY THE "RITISH "ROADCASTING #ORPORATION ""# BUT ITS CLEAR THAT YOU CAN USE ALL FEEDS IN !TOM FORMAT ! FEED IS SIMPLY A DOCUMENT MADE AVAILABLE ON THE 7EB WE HOPE ALWAYS AT THE SAME ADDRESS IN AN 8-, FORMAT THAT FOLLOWS A SPECIFIC SYNTAX DESCRIBED IN THIS 83$ +gb)bRWT\P g\[]b)gb,Wcc_)ffff"^aV! G<;BRWT\P T[T\T]c5^a\3TUPd[c,`dP[XUXTS g\[]b)Pc^\,fffPc^\R^\+gb)X\_^ac ]P\Tb_PRT,fffPc^\R^\ bRWT\P;^RPcX^],Pc^\gbS+gb)T[T\T]c ]P\T,abb+gb)R^\_[TgCh_T+gb)bT`dT]RT+gb)T[T\T]c aTU,RWP]]T[+gb)bT`dT]RT+gb)PccaXQdcT ]P\T,eTabX^] ch_T,gb)bcaX]V+gb)PccaXQdcT ]P\T,g\[]b)Pc^\ ch_T,gb)bcaX]V+gb)R^\_[TgCh_T+gb)T[T\T]c+gb)T[T\T]c ]P\T,RWP]]T[-
+gb)R^\_[TgCh_T+gb)bT`dT]RT+gb)T[T\T]c aTU,[X]Z+gb)T[T\T]c aTU,cXc[T+gb)T[T\T]c aTU,[X]Z+gb)T[T\T]c aTU,STbRaX_cX^]+gb)T[T\T]c aTU,[P]VdPVT+gb)T[T\T]c aTU,R^_haXVWc+gb)T[T\T]c aTU,XcT\ \Pg>RRdab,d]Q^d]STS+gb)bT`dT]RT+gb)R^\_[TgCh_T+gb)T[T\T]c+gb)T[T\T]c ]P\T,cXc[T ch_T,gb)bcaX]V+gb)T[T\T]c ]P\T,[X]Z ch_T,gb)bcaX]V+gb)T[T\T]c ]P\T,STbRaX_cX^] ch_T,gb)bcaX]V+gb)T[T\T]c ]P\T,[P]VdPVT ch_T,gb)bcaX]V+gb)T[T\T]c ]P\T,R^_haXVWc ch_T,gb)bcaX]V+gb)T[T\T]c ]P\T,XcT\+gb)R^\_[TgCh_T+gb)bT`dT]RT+gb)T[T\T]c aTU,cXc[T+gb)T[T\T]c aTU,STbRaX_cX^]+gb)T[T\T]c aTU,[X]Z+gb)T[T\T]c aTU,_dQ3PcT+gb)T[T\T]c aTU,VdXS+gb)bT`dT]RT+gb)R^\_[TgCh_T+gb)T[T\T]c+gb)T[T\T]c ]P\T,_dQ3PcT ch_T,gb)bcaX]V+gb)T[T\T]c ]P\T,VdXS ch_T,gb)bcaX]V+gb)bRWT\P-
4HE #ODE 9OU CAN START WITH THE PRECEDING 83$TO GENERATE CLASSES THAT WORK TO SERIALIZEDESERIALIZE ACCORDING TO THE STRUCTURE DEFINED BY THE SCHEMA !ND THIS IS WHAT YOU ARE GOING TO DO NOW #REATE THREE CLASSES IN YOUR PROJECT WITH THESE NAMES v
Abb
v
2WP]]T[
v
8cT\
)N 2SSCS INCLUDE THE FOLLOWING CODE JG\[A^^c4[T\T]c=P\T,abb=P\Tb_PRT,L _dQ[XR R[Pbb Abb j _aXePcT 2WP]]T[ NRWP]]T[* _aXePcT bcaX]V NeTabX^]*
JG\[4[T\T]c4[T\T]c=P\T,RWP]]T[L _dQ[XR 2WP]]T[ 2WP]]T[ j VTc j aTcda] cWXbNRWP]]T[* l bTc j cWXbNRWP]]T[ , eP[dT* l l JG\[4[T\T]c4[T\T]c=P\T , eTabX^]L _dQ[XR bcaX]V ETabX^] j VTc j aTcda] cWXbNeTabX^]* l bTc j cWXbNeTabX^] , eP[dT* l l l 4HE ATTRIBUTES USED ON CLASS AND PROPERTIES SAY CLEARLY THAT YOU ARE GOING TO USE G\[BTaXP[XiTa TO DESERIALIZE THE RESPONSE IN YOUR CLASSES AND THEN GO UP WITH 2WP]]T[Rb J3PcP2^]caPRcL _dQ[XR R[Pbb 2WP]]T[ j _aXePcT bcaX]V _aXePcT bcaX]V _aXePcT bcaX]V _aXePcT bcaX]V _aXePcT bcaX]V _aXePcT bcaX]V _aXePcT 8cT\JL
NPc^\;X]Z* NcXc[T* N[X]Z* NSTbRaX_cX^]* N[P]VdPVT* NR^_haXVWc* NXcT\b*
JG\[4[T\T]c4[T\T]c=P\T , Pc^\)[X]ZL _dQ[XR 0c^\;X]Z 0c^\;X]Z j VTc j aTcda] cWXbNPc^\;X]Z* l
bTc j cWXbNPc^\;X]Z , eP[dT* l l JG\[4[T\T]c4[T\T]c=P\T , cXc[TL _dQ[XR bcaX]V CXc[T j VTc j aTcda] cWXbNcXc[T* l bTc j cWXbNcXc[T , eP[dT* l l JG\[4[T\T]c4[T\T]c=P\T , [X]ZL _dQ[XR bcaX]V ;X]Z j VTc j aTcda] cWXbN[X]Z* l bTc j cWXbN[X]Z , eP[dT* l l JG\[4[T\T]c4[T\T]c=P\T , STbRaX_cX^]L _dQ[XR bcaX]V 3TbRaX_cX^] j VTc j aTcda] cWXbNSTbRaX_cX^]* l bTc j cWXbNSTbRaX_cX^] , eP[dT* l l JG\[4[T\T]c4[T\T]c=P\T , [P]VdPVTL _dQ[XR bcaX]V ;P]VdPVT j VTc j aTcda] cWXbN[P]VdPVT* l
bTc j cWXbN[P]VdPVT , eP[dT* l l JG\[4[T\T]c4[T\T]c=P\T , R^_haXVWcL _dQ[XR bcaX]V 2^_haXVWc j VTc j aTcda] cWXbNR^_haXVWc* l bTc j cWXbNR^_haXVWc , eP[dT* l l JG\[4[T\T]c4[T\T]c=P\T , XcT\L _dQ[XR 8cT\JL 8cT\b j VTc j aTcda] cWXbNXcT\b* l bTc j cWXbNXcT\b , eP[dT* l l l !ND LAST BUT NOT LEAST HERE IS 8cT\Rb THIS IS THE MOST IMPORTANT CLASS IN OUR PROJECT AS IT WILL CONTAIN THE NEWS ITEMS IN THE FEED _dQ[XR R[Pbb 8cT\ j _aXePcT bcaX]V NcXc[T* _aXePcT bcaX]V NSTbRaX_cX^]* _aXePcT bcaX]V N[X]Z* _aXePcT bcaX]V N_dQ3PcT* _aXePcT bcaX]V NVdXS*
JG\[4[T\T]c4[T\T]c=P\T , cXc[TL _dQ[XR bcaX]V CXc[T j VTc j aTcda] cWXbNcXc[T* l bTc j cWXbNcXc[T , eP[dT* l l JG\[4[T\T]c4[T\T]c=P\T , STbRaX_cX^]L _dQ[XR bcaX]V 3TbRaX_cX^] j VTc j aTcda] cWXbNSTbRaX_cX^]* l bTc j cWXbNSTbRaX_cX^] , eP[dT* l l JG\[4[T\T]c4[T\T]c=P\T , [X]ZL _dQ[XR bcaX]V ;X]Z j VTc j aTcda] cWXbN[X]Z* l bTc j cWXbN[X]Z , eP[dT* l l JG\[4[T\T]c4[T\T]c=P\T , _dQ3PcTL _dQ[XR bcaX]V ?dQ3PcT j VTc j aTcda] cWXbN_dQ3PcT* l bTc j cWXbN_dQ3PcT , eP[dT* l l
JG\[4[T\T]c4[T\T]c=P\T , VdXSL _dQ[XR bcaX]V 6dXS j VTc j aTcda] cWXbNVdXS* l bTc j cWXbNVdXS , eP[dT* l l T
l
.OW THAT YOU HAVE PREPARED THE CONTAINERS FOR YOUR DATA ITgS TIME TO RETRIEVE THEM FROM THE CLOUD BY USING THE FTQ2[XT]c CLASS )N YOUR
&IGURE #LASS DIAGRAM FOR FTQ1a^fbTaCPbZ
9OU INSTANTIATE A FTQ2[XT]c AND THEN SUBSCRIBE TO THE >_T]ATPS2^\_[TcT EVENT WHICH FIRES AFTER >_T]ATPS0bh]R COMPLETELY EXECUTES >_T]ATPS2^\_[TcT ONLY DESERIALIZES THE RESULT OF THE REQUEST IN YOUR OBJECT e^XS fRN>_T]ATPS2^\_[TcTS^QYTRc bT]STa >_T]ATPS2^\_[TcTS4eT]c0aVb T j G\[BTaXP[XiTa g\b , ]Tf G\[BTaXP[XiTach_T^UAbb* Abb STb , g\b3TbTaXP[XiTTATbd[c Pb Abb* =Tfb;Xbc8cT\bB^daRT , STb2WP]]T[8cT\b* l !T THIS POINT ALL YOU HAVE TO DO IS TO MANAGE THE CLICK OF THE HYPERLINK BUTTON BY THE USER OPENING THE BROWSER _aXePcT e^XS 7h_Ta[X]Z1dcc^]N2[XRZ^QYTRc bT]STa A^dcTS4eT]c0aVb T j 7h_Ta[X]Z1dcc^] W_Q , bT]STa Pb 7h_Ta[X]Z1dcc^]* fTQ1a^fbTaCPbZDA; , W_Q2^]cT]cC^BcaX]V* fTQ1a^fbTaCPbZBW^f* l
■ .OTE 4HERE IS A PROBLEM IN FTQ1a^fbTaCPbZ THAT SOMETIMES DOESNT OPEN THE SITE WE HAVE NOTICED THIS PROBLEM ONLY WHEN THE DEVICE IS CONNECTED TO :UNE
5SAGE &ROM 6ISUAL 3TUDIO PRESS #TRL & 4HE TYPE OF TARGET IS NOT IMPORTANT AS THIS RECIPE CAN WORK AS FINE ON THE EMULATOR AS ON THE DEVICE 4HE APPLICATION WILL START BRIEFLY SHOWING THE SPLASH SCREEN AND THEN THE MAIN PAGE !FTER A FEW SECONDS DEPENDING ON YOUR )NTERNET CONNECTION A LIST OF NEWS ITEMS WILL DISPLAY #LICK THE HYPERLINK BUTTON TO ACCESS THE "ROWSE FUNCTION AND OPEN THE LINK RELATIVE TO THE NEWS
#REATING A 'OOGLE !0)n"ASED 4RANSLATOR 0ROBLEM 9OU WANT TO CREATE AN APPLICATION THAT INTERACTS WITH A 2EPRESENTATIONAL 3TATE 4RANSFER 2%34FUL SERVICE THAT RETURNS A RESPONSE IN *AVA3CRIPT /BJECT .OTATION *3/. FORMAT
3OLUTION 9OU MUST USE FTQ2[XT]c AND 3PcP2^]caPRc9b^]BTaXP[XiTa
(OW )T 7ORKS FTQ2[XT]c PROVIDES COMMON METHODS FOR SENDING AND RECEIVING DATA TO AND FROM A RESOURCE IDENTIFIED BY A 52) )N THIS CASE THE RESOURCE WILL GIVE YOU A RESPONSE IN *3/. FORMAT 4HEN YOU WILL USE 3PcP2^]caPRc9b^]BTaXP[XiTa TO DESERIALIZE THE RESPONSE INSIDE YOUR OBJECT GRAPH
4HE #ODE &OR THE PURPOSES OF THIS EXERCISE YOU WILL USE AN !0) MADE AVAILABLE BY 'OOGLE FOR THE TRANSLATION OF TEXTS 4O USE THIS !0) YOU MUST HAVE A KEY TO ACCESS THE SERVICE ITSELF 4HE APPLICATION THAT YOU WILL CREATE IN TERMS OF THE 5) IS QUITE SIMPLE )T WILL HAVE A TEXT BOX FOR ENTERING TEXT TO BE TRANSLATED A BUTTON TO START THE INTERACTION WITH THE SERVICE AND A TEXT BLOCK TO SHOW THE RESULT OF YOUR REQUEST WHICH IN THIS CASE WILL BE A TRANSLATION FROM %NGLISH TO )TALIAN (ERE IS THE 8!-, THAT COMPOSES OUR INTERFACE +6aXS G)=P\T,2^]cT]c?P]T[ 6aXSA^f, <PaVX], ! !+6aXSA^f3TUX]XcX^]b+A^f3TUX]XcX^] 7TXVWc, +A^f3TUX]XcX^] 7TXVWc,0dc^ +A^f3TUX]XcX^] 7TXVWc, + 6aXSA^f3TUX]XcX^]b+CTgc1^g =P\T,CTgcC^CaP]b[PcTCTgcQ^g CTgc,CaP]b[PcT
4HEN IN THE CODE BEHIND OF YOUR ?W^]T0__[XRPcX^]?PVT ADD CLASS LEVEL MEMBER AS FOLLOWS FTQ2[XT]c _a^gh , ]d[[* 4HE FTQ2[XT]c CLASS PROVIDES COMMON METHODS FOR SENDING AND RECEIVING DATA FROM A RESOURCE IDENTIFIED BY AN 52) SO ITS PERFECT FOR OUR PURPOSE _aXePcT FTQ2[XT]c _a^gh , ]d[[* !ND NOW IN THE CONSTRUCTOR OF YOUR PAGE YOU NEED TO INSTANTIATE THE PROXY AND PREPARE IT TO MANAGE THE RESPONSE OF AN >_T]ATPS REQUEST _a^gh , ]Tf FTQ2[XT]c * _a^gh>_T]ATPS2^\_[TcTS , ]Tf >_T]ATPS2^\_[TcTS4eT]c7P]S[Ta _a^ghN>_T]ATPS2^\_[TcTS* )N THE EVENT HANDLER YOU WILL INSERT CODE TO HANDLE THE RESPONSE BUT LETS FOCUS FIRST ON THE REQUEST WHICH WILL BE LINKED TO THE CLICK OF CaP]b[PcT1dcc^] q _aXePcT e^XS CaP]b[PcT1dcc^]N2[XRZ ^QYTRc bT]STa A^dcTS4eT]c0aVb T j cah j XU BcaX]V8b=d[[>a4\_ch CTgcC^CaP]b[PcTCTgcQ^gCTgc j DaX aT`dTbc , QdX[S6^^V[TCaP]b[PcTAT`dTbc CTgcC^CaP]b[PcTCTgcQ^gCTgc* _a^gh>_T]ATPS0bh]R aT`dTbc* l l RPcRW 4gRT_cX^] Tg j 3^ b^\TcWX]V fXcW cWXb TgRT_cX^] l l !ND QdX[S6^^V[TCaP]b[PcTAT`dTbcbcaX]V IS OUR PRIVATE METHOD THAT CREATES THE 52) FOR YOUR REQUEST _aXePcT DaX QdX[S6^^V[TCaP]b[PcTAT`dTbcbcaX]V cTgcC^CaP]b[PcT j aTcda] ]Tf DaXWcc_b)fffV^^V[TP_XbR^\[P]VdPVTcaP]b[PcTe!. ZTh,H>DAN0?8N:4HN74A4 `, cTgcC^CaP]b[PcT b^daRT,T] cPaVTc,Xc _aTcch_aX]c,cadT* l
!S A RESULT OF THIS REQUEST THE APPLICATION WILL GIVE YOU AN OBJECT SERIALIZED IN *3/. FORMATMORE PRECISELY THE FORMAT IS AS FOLLOWS j 3PcP) j CaP]b[PcX^]b) J j CaP]b[PcTSCTgc) CTgc l L l l 4HAT TELLS YOU THAT THE ROOT OBJECT OF THE OBJECT GRAPH HAS AN INTERNAL OBJECT OF TYPE 3PcT WHICH IN TURN CONTAINS AN ARRAY OF OBJECTS OF TYPE CaP]b[PcX^]b WHICH IN TURN CONTAINS A PROPERTY OF TYPE bcaX]V CALLED CaP]b[PcTSCTgc &IGURE SHOWS THE CLASS DIAGRAM
&IGURE #LASS DIAGRAM OF CLASSES USED TO DESERIALIZE THE OBJECTS 4HE IMPLEMENTATION OF 6^^V[TCaP]b[PcX^] IS AS FOLLOWS
'OOGLE4RANSLATIONCS J3PcP2^]caPRcL _dQ[XR R[Pbb 6^^V[TCaP]b[PcX^] j J3PcP
$ATACS J3PcP2^]caPRcL _dQ[XR R[Pbb 3PcP j J3PcP
4RANSLATIONCS J3PcP2^]caPRcL _dQ[XR R[Pbb CaP]b[PcX^] j J3PcP
5SAGE /PEN 6ISUAL 3TUDIO AND START DEPLOYING THE APPLICATION TO THE EMULATOR 7RITE A SENTENCE IN THE TEXT BOX AND LOOK FOR THE TRANSLATION /F COURSE YOU NEED TO STAY CONNECTED TO THE )NTERNET TO USE THIS RECIPE
0USHING 9OUR .OTIFICATION 0ROBLEM 9OU WANT TO BUILD AN APPLICATION THAT USES PUSH NOTIFICATION TO INDICATE TO THE USER THAT SOMETHING HAS CHANGED IN THE CLOUD
3OLUTION 9OU MUST USE THE 0USH .OTIFICATION 3ERVICE TO INDICATE THE CHANGE THAT HAS HAPPENED
(OW )T 7ORKS 4HE -ICROSOFT 0USH .OTIFICATION 3ERVICE IN 7INDOWS 0HONE GIVES YOU THE CAPABILITY TO SEND INFORMATION AND UPDATES TO AN APPLICATION FROM A WEB SERVICE 4HIS NEW WAY OF INTERACTING WITH A SERVICE HIDES THE LACK OF MULTITASKING IN 7INDOWS 0HONE 0USH NOTIFICATION WORKS AS SHOWN IN &IGURE !NOTHER GOOD REASON TO USE PUSH NOTIFICATION IS THE NEED TO PRESERVE BATTERY POWER )F APPLICATIONS ARE CONTINUOUSLY POLLING TO CHECK FOR NEW NOTIFICATIONS THE DEVICES BATTERY WILL QUICKLY RUN DOWN
&IGURE 0USH NOTIFICATION ARCHITECTURE 9OUR WEB SERVICE SENDS A NOTIFICATION TO THE -ICROSOFT 0USH .OTIFICATION 3ERVICE WHICH ROUTES THE NOTIFICATION TO THE USERS DEVICE INTERFACING WITH PUSH NOTIFICATION CLIENT THAT NOTIFY TO YOUR APPLICATION THAT SOMETHING NEW IS READY DO KNOW
■ .OTE 9OUR APPLICATION WILL HAVE ONLY ONE CHANNEL AVAILABLE TO ESTABLISH A CONNECTION TO THE 0USH .OTIFICATION 3ERVICE 4HE USER CAN ACTIVATE A MAXIMUM OF APPLICATIONS THAT USE PUSH NOTIFICATION )F YOUR APPLICATION RESULTS IN EXCEEDING THESE QUOTAS AN h)NVALID/PERATION%XCEPTION #HANNEL QUOTA EXCEEDED v ERROR WILL BE RAISED
!FTER YOUR NOTIFICATION IS DELIVERED THE 0USH .OTIFICATION 3ERVICE SENDS A RESPONSE TO YOUR SERVICE "UT REMEMBER THAT YOU WILL NOT RECEIVE A CONFIRMATION THAT YOUR NOTIFICATION WAS DELIVERED 4HERE ARE THREE TYPES OF PUSH NOTIFICATION THAT YOU CAN USE TILE TOAST AND RAW 4HE DETAILS ARE AS FOLLOWS 4ILE NOTIFICATION %VERY APPLICATION HAS A TILE A DYNAMIC REPRESENTATION OF THE APPLICATION THAT IS DISPLAYED ON THE START SCREEN IF THE USER CHOOSES THIS OPTION &IGURE SHOWS INSIDE THE RECTANGLE THE DEFAULT SETTINGS THAT YOUR APPLICATION WILL USE FOR TILE NOTIFICATION ! TILE IS COMPOSED OF THE FOLLOWING THREE ELEMENTS WHICH YOU CAN UPDATE #OUNT !N INTEGER THAT CAN ASSUME A VALUE BETWEEN AND AND THAT IS DISPLAYED ON THE TILE IN A CIRCLE IMAGE 4ITLE ! STRING SET DURING DEVELOPMENT SEE &IGURE "ACKGROUND 4HE BACKGROUND IMAGE CONTAINED IN YOUR PROJECT SEE &IGURE
■ .OTE 4HE TITLE MUST FIT ON A SINGLE LINE OF TEXT )F YOU DONT SET THIS VALUE WILL BE DISPLAYED THE ALREADY DEFINED TITLE
■ .OTE )F NO #OUNT VALUES ARE SET NOTHING WILL BE SHOWN )F YOU WANT TO RESET THE COUNT IN THE TILE YOU MUST USE ZERO AS THE VALUE
&IGURE 4ILE OPTIONS IN THE PROJECT PROPERTIES
&IGURE 4HE BACKGROUND IMAGE IN 3OLUTION %XPLORER
&IGURE 4HE "ACKGROUND IMAGE PINNED IN THE START PAGE 4OAST NOTIFICATION 4HIS CONSISTS OF A MESSAGE SHOWN IN THE TOP PART OF THE SCREEN AND COMPOSED OF A TITLE AND A SUBTITLE 4HESE TWO PROPERTIES ARE SIMPLY STRINGS WITH THE TITLE HAVING A BOLD WEIGHT AND THE SUBTITLE APPEARING AS NORMAL TEXT 9OU CAN SEE AN EXAMPLE OF TOAST NOTIFICATION WHEN YOU RECEIVE A TEXT MESSAGE AND YOU WILL HAVETHE NAME OF THE PERSON CONTACTING YOU AS THE TITLE AND THE TEXT AS THE SUBTITLE
2AW NOTIFICATION 4HIS NOTIFICATION IS SENT DIRECTLY TO YOUR APPLICATION AND CAN BE MAXIMUM OF +"
■ .OTE )F YOU SEND A RAW NOTIFICATION AND YOUR APP IS NOT RUNNING THE 0USH .OTIFICATION 3ERVICE WILL DISCARD YOUR NOTIFICATION
)N THIS RECIPE YOU WILL SIMULATE A NOTIFICATION BY SENDING A MESSAGE TO THE -ICROSOFT 0USH .OTIFICATION 3ERVICE VIA AN APPLICATION CREATED BY US 4HIS IS ONLY A SIMULATION BECAUSE ITS NOT THE PURPOSE OF THIS BOOK TO EXPLAIN HOW TO WRITE A WEB SERVICE
4HE #ODE #REATE A NEW SOLUTION NAMING IT F?&ATRX_T(# ?dbW =^cXUXRPcX^] 4HE FIRST THING TO DO IS TO DEFINE A CONSTANT AS A STRING IN THE CODE WHICH IDENTIFIES THE CHANNEL THAT YOUR APPLICATION WILL USE IN THE FUTURE 4HEN IN 0__gP\[Rb YOU WRITE THIS 2WP]VT cWXb eP[dT fXcW h^da RWP]]T[ ]P\T _aXePcT R^]bc bcaX]V RWP]]T[=P\T , =^cXUXRPcX^]CTbc* .OW YOU HAVE THE CHANNEL NAME BUT YOURE MISSING THE MOST IMPORTANT OBJECT 7cc_=^cXUXRPcX^]2WP]]T[ 3O YOU DECLARE IT 7cc_=^cXUXRPcX^]2WP]]T[ ]^cXUXRPcX^]2WP]]T[* 7cc_=^cXUXRPcX^]2WP]]T[ IS THE CLASS THAT SUPPORTS ON THE CLIENT SIDE THE PROCESS OF NOTIFICATION TO THE USER AS YOU CAN SEE IN &IGURE 4HIS CLASS PUTS AT YOUR DISPOSAL SEVERAL METHODS THE FIRST OF WHICH IS 5X]S 4HE 5X]S METHOD IS USED TO CHECK WHETHER ANY NOTIFICATION CHANNELS WITH THE NAME THAT YOU HAVE SET RWP]]T[=P\T ALREADY EXIST ON THE DEVICE AND IF EXIST RETURNS IT 4HIS METHOD IS VERY IMPORTANT FOR CONTROLLING THE MAXIMUM NUMBER OF CHANNELS THAT CAN BE CREATED ON A DEVICE !LSO IN FIGURE YOU CAN SEE THAT 7cc_=^cXUXRPcX^]2WP]]T[ DOESNT HAVE A PARAMETERLESS CONSTRUCTOR BECAUSE YOU NEED TO SPECIFY AT LEAST THE CHANNEL NAME
&IGURE #LASS DIAGRAM OF 7cc_=^cXUXRPcX^]2WP]]T[ AND EVENT ARGS CLASSES .OW LETS TAKE A LOOK AT THE METHOD TO CALL INSIDE THE CONSTRUCTOR OF THE APP TO SEE THE OTHERS IMPORTANT PROPERTIES AND EVENTS TO SUBSCRIBE TO _aXePcT e^XS X]Xc=^UXcXRPcX^]2WP]]T[ j cah j ]^cXUXRPcX^]2WP]]T[ , 7cc_=^cXUXRPcX^]2WP]]T[5X]SRWP]]T[=P\T* XU ]^cXUXRPcX^]2WP]]T[ ,, ]d[[ j ]^cXUXRPcX^]2WP]]T[ , ]Tf 7cc_=^cXUXRPcX^]2WP]]T[RWP]]T[=P\T*
]^cXUXRPcX^]2WP]]T[4aa^a>RRdaaTS , ]Tf 4eT]c7P]S[Ta+=^cXUXRPcX^]2WP]]T[4aa^a4eT]c0aVb- ]^cXUXRPcX^]2WP]]T[N4aa^a>RRdaaTS* ]^cXUXRPcX^]2WP]]T[2WP]]T[DaXD_SPcTS , ]Tf 4eT]c7P]S[Ta+=^cXUXRPcX^]2WP]]T[DaX4eT]c0aVb- ]^cXUXRPcX^]2WP]]T[N2WP]]T[DaXD_SPcTS* ]^cXUXRPcX^]2WP]]T[>_T]* l XU ]^cXUXRPcX^]2WP]]T[8bBWT[[CX[T1^d]S ]^cXUXRPcX^]2WP]]T[1X]SC^BWT[[CX[T* XU ]^cXUXRPcX^]2WP]]T[8bBWT[[C^Pbc1^d]S ]^cXUXRPcX^]2WP]]T[1X]SC^BWT[[C^Pbc* ]^cXUXRPcX^]2WP]]T[7cc_=^cXUXRPcX^]ATRTXeTS , ]Tf 4eT]c7P]S[Ta+7cc_=^cXUXRPcX^]4eT]c0aVb- ]^cXUXRPcX^]2WP]]T[N7cc_=^cXUXRPcX^]ATRTXeTS* ]^cXUXRPcX^]2WP]]T[BWT[[C^Pbc=^cXUXRPcX^]ATRTXeTS , ]Tf 4eT]c7P]S[Ta+=^cXUXRPcX^]4eT]c0aVb- ]^cXUXRPcX^]2WP]]T[NBWT[[C^Pbc=^cXUXRPcX^]ATRTXeTS* l RPcRW 8]eP[XS>_TaPcX^]4gRT_cX^] Tg j ]^cXUh cWT dbTa ^U cWXb _a^Q[T\
4aa^a>RRdaaTS OCCURS WHENEVER THERE IS A PROBLEM IN THE USE OF CLASS AND ALSO LATER DURING THE RECEPTION OF NOTIFICATIONS COULD BE RAISED
v
2WP]]T[DaXD_SPcTS WILL BE RAISED AFTER YOU RECEIVE THE 52) ON -ICROSOFT 0USH .OTIFICATION 3ERVICE OF YOUR CHANNEL THAT WILL ALLOW YOU TO SEND NOTIFICATIONS DIRECTLY ON YOUR DEVICE
4HEN OPEN THE CHANNEL 4HIS MAY TRIGGER THE EXCEPTION THAT WE MENTIONED EARLIER 8]eP[XS>_TaPcX^]4gRT_cX^] 4HIS TELLS YOU THAT THERE ARE ALREADY TOO MANY APPLICATIONS THAT USE PUSH NOTIFICATION ON THE DEVICE )F YOU DONT HAVE PERMISSION TO USE NOTIFICATION IN YOUR APP YOU MAY WANT TO NOTIFY THE USER FOR EXAMPLE WITH A MESSAGE BOX THAT HAVING TOO MANY OPEN CHANNELS ON THE DEVICE BLOCKS THE FULL USE OF YOUR APPLICATION ESPECIALLY IF YOUR APPLICATION IS MEANT TO MAKE WIDE USE OF NOTIFICATIONS )N THIS EXAMPLE YOU BIND THE CHANNEL DIRECTLY TO THE NOTIFICATIONS TILE AND TOAST (OWEVER REMEMBER THAT TO USE TOAST NOTIFICATION YOU MUST ALLOW THE USER TO TURN THEM OFF FROM THE CONTROL PANEL OF YOUR APPLICATION SEE #HAPTER FOR FURTHER EXPLANATION !FTER THIS YOU SUBSCRIBE TO THE TWO EVENTS 7cc_=^cXUXRPcX^]ATRTXeTS AND BWT[C^Pbc=^cXUXRPcX^]ATRTXeTS 4HE FIRST WILL BE RAISED WHEN A RAW NOTIFICATION IS RECEIVED 4HE SECOND WILL BE RAISED WHEN THE APPLICATION RECEIVES A TOAST NOTIFICATION 4HIS EVENT WILL OCCUR ONLY IF THE APPLICATION IS RUNNING IN THE FOREGROUND .OW TAKE A LOOK AT THE 2WP]]T[DaXD_SPcTS EVENT HANDLER )N THIS EXAMPLE YOU WRITE AT THE DEBUG CONSOLE THE CHANNEL 52) BUT YOU HAVE TO ADD THE LOGIC TO NOTIFY YOUR WEB SERVICE OF THE ADDRESS TO WHICH THE PUSH NOTIFICATION IS SENT e^XS ]^cXUXRPcX^]2WP]]T[N2WP]]T[DaXD_SPcTS^QYTRc bT]STa =^cXUXRPcX^]2WP]]T[DaX4eT]c0aVb T j 3TQdVFaXcT;X]TT2WP]]T[DaX* cWXb Xb cWT R^ST c^ ]^cXUh h^da fTQbTaeXRT ^UcWT DaX ^U cWT RWP]]T[ l 4HE RWP]]T[DaX ^QYTRc WILL BE SOMETHING LIKE THIS Wcc_)SQ"]^cXUh[XeT]TccWa^cc[TScWXaS_Pach GGGGGGGGGGGGGGGGG 9OU WOULD REPLACE ALL THE 8S WITH THE IDENTIFICATION OF YOUR CHANNEL 4HE CONCEPT IS SIMPLE YOU HAVE RECEIVED THIS CHANNEL AND NOW YOUR SERVICE CAN SEND NOTIFICATIONS (OWEVER BECAUSE IT IS NOT OUR AIM TO SHOW YOU HOW TO MAKE A SERVICE WE WILL INSTEAD SHOW YOU HOW TO BUILD A SMALL TEST APPLICATION TO SEND NOTIFICATIONS TO THE DEVICE /PEN 6ISUAL 3TUDIO #REATE A DESKTOP APPLICATION AND CALL IT BT]S=^cXUXRPcX^]0__[XRPcX^] )N THE 8!-, OF THE MAIN PAGE CREATE THE FOLLOWING STRUCTURE +FX]S^f g\[]b,Wcc_)bRWT\Pb\XRa^b^UcR^\fX]Ug!%gP\[_aTbT]cPcX^] g\[]b)g,Wcc_)bRWT\Pb\XRa^b^UcR^\fX]Ug!%gP\[ g\[]b)S,Wcc_)bRWT\Pb\XRa^b^UcR^\Tg_aTbbX^]Q[T]S!' g\[]b)\R,Wcc_)bRWT\Pb^_T]g\[U^a\Pcb^aV\PaZd_R^\_PcXQX[Xch!% \R)8V]^aPQ[T,S g)2[Pbb,BT]S=^cXUXRPcX^]0__[XRPcX^]
+A^f3TUX]XcX^] 7TXVWc,!$ +A^f3TUX]XcX^] 7TXVWc,!$ +A^f3TUX]XcX^] 7TXVWc,!$ +A^f3TUX]XcX^] 7TXVWc,!$ +A^f3TUX]XcX^] 7TXVWc,!$ +A^f3TUX]XcX^] 7TXVWc,!$ +A^f3TUX]XcX^] 7TXVWc, +6aXSA^f3TUX]XcX^]b+CTgc1[^RZ CTgc,=^cXUXRPcX^] DaX +CTgc1^g g)=P\T,=^cXUXRPcX^]DaXCTgc1^g 6aXS2^[d\], +CTgc1[^RZ CTgc,CTgc 6aXSA^f, +CTgc1^g g)=P\T,5XacbA^fCTgc1^g 6aXSA^f, 6aXS2^[d\], +CTgc1[^RZ CTgc,CTgc ! 6aXSA^f,! +CTgc1^g g)=P\T,BTR^]SA^fCTgc1^g 6aXSA^f,! 6aXS2^[d\], +CTgc1[^RZ CTgc,1PRZVa^d]S 6aXSA^f,# +CTgc1^g g)=P\T,1PRZVa^d]SCTgc1^g 6aXSA^f,# 6aXS2^[d\], +CTgc1[^RZ CTgc,2^d]c 6aXSA^f,$ +CTgc1^g g)=P\T,2^d]cCTgc1^g 6aXSA^f,$ 6aXS2^[d\], +CTgc1[^RZ CTgc,CXc[T 6aXSA^f,% +CTgc1^g g)=P\T,CXc[TCTgc1^g 6aXSA^f,% 6aXS2^[d\], +1dcc^] g)=P\T,BT]SCX[T=^cXUXRPcX^]1dcc^] 6aXSA^f,& 6aXS2^[d\]B_P],! 2^]cT]c,BT]S CX[T =^cXUXRPcX^] 2[XRZ,BT]SCX[T=^cXUXRPcX^]1dcc^]N2[XRZ +1dcc^] g)=P\T,BT]SC^Pbc=^cXUXRPcX^]1dcc^] 6aXSA^f," 6aXS2^[d\]B_P],! 2^]cT]c,BT]S C^Pbc =^cXUXRPcX^] 2[XRZ,BT]SC^Pbc=^cXUXRPcX^]1dcc^]N2[XRZ +CTgc1[^RZ g)=P\T,ATb_^]bTCTgc1^g 6aXSA^f,' CTgc0[XV]\T]c,;TUc 6aXS2^[d\]B_P],! +6aXS+FX]S^f4HAT WILL DISPLAY SOMETHING LIKE &IGURE 4HEN YOU WRITE THE TWO EVENT HANDLERS FOR THE TWO BUTTONS 4HE FIRST EVENT HANDLER IS BT]SCX[T=^cXUXRPcX^]1dcc^]N2[XRZ WHICH TAKES THE SUBSCRIPTION 52) FROM THE TEXT BOX AND THEN CREATES THE REQUEST 9OU MUST ALWAYS REMEMBER THAT YOU CANT SEND A NOTIFICATION VIA THE 64C METHOD BUT ONLY WITH ?>BC !FTER THIS THE NEXT STEP IS TO ADD HEADERS TO YOUR REQUEST /PTIONALLY YOU CAN ADD AN G
_aXePcT e^XS BT]SCX[T=^cXUXRPcX^]1dcc^]N2[XRZ^QYTRc bT]STa A^dcTS4eT]c0aVb T j bcaX]V bdQbRaX_cX^]DaX , cWXb=^cXUXRPcX^]DaXCTgc1^gCTgc* 7cc_FTQAT`dTbc bT]S=^cXUXRPcX^]AT`dTbc , 7cc_FTQAT`dTbcFTQAT`dTbc2aTPcTbdQbRaX_cX^]DaX* bT]S=^cXUXRPcX^]AT`dTbc
&IGURE 4HE 3END .OTIFICATION APPLICATION INTERFACE /N THE OTHER HAND YOU HAVE THE CODE TO SEND A TOAST NOTIFICATION THAT APPEARS LARGELY SIMILAR TO THE CODE FOR THE TILE NOTIFICATION 4HE MAIN DIFFERENCE IS IN THE FORMAT OF THE 8-, THAT MAKES UP THE NOTIFICATION )N THIS CASE G=^cXUXRPcX^]2[Pbb CAN TAKE THE VALUE OR REFLECTING A DELAY IN SENDING THE NOTIFICATION OF AND SECONDS RESPECTIVELY _aXePcT e^XS BT]SC^Pbc=^cXUXRPcX^]1dcc^]N2[XRZ^QYTRc bT]STa A^dcTS4eT]c0aVb T j bcaX]V bdQbRaX_cX^]DaX , cWXb=^cXUXRPcX^]DaXCTgc1^gCTgc* 7cc_FTQAT`dTbc bT]S=^cXUXRPcX^]AT`dTbc , 7cc_FTQAT`dTbc FTQAT`dTbc2aTPcTbdQbRaX_cX^]DaX* bT]S=^cXUXRPcX^]AT`dTbc
bcaX]V c^Pbc
&IGURE 4HE RESULT OF SENDING THE NOTIFICATION
5SAGE /PEN THESE TWO PROJECTS AND START DEPLOYING THE APPLICATION TO THE 7INDOWS 0HONE %MULATOR 'ET THE NOTIFICATION 52) FROM THE DEBUG CONSOLE AND THEN USE IT IN BT]S=^cXUXRPcX^]0__[XRPcX^] 2EMEMBER THAT TO SEE THE TOAST NOTIFICATION YOU MUST HAVE YOUR APPLICATION RUNNING IN THE BACKGROUND
CHAPTER ■■■
Testing Windows Phone Applications 7HEN YOUR APPLICATION IS COMPLETE YOU ARE READY TO PUBLISH IT UNLESS YOU HAVE MADE IT ONLY AS AN EXERCISE %VEN IF -ICROSOFT WERE TO RAISE THE LIMIT OF FREE APPLICATIONS THAT YOU COULD PUBLISH TO NONE OF THOSE APPLICATIONS SHOULD BE USELESS 4O BE INSTALLED YOUR APPLICATION MUST BE SIGNED BY -ICROSOFT WITH AN !UTHENTICODE CERTIFICATE 4HE BEST WAY TO OBTAIN AN !UTHENTICODE CERTIFICATE IS TO FOLLOW -ICROSOFTS RULES AND UNDERSTAND THE !PPLICATION #ERTIFICATION 'UIDELINES WHICH ARE AVAILABLE AT V^\XRa^b^UcR^\.[X]ZXS,(&"$$' (OWEVER -ICROSOFTS !UTHENTICODE CERTIFICATE IS ONLY PART OF WHAT IS NEEDED FOR A SUCCESSFUL APPLICATION 3AY FOR EXAMPLE THAT -ICROSOFT BELIEVES THAT YOUR APPLICATION COMPLIES WITH THE RULES OF THE MARKETPLACE BUT FOR SOME hINEXPLICABLEv REASON YOUR APPLICATION CRASHES WHILE THE USER USES IT 4HE USER MIGHT NOT MIND THE FIRST TIME HOPING THAT THE CRASH WAS AN EXTRAORDINARY CASE "UT IF A CRASH OCCURS MORE OFTEN THE USER WILL LIKELY DELETE YOUR APPLICATION AND YOU WILL HAVE WASTED YOUR TIME 4HIS CHAPTER INTRODUCES YOU TO CONCEPTS INCLUDING 3EPARATION OF #ONCERNS AND THE -ODEL 6IEW 6IEW-ODEL PATTERN 4HESE ENABLE YOU NOT ONLY TO PROVIDE A SEPARATION OF ROLES BETWEEN YOUR COMPONENTS BUT ALSO TO MAKE YOUR APPLICATION CAPABLE OF UNDERGOING UNIT TESTING "UT FIRST YOU MUST UNDERSTAND WHAT IS MEANT BY 3O# AND UNIT TESTING 3EPARATION OF #ONCERNS 3O# IS ONE OF THE KEY PRINCIPLES OF SOFTWARE ENGINEERING 4O ACHIEVE SOFTWARE OF A GOOD QUALITYTHAT IS SOFTWARE THAT HAS ROBUSTNESS ADAPTABILITY MAINTAINABILITY AND REAUSABILITYYOU MUST DECOUPLE THE CONCERN OF ONE ELEMENT FROM ANOTHER &OR EXAMPLE IT IS THE CONCERN OF THE 6IEW TO SHOW INFORMATION AND THE WAY TO DO IT BUT 6IEW-ODEL IS RESPONSIBLE FOR RETRIEVING INFORMATION AND PREPARING THAT INFORMATION FOR 6IEW )N UNIT TESTING CODE IS WRITTEN TO TEST A SMALL PIECE OF SOURCE CODE THAT REPRESENTS A SINGLE FUNCTIONALITYOR TO BE MORE ACCURATE TO TEST THAT FUNCTIONALITY IN A PARTICULAR CONDITION 4HEREFORE ONE FUNCTIONALITY CAN HAVE MORE THAN ONE UNIT TEST 4O UNDERLINE THE IMPORTANCE OF UNIT TESTING LETS COMPARE THIS APPROACH WITH THE DEBUG APPROACH )F YOU WRITE A TEST AND THEN CHANGE YOUR CODE YOU CAN RUN THE TEST SUITE AGAIN TO SEE WHETHER SOMETHING WAS BROKEN BY YOUR MODIFICATIONS THIS IS KNOWN AS REGRESSION TESTING (OWEVER IF YOU CHOOSE TO ALWAYS DEBUG YOUR APPLICATION YOU WILL NOT HAVE THE SAME RESULT WITH THE SAME VELOCITY /F COURSE YOU MUST PERFORM INTEGRATION TESTING AND FUNCTIONAL TESTING BEFORE YOU CAN SAY THAT YOUR APPLICATION WAS COMPLETELY TESTED !GAIN ITgS OUR OPINION THAT THE TEST MUST BE WRITTEN BEFORE YOU WRITE THE CODE ESPECIALLY IF THE PROGRAMMER WHO WRITES THE CODE IS THE SAME PERSON WHO WILL TEST THE CODE
4HE RECIPES IN THIS CHAPTER DESCRIBE HOW TO DO THE FOLLOWING v
)MPLEMENT -66- ON 7INDOWS 0HONE BY USING -66-,IGHT
v
5SE -66- AND PERFORM UNIT TESTING
)MPLEMENTING -66- ON 7INDOWS 0HONE BY 5SING -66-,IGHT 0ROBLEM 9OU WANT YOUR APPLICATION IMPLEMENTATION TO HAVE A CONSISTENT SEPARATION OF CONCERNS BETWEEN MODULES 9OU WANT THE VIEW TO HAVE ONLY THE TASK OF DISPLAYING INFORMATION AND TO REMOVE FROM THE VIEW EVERYTHING THAT REQUIRES SOME LOGIC OR DATA ACCESS 9OU NEED TO CREATE A VIEW WITH ONLY A SET OF CONTROLS SUCH AS 4EXT"LOCK 4EXT"OX "UTTON x BINDING THEM WITH THE 3PcP2^]cTgc EXTf<^ST[ OF THE VIEW 4HEN THE VIEW ITS NOT RESPONSIBLE OF DATA RETRIEVING BUT ITS A TASK RESERVED TO THE EXTf<^ST[ THAT WILL AGGREGATE DATA IF NECESSARY AND PUT IT IN PROPERTIES BINDABLE BY THE VIEW
3OLUTION 9OU MUST IMPLEMENT THE -ODEL 6IEW 6IEW-ODEL -66- PATTERN AND BECAUSE YOU DONT WANT TO REINVENT THE WHEEL YOULL ALSO USE THE -66-,IGHT FRAMEWORK WHICH IS AVAILABLE ON #ODE0LEX Wcc_)\ee\[XVWcR^ST_[TgR^\ -66-,IGHT PROVIDES SOME IMPORTANT CLASSES AND hGEARSv NECESSARY TO IMPLEMENT -66- ON 3ILVERLIGHT FOR 7INDOWS 0HONE SUCH AS 4eT]cC^2^\\P]S AND
(OW )T 7ORKS -66- BASED ON A SPECIALIZATION OF -ARTIN &OWLERS 0RESENTATION -ODEL IS A DESIGN PATTERN USED TO REALIZE THE SEPARATION OF CONCERNS %LEMENTS OF THE -66- PATTERN ARE AS FOLLOWS v
6IEW IS RESPONSIBLE FOR SHOWING INFORMATION AS IN OTHER -6X PATTERNS WHERE X COULD BE # CONTROLLER 0 PRESENTER AND SO FORTH TO DISPLAY CONTROLS FOR EXAMPLE BUTTONS AND TEXT BOXES
v
6IEW-ODEL IS RESPONSIBLE FOR PREPARING DATA TAKEN FROM THE MODEL FOR THE VISUALIZATION
v
-ODEL REPRESENTS THE MODEL OF YOUR APPLICATION THAT IS YOUR DATA SOURCE
)N ORDER TO IMPLEMENT -66- YOU NEED TO UNDERSTAND SOME BASIC CONCEPTS SUCH AS COMMANDS AND BINDING 4HEN YOULL LEARN ABOUT THE BASICS OF -66- AND AFTER THAT YOU WILL SEE UNIT TESTING AND THEIR IMPORTANCE WITHIN YOUR APPLICATION LIFE CYCLE
,ETS START WITH BINDING ! BINDING IS SIMPLY AN ASSOCIATION BETWEEN TWO PROPERTIES OF TWO DIFFERENT CLASSES 9OU CAN BIND THE EP[dT OF A B[XSTa WITH THE CTgc PROPERTY OF A CTgc1^g OR IN THE CASE OF THE -66- IMPLEMENTATION YOU CAN BIND THE VALUE OF A PROPERTY IN OUR 6IEW-ODEL WITH THE PROPERTY OF A CONTROL ON THE VIEW 4YPICALLY YOU WILL USE PROPERTIES WITH THE SAME OR SIMILAR TYPES 4HERE ARE DIFFERENT OPTIONS FOR BINDING v
?PcW
v
<^ST
v
D_SPcTCaXVVTa
v
1X]Sb3XaTRc[hC^B^daRT
v
2^]eTacTa
?PcW REPRESENTS THE PATH TO THE BINDING SOURCE PROPERTY &OR EXAMPLE IF YOUR BINDING SOURCE IS A PRODUCT AND YOU ARE BINDING CTgc1^gCTgc TO SHOW THE CATEGORY NAME YOUR PATH WILL BE ?PcW,2PcTV^ah3TbRaX_cX^] )N 3ILVERLIGHT FOR 7INDOWS 0HONE AS IN 3ILVERLIGHT FOR THE 7EB THE <^ST ATTRIBUTE CAN ASSUME THREE VALUES >]TFPh >]TCX\T AND Cf^FPh "Y DEFAULT THE BINDING <^ST IS SET TO >]TFPh 4HIS MEANS THAT WHEN YOU UPDATE THE SOURCE OF THE BINDING THE TARGET IS UPDATED !S YOU MIGHT GUESS FROM ITS NAME Cf^FPh MODE MEANS THAT UPDATING THE TARGET VALUE WILL REFLECT ON THE SOURCE VALUE AND VICE VERSA &INALLY WHEN YOU USE >]TCX\T THE TARGET WILL BE UPDATED ONLY THE FIRST TIME WHEN YOU CREATE THE BINDING D_SPcTCaXVVTa IN 3ILVERLIGHT FOR 7INDOWS 0HONE AS IN ITS COUSIN FOR THE 7EB ACCEPTS ONLY TWO VALUES 3TUPd[c AND 4g_[XRXc 7ITH 4g_[XRXc YOU MUST INDICATE TO THE BINDING ENGINE TO UPDATE THE SOURCE 3TUPd[c MODE UPDATES THE VALUE WHEN A LOST FOCUS OF THE CONTROL OCCURS 4HERE IS A WAY TO USE D_SPcT>]?a^_Tach2WP]VTS AS IN 70& BY USING #ODING&UN TOOLS AVAILABLE ON #ODE0LEX Wcc_) R^SX]V#Ud]R^ST_[TgR^\ 1X]Sb3XaTRc[hC^B^daRT WHEN SET TO UP[bT CAUSES ?PcW TO BE EVALUATED RELATIVE TO THE DATA ITEM OTHERWISE ?PcW IS EVALUATED RELATIVE TO THE DATA SOURCE ,AST BUT NOT LEAST IS THE CONCEPT OF A CONVERTER 7ITH A CONVERTER YOU CAN BIND PROPERTIES OF DIFFERENT TYPES DEFINING THE WAY IN WHICH THE VIEW MUST EVALUATE THE VALUE &OR EXAMPLE SOMETIMES YOU WILL NEED TO BIND A "OOLEAN PROPERTY TO THE VISIBILITY OF A CONTROL !S YOU KNOW VISIBILITY IS AN ENUMERATION SO WHEN YOU TRY TO APPLY A "OOLEAN NOTHING HAPPENS 4HE SOLUTION ! CONVERTER 9OU WILL SEE THIS IN THE FOLLOWING h4HE #ODEv SECTION .OW YOU NEED TO UNDERSTAND WHAT A COMMAND IS 4HE CONCEPT OF A COMMAND COMES FROM THE COMMAND PATTERN WHICH ALLOWS YOU TO ISOLATE THE PART OF CODE THAT EXECUTES AN OPERATION FROM THE PART THAT REQUESTS THE EXECUTION )NSIDE THE CODE OF OUR 6IEW-ODEL A COMMAND IS A CLASS THAT IMPLEMENTS THE 82^\\P]S INTERFACE WHICH REPRESENTS THE CONTRACT TO IMPLEMENT COMMANDING !S YOU CAN SEE IN THE CLASS DIAGRAM SHOWN IN &IGURE 82^\\P]S EXPOSES THE METHODS 2P]4gTRdcT AND 4gTRdcT AND THE EVENT 2P]4gTRdcT2WP]VTS !S YOU CAN IMAGINE 2P]4gTRdcT IS THE METHOD THAT ENABLES THE CONTROL BOUND WITH THE COMMAND TO BE ENABLED AND 4gTRdcT IS THE METHOD THAT DESCRIBES WHAT YOU WANT TO DO WITH THAT COMMAND 5NFORTUNATELY IN THIS VERSION OF 3ILVERLIGHT FOR 7INDOWS 0HONE EVEN IF THE 82^\\P]S INTERFACE IS AVAILABLE THE COMMAND CANNOT BE BOUND WITH CONTROLS WITHOUT USING 4eT]cC^2^\\P]S BECAUSE THE CONTROLS DONT EXPOSE THE 2^\\P]S PROPERTY (OWEVER WE ARE CONFIDENT THAT THIS CAPABILITY WILL BE INTRODUCED IN FUTURE VERSIONS )TS IMPORTANT TO REMEMBER THAT WHEN YOU BIND A COMMAND TO A CONTROL THROUGH THE 2^\\P]S,j1X]SX]V
&IGURE #LASS DIAGRAM FOR 82^\\P]S
4HE #ODE "EFORE YOU BEGIN TO CREATE A NEW PROJECT DOWNLOAD THE LIBRARIES INDICATED IN THE PRECEDING h(OW IT 7ORKSv SECTION /F COURSE IF YOU WANT TO GET THE MOST FROM -66-,IGHT YOU SHOULD ALSO INSTALL THE TEMPLATES FOR 6ISUAL 3TUDIO %XPRESS OR NOT DEPENDING ON YOUR VERSION THAT THE PACKAGE CONTAINS 4O BEGIN CREATE A NEW 7INDOWS 0HONE APPLICATION AND ADD A REFERENCE TO THE -66-,IGHT $,,S AND TO THE #ODING&UN LIBRARIES AS SHOWN IN &IGURE
&IGURE !DDING THE -66- LIGHT AND #ODING&UN $,,S TO YOUR PROJECT
9OUR APPLICATION IS NOW READY FOR A QUICK IMPLEMENTATION OF THE PATTERN AND TO USE A WORKAROUND NOTORIOUS AMONG PEOPLE WHO WORK WITH 3ILVERLIGHT 4HIS WORKAROUND HELPS YOU TO UPDATE THE SOURCE OF THE BINDING EVERY TIMES A CHANGE ACCOURS INSIDE A TEXTBOX THEN WILL BE RAISED ?a^_Tach2WP]VTS EVENT EVERY TIME YOU WRITE SOMETHING IN A TEXT BOX BECAUSE AS YOU KNOW THE DEFAULT D_SPcTB^daRTCaXVVTa SET THE VALUE OF THE SOURCE PROPERTY ONLY WHEN THE CONTROL HAS LOST THE FOCUS 4O DO IT YOU NEED TO IMPORT THE 2^SX]V#5d]?W^]T2^]ca^[b1X]SX]V NAMESPACE IN THIS WAY g\[]b)[^RP[,R[a]P\Tb_PRT)2^SX]V#5d]?W^]T2^]ca^[b1X]SX]V* PbbT\Q[h,2^SX]V#5d]?W^]T2^]ca^[b 4HEN THE ONLY THING THAT YOU NEED TO DO NOW ITS TO SET INSIDE THE 4EXT"OX THE ATTACHED PROPERTY 4EXT"OX"INDING 5PDATE3OURCE/N#HANGE TO 4RUE IN THIS WAY +CTgc1^g CTgc,|j1X]SX]V CTgcl|[^RP[)CTgc1^g1X]SX]VD_SPcTB^daRT>]2WP]VT,CadT !FTER THE EXPLANATION OF THE WORKAROUND WE ARE READY TO CONTINUE THE IMPLEMENTATION OF THE PATTERN 4HE FIRST STEP IS TO ADD THE EXTf<^ST[;^RPc^a OF -66-,IGHT TO YOUR APPLICATION 4HEN YOU MUST CREATE THE FOLDER EXTf<^ST[b AND ADD AN ITEM OF TYPE EXTf<^ST[;^RPc^a CALLING IT EXTf<^ST[b;^RPc^a )MMEDIATELY AFTER THIS YOU MUST EDIT YOUR 0__gP\[ BY ADDING THE NAMESPACE OF EXTf<^ST[b;^RPc^a TO IT AND CREATING A RESOURCE OF TYPE EXTf<^ST[b;^RPc^a AT SHOWN HERE +0__[XRPcX^] g)2[Pbb,F_&ATRX_TN N!N<EE<0__ g\[]b,Wcc_)bRWT\Pb\XRa^b^UcR^\fX]Ug!%gP\[_aTbT]cPcX^] g\[]b)g,Wcc_)bRWT\Pb\XRa^b^UcR^\fX]Ug!%gP\[ g\[]b)_W^]T,R[a]P\Tb_PRT)<XRa^b^Uc?W^]T2^]ca^[b*PbbT\Q[h,<XRa^b^Uc?W^]T g\[]b)bWT[[,R[a]P\Tb_PRT)<XRa^b^Uc?W^]TBWT[[*PbbT\Q[h,<XRa^b^Uc?W^]T g\[]b)e\,R[a]P\Tb_PRT)F_&ATRX_TN N!N<EE<EXTf<^ST[b+0__[XRPcX^] ATb^daRTb+0__[XRPcX^]ATb^daRTb+e\)EXTf<^ST[b;^RPc^a g\[]b)e\,R[a]P\Tb_PRT)F_&ATRX_TN N N<EE<EXTf<^ST[b g):Th,;^RPc^a +0__[XRPcX^]ATb^daRTb +0__[XRPcX^].OW THAT YOU HAVE A WAY OF ACCESSING YOUR 6IEW-ODELS YOU CAN START CREATING THEM 9OULL BEGIN WITH THE 6IEW-ODEL FOR THE MAIN PAGE
■ 4IP ! NAMING CONVENTION FOR 6IEWS AND 6IEW-ODELS IS IMPORTANT )F YOU HAVE A VIEW NAMED 2PcTV^aXTbEXTf YOU COULD NAME THE RELATIVE 6IEW-ODEL 2PcTV^aXTbEXTf<^ST[ !LTHOUGH YOU DO NOT HAVE TO ALWAYS HAVE A CORRESPONDENCE OF 6IEWS AND 6IEW-ODELS PERHAPS THERE IS SOME CASE WHERE YOU WILL HAVE ONLY ONE 6IEW-ODEL FOR #25$ #REATE 2EAD 5PDATE AND $ELETE OPERATIONS FOR ALL YOUR TYPOLOGICAL ENTITIES
!S BEFORE ADD A NEW ITEM TO YOUR EXTf<^ST[b FOLDER OF TYPE EXTf<^ST[ AND CALL IT
+bd\\Pah ?a^eXSTb P STcTa\X]XbcXR fPh c^ ST[TcT cWT
■ 4IP 4O QUICKLY WRITE THESE PARTS OF THE CODE YOU MUST INSTALL SNIPPETS THAT ARE AVAILABLE INSIDE THE -66-,IGHT PACKAGE THAT YOU DOWNLOAD FROM #ODE0LEX 4HE \ee\[^RPc^a_a^_Tach SNIPPET CREATES A PROPERTY OF 6IEW-ODEL INSIDE YOUR EXTf<^ST[;^RPc^a !NOTHER REALLY HELPFUL SNIPPET IS \ee\X]_R WHICH RAPIDLY CREATES A BINDABLE PROPERTY IN YOUR 6IEW-ODEL THAT RAISES ?a^_Tach2WP]VTS4eT]c
.OW YOU HAVE THE MOST IMPORTANT STEP TO DO BINDING THE DATA CONTEXT OF THE VIEW TO YOUR 6IEW-ODEL )N THIS WAY ALL PROPERTIES EXPOSED BY THE 6IEW-ODEL WILL BE AVAILABLE FOR BINDING CONTROLS INSIDE THE VIEW 9OU DO THIS WITH A SIMPLE BINDING AS YOU CAN SEE IN THE FOLLOWING CODE +_W^]T)?W^]T0__[XRPcX^]?PVT g)2[Pbb,F_&ATRX_TN N!N<EE<
\R)8V]^aPQ[T,S S)3TbXV]FXScW,#' S)3TbXV]7TXVWc,&%' 5^]c5P\X[h,jBcPcXRATb^daRT ?W^]T5^]c5P\X[h=^a\P[l 5^]cBXiT,jBcPcXRATb^daRT ?W^]T5^]cBXiT=^a\P[l 5^aTVa^d]S,jBcPcXRATb^daRT ?W^]T5^aTVa^d]S1adbWl Bd__^acTS>aXT]cPcX^]b,?^acaPXc >aXT]cPcX^],?^acaPXc bWT[[)BhbcT\CaPh8bEXbXQ[T,CadT 3PcP2^]cTgc,j1X]SX]V B^daRT,jBcPcXRATb^daRT ;^RPc^al ?PcW,
&IGURE -AIN0AGE6IEW-ODEL SUPPORTS BLENDABILITY !T THIS POINT YOUR VIEW 8!-, WILL BE SOMETHING LIKE THIS +6aXS g)=P\T,2^]cT]c?P]T[ 6aXSA^f, <PaVX], ! !+6aXS2^[d\]3TUX]XcX^]b+2^[d\]3TUX]XcX^] FXScW,#! +2^[d\]3TUX]XcX^] FXScW,$&(+6aXS2^[d\]3TUX]XcX^]b+6aXSA^f3TUX]XcX^]b+A^f3TUX]XcX^] 7TXVWc,'+A^f3TUX]XcX^] 7TXVWc,'+A^f3TUX]XcX^] 7TXVWc,'+A^f3TUX]XcX^] 7TXVWc,'+A^f3TUX]XcX^]+6aXSA^f3TUX]XcX^]b-
+CTgc1[^RZ <PaVX], CTgcFaP__X]V,FaP_ CTgc,3PcT CTgc0[XV]\T]c,2T]cTa ETacXRP[0[XV]\T]c,2T]cTa+CTgc1[^RZ <PaVX], 6aXSA^f, CTgcFaP__X]V,FaP_ CTgc,0\^d]c CTgc0[XV]\T]c,2T]cTa ETacXRP[0[XV]\T]c,2T]cTa+CTgc1[^RZ <PaVX], 6aXSA^f,! CTgcFaP__X]V,FaP_ CTgc,<^cXePcX^] CTgc0[XV]\T]c,2T]cTa ETacXRP[0[XV]\T]c,2T]cTa+CTgc1^g <PaVX], 6aXS2^[d\], 6aXSA^f, CTgcFaP__X]V,FaP_ CTgc0[XV]\T]c,2T]cTa ETacXRP[0[XV]\T]c,2T]cTa CTgc,j1X]SX]V ?PcW,0\^d]c <^ST,Cf^FPhl [^RP[)CTgc1^g1X]SX]VD_SPcTB^daRT>]2WP]VT,CadT +CTgc1^g <PaVX], 6aXS2^[d\], 6aXSA^f,! CTgcFaP__X]V,FaP_ CTgc0[XV]\T]c,2T]cTa ETacXRP[0[XV]\T]c,2T]cTa CTgc,j1X]SX]V ?PcW,<^cXePcX^] <^ST,Cf^FPhl [^RP[)CTgc1^g1X]SX]VD_SPcTB^daRT>]2WP]VT,CadT+c^^[ZXc)3PcT?XRZTa 6aXS2^[d\], ETacXRP[0[XV]\T]c,1^cc^\ 7TXVWc,&& 7^aXi^]cP[2^]cT]c0[XV]\T]c,2T]cTa EP[dT,j1X]SX]V ?PcW,3PcT <^ST,Cf^FPhl [^RP[)CTgc1^g1X]SX]VD_SPcTB^daRT>]2WP]VT,CadT +1dcc^] 2^]cT]c,BPeT 8c 6aXS2^[d\], 7^aXi^]cP[0[XV]\T]c,2T]cTa 6aXSA^f," FXScW, $! 6aXS2^[d\]B_P],! +X)8]cTaPRcX^]CaXVVTab+X)4eT]cCaXVVTa 4eT]c=P\T,2[XRZ+R\S)4eT]cC^2^\\P]S 2^\\P]S,j1X]SX]V BPeT2^\\P]Sl+X)4eT]cCaXVVTa+X)8]cTaPRcX^]CaXVVTab+1dcc^]+6aXS !S YOU CAN SEE IN THIS 8!-, YOU HAVE TWO hNEWv NAMESPACES R\S AND X WHICH COME FROM THE -66-,IGHT LIBRARIES )N THIS WAY YOU HAVE BOUND THE EVENT 2[XRZ WITH A COMMAND INSIDE 6IEW-ODEL NAMED BPeT2^\\P]S DEMANDING TO THIS COMMAND THE INTEREST TO EXECUTE THE LOGIC OF THIS OPERATION SO WHEN 1dcc^]2[XRZ RAISES BPeT2^\\P]S4gTRdcT WILL BE CALLED /F COURSE TO USE THESE NAMESPACES YOU MUST IMPORT THEM IN YOUR 8!-, IN THIS WAY g\[]b)X,R[a]P\Tb_PRT)BhbcT\FX]S^fb8]cTaPRcXeXch*PbbT\Q[h,BhbcT\FX]S^fb8]cTaPRcXeXch g\[]b)R\S,R[a]P\Tb_PRT)6P[PB^Uc<ee\;XVWc2^\\P]S*PbbT\Q[h,6P[PB^Uc<ee\;XVWc4gcaPbF?& !S YOU CAN SEE FROM THE 8!-, YOU BOUND YOUR CONTROLS TO THE PROPERTIES OF 6IEW-ODEL NAMED 3PcT 0\^d]c AND <^cXePcX^] )N THE SAME WAY AS BEFORE YOU CAN USE A SNIPPET \ee\X]_R TO CREATE THESE PROPERTIES INSIDE YOUR 6IEW-ODEL 4HE ADVANTAGE OF USING THIS SNIPPET IS THAT YOU DONT NEED TO ADD ANY CALL TO THE APXbT?a^_Tach2WP]VTS METHOD THAT RAISES THE ?a^_Tach2WP]VTS EVENT FOR SUBSCRIBED HANDLERS IN THIS CASE BY BINDING ENGINE
■ .OTE 4HE APXbT?a^_Tach2WP]VTS METHOD CALL RAISES THE ?a^_Tach2WP]VTS EVENT IN EXTf<^ST[1PbT A CLASS INSIDE OF THE -66-,IGHT TOOLKIT THAT DERIVES FROM THE INTERFACE 8=^cXUh?a^_Tach2WP]VTS 4HE BINDING ENGINE WILL HANDLE THE EVENT LOOKING FOR UPDATED PROPERTIES AND INFORMING THE SOURCE OF THE BINDING THAT SOMETHING HAS CHANGED
!S YOU CAN IMAGINE THE 6IEW-ODEL HAS BECOME A LITTLE LONGER BECAUSE YOU HAVE TO BIND MORE PROPERTIES AND A COMMAND _dQ[XR R[Pbb
ePa ^[SEP[dT , NSPcT* NSPcT , eP[dT* D_SPcT QX]SX]Vb ]^ Qa^PSRPbc APXbT?a^_Tach2WP]VTS3PcT?a^_Tach=P\T* l l T]SaTVX^] aTVX^] 0\^d]c ?a^_Tach +bd\\Pah CWT +bTT RaTU,0\^d]c - _a^_Tachb ]P\T +bd\\Pah_dQ[XR R^]bc bcaX]V 0\^d]c?a^_Tach=P\T , 0\^d]c* _aXePcT STRX\P[ NP\^d]c , * _dQ[XR STRX\P[ 0\^d]c j VTc j aTcda] NP\^d]c* l bTc j XU NP\^d]c ,, eP[dT j aTcda]* l ePa ^[SEP[dT , NP\^d]c* NP\^d]c , eP[dT* D_SPcT QX]SX]Vb ]^ Qa^PSRPbc APXbT?a^_Tach2WP]VTS0\^d]c?a^_Tach=P\T* l l T]SaTVX^] aTVX^] <^cXePcX^] ?a^_Tach +bd\\Pah CWT +bTT RaTU,<^cXePcX^] - _a^_Tachb ]P\T +bd\\Pah_dQ[XR R^]bc bcaX]V <^cXePcX^]?a^_Tach=P\T , <^cXePcX^]* _aXePcT bcaX]V N\^cXePcX^] , bcaX]V4\_ch* _dQ[XR bcaX]V <^cXePcX^] j
VTc j aTcda] N\^cXePcX^]* l bTc j XU N\^cXePcX^] ,, eP[dT j aTcda]* l ePa ^[SEP[dT , N\^cXePcX^]* N\^cXePcX^] , eP[dT* D_SPcT QX]SX]Vb ]^ Qa^PSRPbc APXbT?a^_Tach2WP]VTS<^cXePcX^]?a^_Tach=P\T* l l T]SaTVX^] +bd\\Pah 8]XcXP[XiTb P ]Tf X]bcP]RT ^U cWT
5SAGE 4HIS APPLICATION CAN RUN IN THE EMULATOR OR THE PHYSICAL DEVICE 4HIS RECIPE IS A GOOD START POINT FOR A REAL FINANCIAL TRACKING APPLICATION ALL YOU NEED TO DO IS TO ADD YOUR PREFERRED LOGIC FOR SAVING DATA LOOK AT #HAPTER FOR INSPIRATION AND START THE APPLICATION -AKE SURE THAT YOU HAVE DECOUPLED THE VIEW FROM THE RELATED 6IEW-ODEL SO THAT THE ONLY INTEREST OF THE VIEW IS TO KNOW HOW TO SHOW DATA 6IEW-ODEL IS VIEW IGNORANT )N THIS WAY IF YOU CHANGE YOUR LOGIC FOR SAVING INFORMATION NOTHING MUST BE DONE ON YOUR VIEW &URTHERMORE IF YOU WANT TO TEST YOUR 6IEW-ODEL YOU CAN DO IT WITH UNIT TESTS WITHOUT PROBLEMSAS OPPOSED TO THE EVENTS APPROACH THAT REQUIRES THAT AN EVENT BE RAISED
5SING -66- AND 0ERFORMING 5NIT 4ESTING 0ROBLEM 9OU WANT TO WRITE AN APPLICATION AND TEST ITS LOGIC BY USING A UNIT TEST INSTEAD OF USING THE & DEBUG APPROACH
3OLUTION 9OU MUST WRITE YOUR APPLICATION BY USING THE -66- PATTERN THEN YOU WILL BE ABLE TO WRITE 5NIT 4EST FOR EACH 6IEW-ODEL 4O TEST YOUR 6IEW-ODELS YOU NEED TO USE THE 3ILVERLIGHT 5NIT 4EST &RAMEWORK TWEAKED FOR 7INDOWS 0HONE BY *EFF 7ILCOX
(OW )T 7ORKS 5NIT TESTS ARE IMPORTANT FOR TESTING THE SINGULAR FUNCTIONALITY OF YOUR CLASSES )N THIS RECIPE YOU WILL BUILD ON 2ECIPE BY CREATING LOGIC FOR THE BPeT2^\\P]S4gTRdcT METHOD 9OU WILL THEN CREATE A TEST CLASS WITH TWO TEST METHODS ONE THAT ALWAYS FAILS AND ANOTHER THAT ALWAYS WORKS 4HIS WAY YOU WILL LEARN HOW TO RUN TESTS ON YOUR 6IEW-ODEL AND HOW TO WRITE THEM WITH THE SCOPE OF AUTOMATICALLY TEST YOUR BUSINESS LOGIC WITHOUT ANY NEEDS OF INTERACTION BY YOU WITH THE USER INTERFACE THIS IS NOT COMPLETELY EXACT BECAUSE 3ILVERLIGHT 5NIT 4EST &RAMEWORK REQUIRES A COUPLE OF TAP BY YOU TO RUN THE 4EST
4HE #ODE /PEN THE PROJECT CREATED FOR 2ECIPE 4HE FIRST THING TO DO IS TO ADD A REFERENCE TO THE TWO ASSEMBLIES CONTAINED IN THE PACKAGE FOR UNIT TESTING AND MENTIONED IN THE h3OLUTIONv SECTION OF THIS RECIPE AT THIS ADDRESS fffYTUUfX[R^g]P\T! $b["dcUQXcb .OW THAT YOU HAVE THESE REFERENCES YOU NEED TO ADD A LITTLE MORE LOGIC TO
_aXePcT BcPcTb NbcPcT , BcPcTbD]bPeTS* +bd\\Pah 6Tcb cWT BcPcT _a^_Tach +bd\\Pah_dQ[XR BcPcTb BcPcT j VTc j aTcda] NbcPcT* l bTc j XU NbcPcT ,, eP[dT j aTcda]* l ePa ^[SEP[dT , NbcPcT* NbcPcT , eP[dT* D_SPcT QX]SX]Vb ]^ Qa^PSRPbc APXbT?a^_Tach2WP]VTSBcPcT?a^_Tach=P\T* l l T]SaTVX^] !S YOU CAN SEE THIS PROPERTY NOTIFIES THE INTERFACE THAT A CHANGE HAS OCCURRED BECAUSE WHEN YOU SAVE AN OBJECT ITS GOOD PRACTICE TO LET THE USER KNOW WHAT IS BEING DONE /UR LAST CHANGE TO
JCTbc2[PbbL _dQ[XR R[Pbb
5SAGE 2UN THE PROJECT BY USING 6ISUAL 3TUDIO TARGETING THE EMULATOR IF YOU RUN IT ON THE DEVICE ITSELF SOME TEXT BLOCKS WILL BE TOO SMALL TO READ WELL BUT WE THINK THAT BY THE QUANTITY OF INFORMATION SHOWN INSIDE THE TEST PAGE THERE IS NOTHING MORE TO DO 7AIT A FEW SECONDS WHILE THE TEST PAGE RUNS SEE &IGURE 4HEN LOOK FOR THE RESULT SEE &IGURE !S PLANNED ONE TEST FAILED AND OTHER TWO PASSED 4HAT IN 4EST $RIVEN $EVELEPEMENT 4$$ TRADUCTS IN hCORRECT THE BUG THEN RUN THE TEST AGAINv
&IGURE 3TARTING THE UNIT TEST
&IGURE 4ESTING RESULT
Index ■A
ACCELEROMETER n USING TO CREATE SEISMOGRAPH n ACCELEROMETER !0) !CCELEROMETER CLASS n !CCELEROMETER SENSOR !CCELEROMETER2EADING%VENT!RGS CLASS !CCEPT2ETURNS PROPERTY !CTIVATED EVENT !CTIVE3ONG PROPERTY !DD4AP CLASS n ! '03 SENSOR !LBUM PROPERTY ANIMATED SPLASH SCREEN CREATING n ANIMATION CREATING n n !PP CLASS n n !PP (UB IDENTIFIER !PPXAML FILE n !PPLICATION #ERTIFICATION 'UIDELINES !PPLICATION CLASS n EVENT HANDLERS 2ESOURCES PROPERTY APPLICATION DATA PERMANENT STORAGE OF n !PPLICATION $EPLOYMENT TOOL !PPLICATION EVENT HANDLERS !PPLICATION?!CTIVATED EVENT HANDLER !PPLICATION?#LOSING EVENT HANDLER
!PPLICATION?$EACTIVATED EVENT HANDLER !PPLICATION?,AUNCHING EVENT HANDLER !PPLICATION!PPLICATION,IFETIME/BJECTS !PPLICATION"AR CONTROL n !PPLICATION"AR)CON"UTTON !PPLICATION"AR)CON3AVE"UTTON?#LICK EVENT HANDLER !PPLICATION"AR-ENU)TEM CONTROL !PPLICATION)CON"AR BUTTON !PPLICATION)DLE$ETECTION-ODE PROPERTY n !PPLICATION2ESOURCES APPLICATIONS 3EE 3ILVERLIGHT APPLICATIONS 7INDOWS 0HONE APPLICATIONS 8.! APPLICATIONS !PPLY4HEME METHOD !PP-ANIFESTXML FILE !PP3ETTINGS CLASS n !RTIST PROPERTY !SSISTED 'LOBAL 0OSITIONING 3YSTEM !UTH#ALC5RL METHOD !UTHENTICODE CERTIFICATE !UTH'ET&ROB!SYNC METHOD !UTH'ET4OKEN!SYNC METHOD !UTO#OMPLETE"OX CONTROL n n !UTO0LAY PROPERTY
■
"ACK BUTTON BACKGROUND COLOR CHANGING n "EGIN)NVOKE METHOD "EHAVIOR CLASS n "INARY2EADER CLASS BINDING DATA CONTEXT OF VIEW TO 6IEW-ODEL n PROPERTIES TO 6IEW-ODEL n "INDS$IRECTLY4O3OURCE ATTRIBUTE "ING -APS n "ITMAP)MAGE CLASS BLENDABILITY n BTN,OAD?#LICK EVENT HANDLER BTN0LAY?#LICK EVENT HANDLER "UFFERING0ROGRESS#HANGED EVENT "UFFERING0ROGRESS#HANGED EVENT HANDLER "UFFER2EADY EVENT "UILD !CTION PROPERTY "UILD !CTIONS PROPERTY BUTTONS CUSTOMIZING n
■C
# CAMERA TAKING PHOTOS WITH n #AMERA SENSOR CAMERA?#OMPLETED EVENT HANDLER #AMERA#APTURE4ASK CLASS n CAMERA4ASK?#OMPLETED EVENT HANDLER #AN%XECUTE METHOD #AN%XECUTE#HANGED EVENT #AN'O"ACK PROPERTY #APTURE-OUSE METHOD
#HANNEL&ACTORY4#HANNEL CLASS #HILD PROPERTY OF 0OPUP #LASS n CHOOSER?#OMPLETED EVENT HANDLER CHOOSERS n #AMERA#APTURE4ASK n 0HOTO#HOOSER4ASK n #HOOSERS LIST BOX #HOSEN0HOTO PROPERTY #IVIC!DDRESS2ESOLVER CLASS n #LICK EVENT #LICK EVENT HANDLER #LOSING EVENT CLOUD COMPUTING n CREATING 'OOGLE !0) BASED TRANSLATOR n FEED READER CREATING n PUSH NOTIFICATION n 7#& INTERACTION n #OLLISION$ETECTED METHOD #OLOR CLASS COLOR SCHEMES OF USER INTERFACE n #OMMAND INTERFACE COMMAND PATTERN COMMANDS COMPASS #OMPLETED EVENT n #OMPLETED EVENT HANDLER #OMPLETE)NITIALIZE0HONE!PPLICATION EVENT HANDLER COMPLEX DATA OBJECTS NAVIGATING BETWEEN PAGES WITH n CONCURRENT APPLICATIONS #ONTENT ATTRIBUTE #ONTENT PROPERTY #ONTENT)DENTIFIER PROPERTY #ONTENT4YPE PROPERTY n
#ONTEXT-ENU CONTROL n CONTROLS CUSTOMIZING n #ONTROLS PROPERTY CONVERTER COORDINATES INDICATING USERgS POSITION VIA n #REATE!LBUM"UTTON?#LICK EVENT HANDLER #REATE)NSTANCE METHOD n #ULTURE)NFO CLASS n #URRENT STATIC PROPERTY #URRENT#ULTURE PROPERTY #URRENT3TATE#HANGED EVENT #URRENT4HREAD STATIC PROPERTY
■
$ARK THEME COLOR SCHEMES FOR n CREATING RESOURCE DICTIONARIES FOR n DETECTING CHANGE BETWEEN ,IGHT AND n DATA PERMANENT STORAGE OF APPLICATION n SERIALIZED SAVING n STORING ACROSS PAGES n $ATA PANEL IN %XPRESSION "LEND n DATA TEMPLATE CREATING FOR LIST BOX n $ATA#ONTRACT*SON3ERIALIZER $ATE0ICKER CONTROL $EACTIVATED EVENT DEBUGGING $ELTA PROPERTY $ESIRED!CCURACY PROPERTY DEVELOPER LICENSE
DEVELOPMENT TOOLS n $EVICE PANEL OF %XPRESSION "LEND n DICTIONARIES CREATING $ISPATCHER CLASS $ISPATCHER4IMER OBJECT $O#OMPLETED4ASK METHOD $O(OLD EVENT $O3HUFFLE METHOD n $O4AP EVENT $OUBLE #LICK EVENT $OUBLE #LICK EVENT HANDLER $OUBLE 4AP GESTURE n $OWNLOAD3TRING!SYNC METHOD $OWNLOAD3TRING#OMPLETED EVENT $OWNLOAD3TRING#OMPLETED EVENT HANDLER $RAG #OMPLETE GESTURE DRAG AND DROP FUNCTION n $RAG$ELTA'ESTURE%VENT!RGS PARAMETER $RAW METHOD $RAW,INE METHOD $RAW3TRING METHOD $URATION PROPERTY
■E
%MAIL!DDRESS#HOOSER4ASK %MAIL#OMPOSE4ASK %NABLED'ESTURES PROPERTY n %XECUTE METHOD EXECUTION MODEL n MANAGING OBSCURED AND UNOBSCURED EVENTS n NAVIGATION BETWEEN PAGES n
USING GLOBAL APPLICATION VARIABLES n WITH STATE n PASSING DATA THROUGH PAGES n TOMBSTONING MANAGEMENT n IN 3ILVERLIGHT APPLICATIONS BEGIN IN 3ILVERLIGHT APPLICATIONS END IN 8.! APPLICATIONS n EXECUTION MODEL EVENTS %XERCISE3ETTINGS CLASS n %XPRESSION "LEND $ATA PANEL n $EVICE PANEL n USER INTERFACE WITH n %XTENSIBLE !PPLICATION -ARKUP ,ANGUAGE 8!-,
■
FEED READER CREATING n FILES SAVING AND LOADING IN ISOLATED STORAGE n &LICK GESTURE &LICKR UPLOADING PHOTOS TO n &LICKR.%4 LIBRARY &-2ADIO CLASS n FONT &ONTS STATIC RESOURCE STYLES FORMS RESETTING BY SHAKING PHONE n FRAME &RAME CONTROL &RAME2EPORTED EVENT &RAME2EPORTED EVENT HANDLER &RAMEWORK$ISPATCHER CLASS &REE $RAG GESTURE &ROB PROPERTY n
&ROM!RGB STATIC METHOD &ROM3TREAM METHOD &UNNY2EPEATER APPLICATION n
■
'AME CLASS GAME MENUS MANAGING GESTURES IN n 'AME CLASS 'AMECS FILE 'AME(AS#ONTROL METHOD 'AMER3ERVICES NAMESPACE 'AME3ETTINGS CLASS 'AME3ETTINGS OBJECT 'AME3ETTINGS-ANAGER CLASS 'ENRE PROPERTY 'EO#OORDINATE CLASS n GEO COORDINATES n 'EO#OORDINATE7ATCHER CLASS n GEO7ATCHER?0OSITION#HANGED EVENT GEO7ATCHER?0OSITION#HANGED EVENT HANDLER GEO7ATCHER?3TATUS#HANGED EVENT HANDLER 'ESTURE,ISTENER PROPERTY n 'ESTURE,ISTENER?$RAG#OMPLETED EVENT HANDLER 'ESTURE,ISTENER?$RAG$ELTA EVENT HANDLER 'ESTURE,ISTENER?$RAG3TARTED EVENT HANDLER GESTURES n ABOUT ADDING TO CLICK LESS 3ILVERLIGHT CONTROLS n
MANAGING FROM 3ILVERLIGHT FOR 7INDOWS 0HONE TOOLKIT n IN GRAPHICAL CONTEXT n IN 3ILVERLIGHT APPLICATIONS n SUPPORTED USING IN APPLICATION 'ESTURE3AMPLE OBJECT 'ESTURE3AMPLE STRUCTURE n 'ESTURE3ERVICE CLASS 'ESTURE3ERVICE TAG 'ESTURE3ERVICE'ESTURE,ISTENER CONTROLS 'ESTURE4YPE ENUMERATION 'ET!REA&ROM0T#OMPLETED EVENT 'ET$ATA METHOD 'ET2ESOURCE3TREAM STATIC METHOD 'ET3AMPLE3IZE)N"YTES METHOD 'ET4ILE METHOD 'ET4ILE#OMPLETED EVENT 'ET4OUCH0OINTS METHOD GLOBAL APPLICATION VARIABLES n 'O"ACK METHOD 'O&ORWARD METHOD 'OT&OCUS METHOD GRAPHIC DEVICE MANAGE 'RAPHICS$EVICE-ANAGER OBJECT 'RID CONTROL ADDING GESTURES TO n 'ROUP(EADER4EMPLATE 'ROUP)TEM4EMPLATE 'UIDE CLASS n
■H
(ANDLED PROPERTY HARDWARE OVERVIEW n
(AS!RT PROPERTY (AS%RROR PROPERTY (EADER PROPERTY HIGH INTERACTION GAMES (OLD GESTURE (ORIZONTAL $RAG GESTURE (TTP.OTIFICATION#HANNEL CLASS n HUBS (UB4YPE ATTRIBUTE HYPERLINK BUTTONS ADDING (YPERLINK"UTTON CONTROLS n (YPERLINK"UTTON?#LICK EVENT HANDLER
■
)!PPLICATION3ERVICE INTERFACE )#IVIC!DDRESS2ESOLVER INTERFACE )#OMMAND )DLE$ETECTION-ODE PROPERTY )DLE$ETECTION-ODE$ISABLED )DLE$ETECTION-ODE%NABLED )MAGE CONTROL IMAGES OVERLAYING ON CONTROLS n )MAGE3TREAM PROPERTY INIT!CCELEROMETER METHOD )NITIALIZE METHOD )NITIALIZE0HONE!PPLICATION METHOD )NIT2ESOLVER METHOD )NIT7ATCHER METHOD ).OTIFY0ROPERTY#HANGED INTERFACE )NPUT3COPE PROPERTY n )NPUT3COPE.AME6ALUE ENUMERATOR )NSTANCE PROPERTY INTERACTION ADDING WITH EXTERNAL APPLICATIONS n )NTERMEDIATE ,ANGUAGE ), CODE
INVARIANT CULTURE RESOURCE FILE I0HONE I0OD 4OUCH )S#HECKED "OOLEAN PROPERTY )S$ARK4HEME STATIC PROPERTY )S$ATA,OADED PROPERTY )S'ESTURE!VAILABLE PROPERTY n )S)NDETERMINATE PROPERTY n )S,OCKED PROPERTY ISOLATED STORAGE n APPLICATION SETTINGS SAVING AND RETRIEVING n SAVING AND LOADING A FILE IN n SAVING PHOTO IN n SAVING SERIALIZED DATA n )SOLATED3TORAGE CLASSES )SOLATED3TORAGE&ILE CLASS n )SOLATED3TORAGE3ETTINGS CLASS n )S4OMBSTONED PROPERTY )S4RIAL METHOD n )S4RIAL-ODE PROPERTY n )S6ISIBLE PROPERTY )TEM#ONTAINER4EMPLATE )TEM3OURCE PROPERTY )TEM4EMPLATE TEMPLATE )TEM6IEW-ODEL PROPERTY )TEM6IEW-ODELCS
■
*AVA3CRIPT /BJECT .OTATION *3/.
■
+EY$OWN EVENT +EY$OWN EVENT HANDLER +EY%VENT!RGS PARAMETER
■
LAMBDA EXPRESSIONS LANGUAGE SETTINGS n LAUNCHERS n VS CHOOSERS ,AUNCHING EVENT LB%XERCISE?3ELECTION#HANGED EVENT HANDLER ,ICENSE)NFORMATION CLASS n LIFE CYCLE APPLICATION MANAGEMENT LIGHT ,IGHT THEME COLOR SCHEMES FOR n CREATING RESOURCE DICTIONARIES FOR n DETECTING CHANGE BETWEEN $ARK AND n ,).1 QUERY LIST BOX CREATING CUSTOM LAYOUT FOR n LIST PICKER CONTROLS ,IST"OX CONTROL ,IST(EADER4EMPLATE ,IST0ICKER CONTROL n LIVE TILES ,OAD METHOD ,OAD#ONTENT METHOD ,OAD$ATA METHOD ,OADED EVENT ,OADED EVENT HANDLER LOCALIZATION n ,OCATION 3ERVICES n LOCK SCREEN IDLE TIME ,ONG,IST3ELECTOR CONTROL n
■
-AIN0AGE CLASS n -AIN0AGEXAML FILE n -ANAGE&REQUENCY#HANGE METHOD -ARKETPLACE$ETAIL4ASK CLASS -ARKETPLACE(UB4ASK CLASS -ARKETPLACE2EVIEW4ASK CLASS -ARKETPLACE3EARCH4ASK CLASS MASK IMAGES n MEDIA MANAGEMENT n MICROPHONE USING n -USIC 6IDEOS HUB ADDING INTEGRATION WITH n PHOTOS CHOOSING FROM MEDIA LIBRARY n TAKING n UPLOADING TO &LICKR n PLAYING MUSIC AND VIDEO n USING MEDIA PLAYER n MEDIA PLAYER RETRIEVING SONGS USING n SHUFFLING SONGS n -EDIA PROPERTY -EDIA%LEMENT CONTROL n -EDIA%NDED EVENT -EDIA(ISTORY CLASS n -EDIA(ISTORY)TEM CLASS n -EDIA(ISTORY)TEM OBJECT -EDIA,IBRARY CLASS n -EDIA/PENED EVENT n -EDIA0LAYER CLASS n -EDIA0LAYER1UEUE4O3TRING -EDIA0LAYER,AUNCHER CLASS
-EDIA1UEUE CLASS MEMORY -ENU)TEM TAG -ERGED$ICTIONARIES COLLECTION -ETRO USER INTERFACE MICROPHONE USING n -ICROPHONE CLASS n -ICROSOFT !UTHENTICODE CERTIFICATE -ICROSOFT "LEND -ICROSOFT 2ESEARCH -APS -ICROSOFT 7INDOWS 0HONE $EVELOPER 4OOLS n -ICROSOFT$EVICE3ENSORS ASSEMBLY -ICROSOFT$EVICES2ADIO NAMESPACE -ICROSOFT0HONE#ONTROLSDLL ASSEMBLY -ICROSOFT8NA&RAMEWORKDLL ASSEMBLY -ICROSOFT8NA&RAMEWORK)NPUT4OUCHDLL ASSEMBLY -ODE ATTRIBUTE MODEL -ODEL 6IEW 6IEW-ODEL -66- ARCHITECTURE IMPLEMENTING USING -66-,IGHT n USING AND UNIT TESTING n -OUSE,EFT"UTTON$OWN EVENT n -OUSE,EFT"UTTON5P EVENT n MSCORLIB ASSEMBLY MULTI TOUCH SCREEN -ULTI 4OUCH 6ISTA LIBRARY MUSIC PLAYING n -USIC 6IDEOS HUB ADDING INTEGRATION WITH n -USIC6IDEOS(UB)NTEGRATION APPLICATION n
MVVMINPC SNIPPET -66-,IGHT FRAMEWORK n MVVMLOCATORPROPERTY SNIPPET
■
.AME PROPERTY .ATURAL$URATION PROPERTY .ATURAL(EIGHT PROPERTY .ATURAL7IDTH PROPERTY .AVIGATE METHOD .AVIGATED EVENT .AVIGATING!PP APPLICATION n NAVIGATION BETWEEN PAGES n USING GLOBAL APPLICATION VARIABLES n WITH STATE n .AVIGATION#ONTEXT PROPERTY .AVIGATION%VENT!RGS OBJECT .AVIGATION3ERVICE CLASS n .AVIGATION3ERVICE PROPERTY .AVIGATION3ERVICES CLASS .AVIGATION3ERVICES PROPERTY .%4 APPLICATIONS .%4 &RAMEWORK .EW'UID STATIC METHOD .OW0LAYING PROPERTY n
■
OBJECTS STORING /BSCURED EVENT HANDLER n OBSCURED EVENTS MANAGING n /BSCURED%VENT!RGS PARAMETER /FFICE SERVICE /N!CTIVATED EVENT HANDLER n /N!TTACHED METHOD n
/N"ACK+EY0RESS METHOD /N$EACTIVATED EVENT HANDLER n /N$ETACHING METHOD n /NE4IME MODE /NE7AY MODE /N%XITING EVENT HANDLER /N.AVIGATED&ROM EVENT HANDLER /N.AVIGATED4O EVENT HANDLER n /N.AVIGATED4O METHOD /N2ESOLVE!DDRESS#OMPLETED EVENT /PACITY PROPERTY /PEN2EAD#OMPLETE EVENT /RIENTATION PROPERTY /RIGINAL&ILE.AME PROPERTY
■P
0AGE 4RANSITIONS 0AGE?,OADED EVENT HANDLER 0AGE,OADED EVENT PAGES DEFINED NAVIGATING BETWEEN n USING GLOBAL APPLICATION VARIABLES n WITH STATE n PASSING DATA THROUGH n 0AINT.%4 DRAWING TOOL 0ANORAMA CONTROL n PARAMETERS PASSING BETWEEN PAGES n 0ARSE METHOD PAUSE MODE n 0AUSED PROPERTY n PEN STYLUS 0ERFORMANCE0ROGRESS"AR CONTROL
0HONE!PPLICATION#LASS CLASS 0HONE!PPLICATION&RAME CLASS 0HONE!PPLICATION0AGE 0HONE!PPLICATION0AGE CLASS 0HONE!PPLICATION0AGE?,OADED EVENT HANDLER 0HONE!PPLICATION3ERVICE CLASS 0HONE"ACKGROUND"RUSH RESOURCE 0HONE#ALL4ASK n 0HONE,IGHT4HEME6ISIBILITY 0HONE.UMBER PROPERTY 0HONE.UMBER#HOOSER4ASK CLASS 0HOTO#HOOSER4ASK CHOOSER CLASS n 0HOTO2ESULT EVENT ARGUMENT PHOTOS CHOOSING FROM MEDIA LIBRARY n SAVING IN ISOLATED STORAGE n TAKING FROM PHONE CAMERA n UPLOADING TO &LICKR n 0ICK4APPED#OLOR METHOD 0ICTURE$ECODER CLASS n 0ICTURES HUB 0INCH #OMPLETE GESTURE 0INCH GESTURE 0IVOT CONTROL n 0IXELS ARRAY 0LAY METHOD n n 0LAY#OUNT PROPERTY 0LAYER#ONTEXT COLLECTION 0LAY2ECORDED!UDIO METHOD 0LAY3ONG METHOD n POINT4EXTURE 0OPUP CLASS n
0OSITION PROPERTY 0OSITION#HANGED EVENT n PREDEFINED STYLES n 0ROGRESS"AR CONTROL n 0ROPERTY#HANGED EVENT PROXIMITY SENSOR PROXY ? 'ET4ILE#OMPLETE EVENT PROXY?'ET!REA&ROM0T#OMPLETED EVENT 0USH .OTIFICATION 3ERVICE n PUSH NOTIFICATIONS
■
1UERY3TRING COLLECTION 1UERY3TRING PROPERTY
■R
RADIO USING n 2AISE0ROPERTY#HANGED METHOD 2ATING PROPERTY 2EAD"YTES METHOD 2EAD'ESTURE METHOD n 2EADING#HANGED EVENT n 2ECEIVED 3IGNAL 3TRENGTH )NDICATOR 233) 2EGION ,ANGUAGE SETTINGS PAGE REGIONAL SETTINGS n 2EPRESENTATIONAL 3TATE 4RANSFER 2%34FUL SERVICE n 2ESET4EXT"OX METHOD 2ESOURCE CLASS RESOURCE DIRECTORIES CREATING DIFFERENT FOR LIGHT OR DARK THEMES n 2ESOURCE$ICTIONARY CLASS n 2ESOURCES PROPERTY
2OLL4RANSITION CLASS 2OOT6ISUAL PROPERTY 2OTATE4RANSITION CLASS
■
3AVE METHOD n 3AVE#OMMAND METHOD 3AVE#OMMAND%XECUTE METHOD n 3AVE%MAIL!DDRESS4ASK METHOD 3AVE/R5PDATE METHOD n 3AVE0HONE.UMBER4ASK METHOD SCREEN RESOLUTION 3EARCH BUTTON 3EARCH1UERY PROPERTY 3EARCH4ASK LAUNCHER 3EARCH4ERMS PROPERTY 3EE METHOD SEISMOGRAPH CREATING n 3ELECTION#HANGED EVENT 3ELECTION#HANGED EVENT HANDLER SENSORS n CREATING SEISMOGRAPH n DISPLAYING SUNSET AND SUNRISE n INDICATING USERgS POSITION VIA COORDINATES n RESETTING FORMS BY SHAKING PHONE n USERgS POSITION INDICATING n USING RADIO n 3EPARATION OF #ONCERNS CONCEPT SERIALIZABLE OBJECTS SERIALIZED DATA SAVING n SERVICES ADDING REFERENCE TO n ASYNCHRONOUS ACCESS
PUSH NOTIFICATION n 2%34 n 3ETTING SYSTEMS PAGE SETTINGS MODIFYING n 3ETTINGS CLASS n SETTINGS PROPERTY 3ETTINGS SYSTEM PAGE 3ETTINGS?,OADED EVENT HANDLER n SHAKING PHONE RESETTING FORMS BY n 3HOW METHOD n n n 3HOW-ARKETPLACE METHOD 3HUFFLE-E APPLICATION n 3IGNAL 3TRENGTH 3ILVERLIGHT APPLICATIONS CREATING n CODE n GETTING STARTED n USAGE GESTURES MANAGING n ADDING TO CLICK LESS CONTROLS n FROM 3ILVERLIGHT FOR 7INDOWS 0HONE TOOLKIT n NAVIGATION BETWEEN PAGES n TOMBSTONING MANAGEMENT n TRIAL VERSIONS n 3ILVERLIGHT FOR 7INDOWS 0HONE 3ILVERLIGHT FOR 7INDOWS 0HONE 4OOLKIT n n 3ILVERLIGHT 5NIT 4EST &RAMEWORK 3ILVERLIGHT4EST CLASS 3IMPLE3ILVERLIGHT!PPLICATION NAMESPACE 3IMULATE4RIAL-ODE PROPERTY n 3LIDE4RANSITION CLASS 3MS#OMPOSE4ASK LAUNCHER
3OFT )NPUT 0ANEL 3)0 CUSTOMIZING TO ACCEPT ONLY NUMBERS n 3ONG CLASS n 3ONG#OLLECTION CLASS 3ONG.UMBER PROPERTY n SONGS PLAYING n SHUFFLING n 3ONGS COLLECTION 3ONGS PROPERTY 3OUND%FFECT CLASS n 3OUND%FFECT)NSTANCE OBJECT 3OURCE PROPERTY SPLASH SCREEN CREATING ANIMATED n 3PLASH3CREEN)MAGEJPG IMAGE 3TACK0ANEL 3TART BUTTON 3TATE DICTIONARY n n 3TATE PROPERTY STATES MANAGING ACTIVE AND INACTIVE STATIC RESOURCE STYLES n STATIC RESOURCES 3TATUS#HANGED EVENT STORAGE ISOLATED n PERMANENT OF APPLICATION DATA n QUOTA SIZE 3TREAM2ESOURCE)NFO CLASS SUNRISE DISPLAYING SUNSET DISPLAYING n 3UNTIMES(ELPER CLASS 3WIVEL4RANSITION CLASS
3YSTEM$EVICE,OCATION 3YSTEM7INDOWS)NTERACTIVITYDLL ASSEMBLY n
■T
4AB)NDEX PROPERTY n 4AP GESTURE 4ASK2ESULT PROPERTY TEMPLATES n 4ERRA3ERVICE TESTING n IMPLEMENTING --6- n UNIT n TEXT INPUT 4EXT"LOCK CONTROL 4EXT"OX CONTROL n THEME SELECTION THEME TEMPLATE DETECTING CHANGES IN n 4HEME$ETECTOR CLASS n THEMES APPLYING 4HREAD CLASS 4ICK EVENT 4ICK EVENT HANDLER 4ILT%FFECT CONTROL 4IME0ICKER CONTROL 4IME3PAN4ICKS0ER3ECOND VALUE 4ITLE PROPERTY 4O!RRAY METHOD 4OGGLE3WITCH CONTROL TOMBSTONING n n DEFINED MANAGEMENT OF n IN 3ILVERLIGHT APPLICATIONS n IN 8.! APPLICATIONS n TOUCH SCREENS
4OUCH STATIC CLASS 4OUCH&RAME2EPORTED EVENT 4OUCH&RAME2EPORTED EVENT HANDLER 4OUCH&RAME%VENT!RGS ARGUMENT 4OUCH&RAME%VENT!RGS PARAMETER 4OUCH0ANEL CLASS n 4OUCH0OINT#OLLECTION COLLECTION 4RACK.UMBER PROPERTY TRAIL VERSION CREATING n 4RANSITIONS CONTROL n 4RANSITIONS EFFECTS TRANSLATOR CREATING 'OOGLE !0) BASED n 4URNSTILE4RANSITION CLASS 4WO7AY MODE
■
5)%LEMENT CLASS UNIT TESTING n 5NOBSCURED EVENT HANDLER n UNOBSCURED EVENTS MANAGING n 5PDATE METHOD n 5PDATE(ISTORY METHOD 5PDATE.OW0LAYING METHOD n 5PDATE3OURCE4RIGGER METHOD 5PDATE4RIGGER METHOD 5PDATE5) METHOD 5PLOAD0ICTURE!SYNC METHOD 5RI OBJECT 5RI+IND ENUMERATION 52,S RELATIVE USER INTERACTION n USER INTERFACE 5) n ANIMATIONS CREATING n n APPLICATION BAR ADDING n
CHANGING COLOR SCHEMES OF n CHOOSERS USING n CUSTOMIZATION WITH %XPRESSION "LEND n CHANGING SKIN OF APPLICATION n CREATING ANIMATIONS n CUSTOMIZING CONTROLS n CUSTOM LIST BOX LAYOUT n,IGHT AND $ARK THEMES n FIRST IMPRESSIONS OF GUIDELINES FOR INTERACTION ADDING WITH EXTERNAL APPLICATIONS n LAUNCHERS USING LOCALIZING n -ETRO 0ANORAMA CONTROL n 0IVOT CONTROL n PREDEFINED STYLES USING n 3ILVERLIGHT FOR 7INDOWS 0HONE 4OOLKIT n 3OFT )NPUT 0ANEL CUSTOMIZING TO ACCEPT ONLY NUMBERS n THEME TEMPLATE DETECTING CHANGES IN n USERS AUTHENTICATING USERgS POSITION INDICATING n VIA COORDINATES n
■
VERTEX"UFFER n 6ERTICAL $RAG GESTURE VERTICES COLLECTION VIDEO PLAYING n 6IEW-ODEL,OCATOR
6IEW-ODELS ACCESSING ADDING PROPERTIES TO BINDING DATA CONTEXT OF VIEW TO n BINDING PROPERTIES TO n CREATING n NAMING CONVENTION FOR UNIT TESTING n 6IEWS BINDING DATA CONTEXT OF TO 6IEW-ODELS n NAMING CONVENTION FOR VIRTUAL KEYBOARD CUSTOMIZING TO ACCEPT ONLY NUMBERS n 6ISUAL "ASIC 6ISUAL 3TUDIO .EW 0ROJECT DIALOG BOX PROJECT TEMPLATES 6ISUAL 3TUDIO %XPRESS 6ISUAL 3TUDIO 0ROFESSIONAL 6ISUAL 3TUDIO 3UPERIOR
■
WEB SERVICES ACCESSING n ADDING REFERENCE TO n 7EB"ROWSER CONTROL n 7EB"ROWSER4ASK CLASS 7EB#LIENT CLASS n 7I &I SENSOR 7INDOWS #OMMUNICATION &OUNDATION 7#& INTERACTING WITH n 7INDOWS ,IVE )$ 7INDOWS -OBILE 7INDOWS 0HONE
DEVELOPMENT TOOLS n EXECUTION MODEL n MANAGING OBSCURED AND UNOBSCURED EVENTS n NAVIGATION BETWEEN PAGES n PASSING DATA THROUGH PAGES n TOMBSTONING MANAGEMENT n IN 3ILVERLIGHT APPLICATIONS n IN 8.! APPLICATIONS n HARDWARE n PREDEFINED STYLES n USER INTERFACE 3EE USER INTERFACE 5) 7INDOWS 0HONE APPLICATIONS 3EE ALSO 3ILVERLIGHT APPLICATIONS 8.! APPLICATIONS ACCEPTANCE PROCESS n CONCURRENT EXECUTION OF CREATING TRIAL VERSION n USING 3ILVERLIGHT n USING 8.! n CUSTOMIZING WITH DIFFERENT RESOURCE DIRECTORIES n DEPLOYING ON DEVICE n TO EMULATOR n GESTURES MANAGING n ADDING TO CLICK LESS CONTROLS n FROM 3ILVERLIGHT FOR 7INDOWS 0HONE TOOLKIT n IN GRAPHICAL CONTEXT n LOCALIZING MODIFYING SETTINGS OF n NAVIGATION BETWEEN PAGES n
RUNNING WHEN RECEIVING PHONE CALLS n WHEN SCREEN IS LOCKED n SENDING TO THE -ARKETPLACE n SKIN CHANGING n TOMBSTONING MANAGEMENT n TESTING n 7INDOWS 0HONE DEVICES n DEPLOYING APPLICATION ON n 7INDOWS 0HONE %MULATOR DEPLOYING APPLICATION TO n RUNNING 3ILVERLIGHT APPLICATION IN RUNNING 8.! APPLICATION IN 7INDOWS 0HONE !PPLICATION TEMPLATE 7INDOWS 0HONE #ERTIFICATION 2EQUIREMENTS 7INDOWS 0HONE #LASS ,IBRARY TEMPLATE 7INDOWS 0HONE $ATABOUND !PPLICATION TEMPLATE 7INDOWS 0HONE $EVELOPER 2EGISTRATION TOOL n 7INDOWS 0HONE $EVELOPER 4OOLS 7INDOWS 0HONE 'AME PROJECT TEMPLATE 7INDOWS 0HONE -ARKETPLACE n 7INDOWS 0HONE 0ANORAMA !PPLICATION TEMPLATE 7INDOWS 0HONE 0IVOT !PPLICATION TEMPLATE 7INDOWS 0HONE RESOURCE DICTIONARY 7-!PP-ANIFESTXML FILE
70#ONNECTEXE PROGRAM 7RAP0ANEL CONTROL 7RITEABLE"ITMAP CLASS 7RITE2ECENT0LAY METHOD
■
8!-, %XTENSIBLE !PPLICATION -ARKUP ,ANGUAGE 8!-, STORYBOARDS X AXIS MOVEMENT ALONG X#/,#LASS ATTRIBUTE 8%LEMENT CLASS 8ML3ERIALIZER CLASS n 8.! APPLICATIONS CREATING n CODE n GETTING STARTED n USAGE TOMBSTONING MANAGEMENT n TRIAL VERSIONS n 8NA$ISPATCHER3ERVICE CLASS 8 .OTIFICATION#LASS n
■
Y AXIS MOVEMENT ALONG Y0OSITION
■
Z AXIS MOVEMENT ALONG :)NDEX PROPERTY :UNE SOFTWARE n