Table Of ContentBuild Windows 8
Apps with HTML5 and
JavaScript
Dino Esposito
Francesco Esposito
Published with the authorization of Microsoft Corporation by:
O’Reilly Media, Inc.
1005 Gravenstein Highway North
Sebastopol, California 95472
Copyright © 2013 by Dino Esposito
All rights reserved. No part of the contents of this book may be reproduced or transmitted in any form or by any
means without the written permission of the publisher.
ISBN: 978-0-7356-7594-0
1 2 3 4 5 6 7 8 9 LSI 8 7 6 5 4 3
Printed and bound in the United States of America.
Microsoft Press books are available through booksellers and distributors worldwide. If you need support related
to this book, email Microsoft Press Book Support at mspinput@microsoft.com. Please tell us what you think of
this book at http://www.microsoft.com/learning/booksurvey.
Microsoft and the trademarks listed at http://www.microsoft.com/about/legal/en/us/IntellectualProperty/
Trademarks/EN-US.aspx are trademarks of the Microsoft group of companies. All other marks are property of
their respective owners.
The example companies, organizations, products, domain names, email addresses, logos, people, places, and
events depicted herein are fictitious. No association with any real company, organization, product, domain name,
email address, logo, person, place, or event is intended or should be inferred.
This book expresses the author’s views and opinions. The information contained in this book is provided without
any express, statutory, or implied warranties. Neither the authors, O’Reilly Media, Inc., Microsoft Corporation,
nor its resellers, or distributors will be held liable for any damages caused or alleged to be caused either directly
or indirectly by this book.
Acquisitions and Developmental Editor: Russell Jones
Production Editor: Christopher Hearse
Editorial Production: S4Carlisle Publishing Services
Technical Reviewer: Russ Mullen
Indexer: Angela Howard
Cover Design: Jake Rae
Cover Composition: Karen Montgomery
Illustrator: S4Carlisle Publishing Services
To Michela and Silvia, who are stronger and smarter than they
think.
—Dino
To Grandma Concetta, for providing free calories through
amazing quantities of unbeatable homemade prosciutto.
—Francesco
Contents at a glance
Introduction xiii
CHApTer 1 Using Visual Studio 2012 express edition for Windows 8 1
CHApTer 2 Making sense of HTML5 23
CHApTer 3 Making sense of CSS 47
CHApTer 4 Making sense of JavaScript 73
CHApTer 5 First steps with Windows 8 development 97
CHApTer 6 The user interface of Windows Store applications 121
CHApTer 7 Navigating through multimedia content 147
CHApTer 8 States of a Windows 8 application 177
CHApTer 9 Integrating with the Windows 8 environment 201
CHApTer 10 Adding persistent data to applications 235
CHApTer 11 Working with remote data 265
CHApTer 12 Accessing devices and sensors 291
CHApTer 13 Adding Live tiles 319
CHApTer 14 publishing an application 335
Index 351
Contents
Introduction ....................................................xiii
Chapter 1 Using Visual Studio 2012 Express edition
for Windows 8 1
Getting ready for development .....................................2
The software you need .......................................2
Configuring Visual Studio 2012 ................................5
Start playing with Windows 8 apps ............................9
The “Hello Windows 8” application ...........................10
Adding a bit more action ....................................16
Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .21
Chapter 2 Making sense of HTML5 23
Elements of a webpage ...........................................24
Building the page layout with HTML5 .........................24
Miscellany of other new elements. . . . . . . . . . . . . . . . . . . . . . . . . . . . .32
Collecting data ..................................................34
Adjusting input fields .......................................35
Form submission ...........................................38
Multimedia elements .............................................41
The audio element ..........................................41
The video element ..........................................42
Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .45
What do you think of this book? We want to hear from you!
Microsoft is interested in hearing your feedback so we can continually improve our
books and learning resources for you. To participate in a brief online survey, please visit:
microsoft.com/learning/booksurvey
vii
Chapter 3 Making sense of CSS 47
Styling a webpage ...............................................47
Adding CSS information to pages .............................48
Selecting elements to style ..................................51
Basic style commands ............................................55
Setting colors ..............................................55
Controlling text. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .58
HTML display modes ........................................60
Spacing and the boxing model ...............................63
Advanced CSS scenarios ..........................................66
CSS pseudo-classes .........................................66
Media Queries .............................................70
Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .71
Chapter 4 Making sense of JavaScript 73
Language basics .................................................74
The JavaScript type system. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .74
Dealing with variables .......................................77
Dealing with objects ........................................79
Dealing with functions ......................................81
Organizing your own JavaScript code ...............................89
Linking JavaScript code to pages .............................89
Practices and habits .........................................92
Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .94
Chapter 5 First steps with Windows 8 development 97
The Windows 8 Runtime (WinRT) ..................................98
Windows Store apps and other apps ..........................98
An overview of the WinRT API ...............................100
The Windows Store app user interface ............................102
Aspects of the Windows 8 UI ................................102
Inspiring principles of the Windows 8 UI ......................104
viii Contents
Description:Ready to learn Windows 8 programming? Start Here! Learn the fundamentals of Windows 8 programming—and begin creating apps for desktops, laptops, tablets, and other devices. If you have previous experience with HTML5 and JavaScript—simply start here! This book introduces must-know concepts and ge