Table of Contents
Preface ix
1 Making the Transition from .NET (Part 1) 1
Why WinRT? 1
Philosophical Differences 2
Objectives 3
The New Project Templates 3
WinRT Metadata 4
Project Settings and Adding References 9
Building a Basic User Interface 11
UI Tracks 11
XAML Parsing Basics 14
Building a Basic Page 15
Implementing MWM 25
WPF and Silverlight 26
MWM Structure and Inversion of Control 28
Creating the View-Model and Running the App 38
2 Making the Transition from .NET (Part 2) 47
Inversion of Control 47
Installing TinyloC 48
Initializing IoC Defaults 49
Understanding Asynchrony 53
How Asynchrony Works in WinRT 55
Calling the Server 60
Building the Service Proxies 60
Building the Register Method 63
Finishing the UI to Call the Register Server Function 67
Logon 68
Building LogonServiceProxy 69
Building the Logon Page 70
Busy Indicators 75
Positioning the Indicator 75
Showing the Indicator 77
3 Local Persistent Data 83
SQLite and sqlite-net 84
Working with SQLite 85
A Primer on Object-Relational Mapping 86
Using the Micro-ORM in sqlite-net 87
Storing Settings 89
The SettingItem Class 89
Linking in sqlite-net 91
Creating the Database Table for SettingItem 95
Reading and Writing Values 96
Modifying LogonPageViewModel 97
Caching Data Locally 100
Local Caching 100
Mapping JSON to Database Entities 101
Creating Test Reports 102
Setting Up the User Database 103
Creating ReportsPage 105
Using Templates 106
Building a Local Cache 109
Updating the Cache 112
Returning Reports from the Server 113
The Items Property 114
4 The App Bar 119
Adding a Simple App Bar 120
Getting Started with an App Bar 121
App Bar Behavior 124
App Bar with Single-Select Grid 126
App Bar with Multiselect Grid 126
A More Complex App Bar Implementation 127
Showing the App Bar on Multiple Selections 128
Checking Touch Operations 133
Showing the App Bar on Right-Click 135
Showing Context Options 136
App Bar Images 140
The Glyph Method 140
Using Images 146
5 Notifications 155
Local Notifications 156
Turning Notifications On and Off 156
XML Templates 156
Toast 158
Badges 167
Tiles 170
Other Notification Features 176
Push Notifications 177
WNS Process 177
Handling User Accounts 179
Obtaining a Notification URI 180
Sending to WNS 182
Troubleshooting Tips 191
6 Working with Files 193
The File Picker 193
File Associations 196
Launching the App 197
Handling the Launch 199
Sandboxed File Access 201
Walking and Copying Pictures 203
Roaming Files 206
Multiple Devices 207
Setting Up the Remote Debugging Client 207
Syncing Files 209
Roaming Settings 210
Using Files with StreetFoo 210
Getting Report Images 211
Migrating to ReportViewItem 212
Implementing ReporllmageCacheManager 217
7 Sharing 223
Sharing Data 224
Basic Sharing 224
Pull Requests/Deferrals 233
Acting as a Share Target 235
Sharing Text 235
Sharing Text (and Troubleshooting) 238
Long-Running Operations 249
Sharing Images 252
Quick Links 254
8 Searching 257
Implementing Search 258
Creating the Search Results Page 258
Creating SearchResultsPageViewModel 258
Implementing the Search Operation 263
Refining Search 276
Placeholder Text 277
Suggestions 278
Remembering Where We Were 284
Using the SearchBox 289
Other Best-Practice Notes 291
9 Settings 293
Adding Options 293
Standard Options 294
Adding Custom Options 294
Implementing the Settings Flyout 297
Building a Settings Pane 297
Building MySettingsFlyout 301
Developing a Help Screen 303
Creating a Help Pane 303
Handling the Fl Key 305
Rendering Markup 306
10 Location 311
Creating a Singleton View 311
Creating the View-Model 312
Creating the View 315
Navigating to the View 318
Retrieving a Current Location 322
Using the Simulator with Location 327
Integrating Maps 328
Adding the Bing Maps Control 329
Handling Input with the View 331
Packaging Points for Display 332
Showing Points on the Map 336
Shelling to the Maps App 339
11 Using the Camera 343
Capturing Photos 344
Creating EditReportPage 345
Building EditReportPageViewModel and Its View-Model 346
Saving and Canceling 352
Adding the New Option 355
Handling Temporary Files 356
Changing the Manifest 356
Taking Pictures 357
Implementing Save 360
Validating and Saving 360
Resizing Images 363
12 Responsive Design 369
Updating the Grid View 371
The VisualStateManager 371
Creating MyListView 373
Modifying the App Bar 375
Updating Singleton Views 377
Adding a More Button to the App Bar 380
Handling Views That Don't Support 320-Pixel Width 385
13 Resources and Localization 387
.pri Files 387
Adding Strings 390
Localizing Strings 393
Default Project Locales 393
Localizing Strings in XAML 394
Conventions 398
Changing Other Properties 399
Explicitly Loading Strings 399
Localizing Images 402
Varying Images by Locale 402
Varying Images by Display DPI 405
14 Background Tasks and App Lifetime 409
App Lifetime 410
Background Tasks API 411
CPU Usage Quota 412
Triggers and Conditions 413
Execution Model 415
Implementing a Sync Background Task 416
Building the Facade 422
Debugging the Task 425
Troubleshooting Background Tasks 427
Restricting the Run Period 428
Implementing the Sync Function 433
Sending Changes 434
Receiving New Work 438
Signaling the App from the Background Task 443
Putting the App on the Lock Screen 444
15 Sideloading and Distribution 447
Using the Windows App Certification Kit 450
Distribution Through Production Sideloading 451
Turning on Sideloading on Windows 8 452
Installing Apps 453
Distribution Through the Windows Store 453
A Cryptography and Hashing 457
B Unit Testing Basics for Windows Store Apps 467
Index 475