Programming Windows Store Apps with HTML, CSS, and Javascript
Total Page:16
File Type:pdf, Size:1020Kb
spine = 2.07” Programming Windows Sixth Edition Writing Windows 8 Apps with C# and XAML Windows Programming Writing Windows 8 Apps with C# and XAML About the Sixth Edition Like Windows itself, this classic book has been reimagined for • Completely rewritten for Windows 8 Programming a new world of programming and user experiences. Guided • Focuses on creating apps using C#, XAML, and the Windows Runtime by developer legend Charles Petzold, Programming Windows, Sixth Edition teaches how to use your existing C# skills with • Expertly teaches essential skills in Part 1: Elementals XAML and the Windows Runtime to create full-screen, touch Rounds out your Windows 8 education apps for Windows 8. • Windows Store in Part 2: Specialties • Provides code samples in both C# Master the elementals and C++ • Create and initialize objects with code or XAML • Handle user-input events such as taps Apps with HTML, • Manage and experiment with dynamic layout • Visually redefine a control’s appearance • Create Windows Runtime libraries • Use MVVM for data binding and commanding • Work with asynchronous methods; write your own About the Author CSS, and JavaScript • Animate transitions and create 2D and 3D effects Charles Petzold has been writing • Manage resolution, scaling, and navigation about Windows programming for 25 years. A Windows Pioneer Extend your skills and apps Award winner, Petzold is author Second Edition of the classic Programming Windows, the • Handle pointer, manipulation, tap, and hold events widely acclaimed Code: The Hidden • Manipulate bitmaps and rich text Language of Computer Hardware and • Work with GPS and orientation sensors Software, Programming Windows Phone 7, and more than a dozen other books. • Call Win32® and DirectX® functions • Enable share, search, and print FIRST Get C# and C++ code samples Ready to download at: edition http://go.microsoft.com/FWLink/?Linkid=277058 PREVIEW Petzold microsoft.com/mspress ISBN: 978-0-7356-7176-8 U.S.A. $59.99 Professional Canada $62.99 [Recommended] Programming/Windows Kraig Brockschmidt FIRST PREVIEW This excerpt provides early content from a book currently in development, and is still in draft, unedited format. See additional notice below. PUBLISHED BY Microsoft Press A Division of Microsoft Corporation One Microsoft Way Redmond, Washington 98052-6399 Copyright © 2013 Microsoft Corporation 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. This document supports a preliminary release of a software product that may be changed substantially prior to final commercial release. This document is provided for informational purposes only and Microsoft makes no warranties, either express or implied, in this document. Information in this document, including URL and other Internet website references, is subject to change without notice. The entire risk of the use or the results from the use of this document remains with the user. Unless otherwise noted, the companies, organizations, products, domain names, e-mail addresses, logos, people, places, and events depicted in examples herein are fictitious. No association with any real company, organization, product, domain name, e-mail address, logo, person, place, or event is intended or should be inferred. 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. 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, 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, Developmental, and Project Editor: Devon Musgrave Cover: Twist Creative • Seattle and Joel Panchot 2 Introduction It seems like it was only a few months ago that I was writing the introduction for the first edition of this book, Programming Windows 8 Apps in HTML, CSS, and JavaScript. Of course, it was only 8 months ago! It’s been a remarkably short time between the release of Windows 8 and the Windows 8.1 Preview that we’ve made available as of June 26th 2013 for the //build conference. And yet much has been improved in the Windows platform during that time. First of all, however, let me thank the hundreds of thousands of readers who downloaded the first edition of this ebook, both directly from Microsoft Press and from the Amazon Kindle store where the book has maintained a high ranking among programming titles as well as within the broader computer & technology category. I’m delighted that this work has been serving you well, and I was certainly inspired to start in on this second edition as soon as I began reading the specifications for Windows 8.1 Preview. My notes on what to add, what to change, and what to expand are quite lengthy! In this First Preview of the second edition, which constitutes only those chapters that I and my editors have worked through so far, I will not cover the whole Windows 8.1 Preview story, of course. For that I can still recommend the first edition of this book as a basis. Then check out the session videos from //build 2013 that you can find through http://buildwindows.com. The Windows Developer Center, http://dev.windows.com, also has updated documentation that covers the Windows 8.1 Preview, so you can find much more there. I can specifically recommend Windows 8.1 Preview: New APIs and features for developers. This second edition is intended to stand alone for developers who are starting with Windows 8.1 Preview. It represents the state of Windows 8.1 Preview rather than trying to document the delta from Windows 8. For this reason I’m not going into much detail about migrating apps from Windows 8 nor trying to highlight all the changes to both APIs and behaviors. Check the Developer Center for such information. Here’s a quick summary of what’s in this First Preview: Chapter 1, “The Life Story of a Windows Store App,” is much the same as in the first edition, with some small additions. For the most part, the core characteristics of the Windows platform is the same as with Windows 8, with the biggest exception being the view model for apps where we now have a variable sizing model. Chapter 2, “Quickstart,” is updated for Windows 8.1 Preview, and I’ve added some sections that cover extra improvements to the Here My Am! app that we’ll be building over the course of the book. Chapter 3, “App Anatomy, Page Navigation, and Promises,” is expanded from the first edition. Besides updating the text for small bits like new tile sizes in Windows 8.1 Preview, I’ve added a section on extended splash screens, tightened up the discussion of promises, written out some 3 details of the new task scheduler for the UI thread, and included a new section on debugging and profiling. Chapter 4, “Using Web Content and Services,” is a mixture of new content and networking topics from the first edition’s Chapter 14. I moved these topics earlier in the book because using web content is increasingly important for apps, if not essential. This chapter covers network connectivity, hosting content (especially with the new webview control), making HTTP requests (especially through the new Windows.Web.Http.HttpClient API), background transfers (which have been improved), authentication, and a little on Live Services. Appendix A, “Demystifying Promises,” completes the discussion of promises that starts in Chapter 3. That is, Chapter 3 covers the essentials about using promises, which are often returned from asynchronous Windows Runtime APIs. After writing the first edition, I wanted to spend more time with promises for my own sake, but it’s just my nature to leave a paper trail of my learnings! So, in this appendix we start from scratch about what promises are, see how promises are expressed in WinJS, explore how to create and source promises, and then pick apart some specific promise-heavy code. Appendix B, “Additional Networking Topics,” contains material that is related to Chapter 4 but didn’t fit into that flow or that is more peripheral in nature. As you can see, in this second edition I’ll be using appendices to go deeper into certain topics that would be too much of a distraction from the main flow of the chapters. Let me know what you think. Some of this material I’ve already posted on my blog, http://www.kraigbrockschmidt.com/blog, where I’ve been working on various topics since we published the first edition. I’ll continue to be posting there, though perhaps not quite on a daily basis as work on this second edition takes priority! Be mindful that the chapter organization of this second edition is still in flux, so references to later chapters are subject to change. As you can expect from the length of the change list I mentioned earlier, I’m going to be adding many pages to this second edition that all need to be appropriately organized! Who This Book Is For This book is about writing Windows Store apps using HTML5, CSS3, and JavaScript. Our primary focus will be on applying these web technologies within the Windows 8 and Windows 8.1 Preview platform, where there are unique considerations, and not on exploring the details of those web technologies themselves. For the most part, then, I'm assuming that you're already at least somewhat conversant with these standards. We will cover some of the more salient areas like the CSS grid, which is central to app layout, but otherwise I trust that you're capable of finding appropriate references for most everything else.