Tải bản đầy đủ (.pdf) (16 trang)

Windows phone toolkit in depth 3rd abstract

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (938.56 KB, 16 trang )


Windows Phone Toolkit

In Depth
edition

by Boryana Miloshevska


Windows Phone Toolkit in Depth 3nd edition

Disclaimers
Disclaimer of Endorsement

Reference within this book to any specific commercial or non-commercial product, process, or
service by trade name, trademark, manufacturer or otherwise does not constitute or imply an
endorsement, recommendation, or favoring by the author.
Disclaimer for Links to External, Third Party Web Sites

Links to external, or third party Web sites, are provided solely for readers' convenience. Links
taken to other sites are done so at your own risk and the author accepts no liability for any
linked sites or their content. When you access an external Web site, keep in mind that the
author has no control over its content.

www.windowsphonegeek.com

3


Windows Phone Toolkit in Depth 3nd edition


About the Author
Boryana Miloshevska is a software developer with more than 6 years of professional experience with
.NET technologies. She is a co-founder of www.windowsphonegeek.com – the leading Windows Phone
development community. Boryana is the author of the hugely popular "Silverlight for Windows Phone
Toolkit In Depth" and "Windows Phone Toolkit In Depth 2-nd" books and winner of the Microsoft
“Engineering Excellence Achievement” Award. She is an active blogger and tech enthusiast trying to
contribute to the Windows Phone development community in various ways, including more than 400
development articles, tutorials and guides related to Windows Phone most of which published on
www.windowsphonegeek.com.Boryana is also working as a consultant in the areas of Windows Phone
and Windows 8 application development.

About the Editor
Yordan Pavlov is an experienced software developer with 8 years of professional experience with the
.NET technology stack and a co-founder of www.windowsphonegeek.com. He has worked on many
interesting projects including UI and data access components at Telerik, financial software and even a
GIS system that consumes data from NASA satellites. Yordan is also a winner of the Microsoft
ImagineCup competition and the Microsoft “Engineering Excellence Achievement” Award.

www.windowsphonegeek.com

4


Windows Phone Toolkit in Depth 3nd edition

Table of Contents
Disclaimers ............................................................................................................................ 3
About the Author .................................................................................................................. 4
About the Editor .................................................................................................................... 4
Introduction ........................................................................................................................ 13

Who is this book for? .............................................................................................................................. 13
What this book covers? .......................................................................................................................... 13
How is this book structured? .................................................................................................................. 14
Source code............................................................................................................................................. 15
About the third edition ........................................................................................................................... 15

1. Introduction to Windows Phone 8.................................................................................... 17
2. Introduction to the Windows Phone Toolkit ..................................................................... 20
Components included in the Windows Phone Toolkit for Windows Phone, October 2012 .................. 20
Unit Testing Framework.......................................................................................................................... 21
What's included in the source code? ...................................................................................................... 21
Suggestions? Features? Questions? ....................................................................................................... 22
Official Blogs & Tweets ........................................................................................................................... 22
What else will you need? ........................................................................................................................ 23
Getting Started with the Windows Phone Toolkit .................................................................................. 23
Option1: Install Windows Phone Toolkit using NuGet ........................................................................... 24
Option2: Download the Windows Phone Toolkit Oct 2012 Source Code ............................................. 31
How to use unofficial builds.................................................................................................................... 33
How to use Windows Phone Toolkit in Visual Studio ............................................................................. 36
How to add Windows Phone Toolkit Controls to the Visual Studio Toolbox ......................................... 40
How to use Windows Phone Toolkit in Expression Blend ...................................................................... 45

3. AutoCompleteBox ........................................................................................................... 50
Overview ................................................................................................................................................. 50
Getting Started........................................................................................................................................ 50
Key Properties ......................................................................................................................................... 51
Key Events ............................................................................................................................................... 58
Key Methods ........................................................................................................................................... 61

www.windowsphonegeek.com


5


Windows Phone Toolkit in Depth 3nd edition
Data Binding AutoCompleteBox ............................................................................................................. 62
Data Binding AutoCompleteBox via ValueMemberBinding.................................................................... 65

4. ContextMenu .................................................................................................................. 68
Overview ................................................................................................................................................. 68
Getting Started........................................................................................................................................ 68
Key Properties ......................................................................................................................................... 69
Key Events ............................................................................................................................................... 71
MenuItem ............................................................................................................................................... 71
MenuItem Key Properties ....................................................................................................................... 72
MenuItem Key Events ............................................................................................................................. 73
Populating a ContextMenu with MenuItems ......................................................................................... 73
Populating ContextMenu with data via Data Binding............................................................................. 74
Using ContextMenu inside ListBox ItemTemplate (DataTemplate) ....................................................... 76

5. CustomMessageBox ......................................................................................................... 80
Overview ................................................................................................................................................. 80
Getting Started........................................................................................................................................ 80
Key Properties ......................................................................................................................................... 82
Key Events ............................................................................................................................................... 86
Key Methods ........................................................................................................................................... 87
Set UserControl as a Content of the CustomMessageBox control ......................................................... 88
Passing Data between the CustmMessageBox and and an application page ........................................ 89

6. DatePicker ....................................................................................................................... 93

Overview ................................................................................................................................................. 93
Getting Started........................................................................................................................................ 93
Key Properties ......................................................................................................................................... 95
Key Events ............................................................................................................................................... 96
Customizing the full-screen picker page ................................................................................................. 96

7. ExpanderView ................................................................................................................. 99
Overview ................................................................................................................................................. 99
Getting Started........................................................................................................................................ 99
Key Properties ....................................................................................................................................... 100

www.windowsphonegeek.com

6


Windows Phone Toolkit in Depth 3nd edition
Key Events ............................................................................................................................................. 102
Data Binding ExpanderView.................................................................................................................. 103
ExpandAll and CollapseAll Example ...................................................................................................... 109

8. HubTile .......................................................................................................................... 110
Overview ............................................................................................................................................... 110
Getting Started...................................................................................................................................... 110
Key Properties ....................................................................................................................................... 111
HubTileService ...................................................................................................................................... 114
Data Binding HubTile ............................................................................................................................ 115
Freezing and Unfreezing Tiles ............................................................................................................... 119

9. ListPicker ....................................................................................................................... 121

Overview ............................................................................................................................................... 121
Getting Started...................................................................................................................................... 121
Key Properties ....................................................................................................................................... 123
Key Events & Methods .......................................................................................................................... 125
Data Binding ListPicker.......................................................................................................................... 126
Working with ListPicker SelectedItem .................................................................................................. 129

10. LongListMultiSelector .................................................................................................. 134
Overview ............................................................................................................................................... 134
Getting Started...................................................................................................................................... 134
Key Properties ....................................................................................................................................... 135
Key Events ............................................................................................................................................. 140
LongListMultiSelectorItem .................................................................................................................... 142
LongListMultiSelectorItem Key Properties ........................................................................................... 142
LongListMultiSelectorItem Key Events ................................................................................................. 143
Data Binding LongListMultiSelector ...................................................................................................... 143

11. LoopingSelector ........................................................................................................... 154
Overview ............................................................................................................................................... 154
Getting Started...................................................................................................................................... 154
Key Properties ....................................................................................................................................... 159
Key Events ............................................................................................................................................. 160

www.windowsphonegeek.com

7


Windows Phone Toolkit in Depth 3nd edition
ILoopingSelectorDataSource ................................................................................................................. 160

Implementing a Generic LoopingSelectorDataSource .......................................................................... 161
LoopingSelector with Double Data ....................................................................................................... 165
LoopingSelector with Int Data .............................................................................................................. 166
LoopingSelector with String Data ......................................................................................................... 167
LoopingSelector with DateTime Data ................................................................................................... 168
Advanced Data Binding using IComparable<T> .................................................................................... 169
Advanced Data Binding using a separate Comparer............................................................................. 172

12. Map API extensions and Controls ................................................................................. 175
Overview ............................................................................................................................................... 175
Getting Started...................................................................................................................................... 175
GeocoordinateExtensions ..................................................................................................................... 176
MapExtensions ...................................................................................................................................... 177
MapItemsControl .................................................................................................................................. 177
Pushpin.................................................................................................................................................. 178
UserLocationMarker ............................................................................................................................. 178
MapChildControl ................................................................................................................................... 178
How to use the new Map API extensions ............................................................................................. 179
Defining the Data Source ...................................................................................................................... 179
Data binding the MapItemsControl ...................................................................................................... 180
Implement multiple visual states by changing the ContentTemplate of the Pushpin ......................... 181
Display the Current Location ................................................................................................................ 182

13. PhoneTextBox ............................................................................................................. 185
Overview ............................................................................................................................................... 185
Getting Started...................................................................................................................................... 185
Key Properties ....................................................................................................................................... 186
Key Events ............................................................................................................................................. 190

14. Rating Control.............................................................................................................. 191

Overview ............................................................................................................................................... 191
Getting Started...................................................................................................................................... 191
Key Properties ....................................................................................................................................... 192

www.windowsphonegeek.com

8


Windows Phone Toolkit in Depth 3nd edition
Key Events ............................................................................................................................................. 197

15. Transitions ................................................................................................................... 198
Overview ............................................................................................................................................... 198
Key concepts ......................................................................................................................................... 198
Getting Started...................................................................................................................................... 201
Page Transition ..................................................................................................................................... 202
UIElement Transition ............................................................................................................................ 204
Transition Structure .............................................................................................................................. 205
CustomTransition with XAML animation .............................................................................................. 206
CustomTransition with C# animation ................................................................................................... 208
CustomTransition with animation defined in the NavigationInTransition / NavigationOutTransition 209

16. TiltEffect ...................................................................................................................... 212
Overview ............................................................................................................................................... 212
Getting Started...................................................................................................................................... 212
Key Properties ....................................................................................................................................... 213
How to Enable TiltEffect globally .......................................................................................................... 214
How to Suppress TiltEffect .................................................................................................................... 215
Adding more controls to the list of TiltableItems ................................................................................. 215

Adding TiltEffect to data bound ListPicker items .................................................................................. 216

17. TurnstileFeatherEffect ................................................................................................. 218
Overview ............................................................................................................................................... 218
Getting Started...................................................................................................................................... 218
Key Properties ....................................................................................................................................... 219
Setup the page navigation before using the TurnstileFeatherEffect .................................................... 220
How to Add TurnstileFeatherEffect to a Databound ListBox ................................................................ 222
How to Add TurnstileFeatherEffect to different UI elements .............................................................. 225
Final Result ............................................................................................................................................ 225

18. TimePicker ................................................................................................................... 227
Overview ............................................................................................................................................... 227
Getting Started...................................................................................................................................... 227
Key Properties ....................................................................................................................................... 229

www.windowsphonegeek.com

9


Windows Phone Toolkit in Depth 3nd edition
Key Events ............................................................................................................................................. 230
Customizing the full-screen picker page ............................................................................................... 230

19. ToggleSwitch ............................................................................................................... 233
Overview ............................................................................................................................................... 233
Getting Started...................................................................................................................................... 233
Key Properties ....................................................................................................................................... 234
Key Events ............................................................................................................................................. 236

Dynamically Changing ToggleSwitch Content depending on the current State ................................... 237

20. WrapPanel ................................................................................................................... 239
Overview ............................................................................................................................................... 239
Getting Started...................................................................................................................................... 239
Key Properties ....................................................................................................................................... 240
Horizontal WrapPanel ........................................................................................................................... 241
Vertical WrapPanel ............................................................................................................................... 241
WrapPanel as ItemsPanel ..................................................................................................................... 242

21. UnitTesting Framework................................................................................................ 245
Introduction to Unit Testing ................................................................................................................. 245
Before you begin ................................................................................................................................... 245
Installing the Windows Phone Toolkit Test Framework via NuGet ...................................................... 246
Getting Started - Step By Step Guide .................................................................................................... 250
Introduction to Tags and how to use them .......................................................................................... 253
Testing Framework: Basic Tests and Async Tests ................................................................................. 254

22. Additional Components ............................................................................................... 260
SlideIn Effect ......................................................................................................................................... 260
RecurringDaysPicker ............................................................................................................................. 261
HeaderedItemsControl ......................................................................................................................... 262
DateTimeConverters ............................................................................................................................. 262
LocalizedResources ............................................................................................................................... 265

23. GestureService and GestureListener (obsolete) ............................................................ 267
Overview ............................................................................................................................................... 267
What is GestureService? ....................................................................................................................... 268

www.windowsphonegeek.com


10


Windows Phone Toolkit in Depth 3nd edition
What is GestureListener?...................................................................................................................... 269
Getting Started...................................................................................................................................... 269
GestureListener Key Events .................................................................................................................. 270
Examples ............................................................................................................................................... 276

24. LockablePivot (obsolete) .............................................................................................. 278
Overview ............................................................................................................................................... 278
Getting Started...................................................................................................................................... 278
Key Properties ....................................................................................................................................... 279
Examples ............................................................................................................................................... 279

25. LongListSelector (obsolete) .......................................................................................... 282
Overview ............................................................................................................................................... 282
Visual structure ..................................................................................................................................... 282
Getting Started...................................................................................................................................... 284
Key Properties ....................................................................................................................................... 285
Key Events ............................................................................................................................................. 289
Key Methods ......................................................................................................................................... 292
Data Binding LongListSelector .............................................................................................................. 293
Customizing LongListSelector group popup ......................................................................................... 298
Animating LongListSelector group items using transitions................................................................... 299
Dynamically Insert, Update and Delete data in a data bound LongListSelector .................................. 303
How to get Selected Item and Group info in the LongListSelector SelectionChaged event ................. 307

26. MultiselectList (obsolete) ............................................................................................. 310

Overview ............................................................................................................................................... 310
Getting Started...................................................................................................................................... 310
Key Properties ....................................................................................................................................... 311
Key Events ............................................................................................................................................. 312
MultiselectItem ..................................................................................................................................... 312
MultiselectItem Key Properties & Events ............................................................................................. 313
Data Binding MultiselectList ................................................................................................................. 314

27. PerformanceProgressBar (obsolete) ............................................................................. 322
Overview ............................................................................................................................................... 322

www.windowsphonegeek.com

11


Windows Phone Toolkit in Depth 3nd edition
Getting Started...................................................................................................................................... 323
Key Properties ....................................................................................................................................... 324

www.windowsphonegeek.com

12


Windows Phone Toolkit in Depth 3nd edition

Introduction
Who is this book for?
The target audience of this book is anyone who is interested in Windows Phone 8

development. It covers all controls from the Microsoft Windows Phone Toolkit – Oct 2012
(Windows Phone 8 SDK).
This book contains all the information necessary to get you started with the Windows Phone
Toolkit for Windows Phone 8. It is suitable for both beginners and advanced developers.
Before you begin you will need to have a basic understanding of:




XAML principles
Windows Phone 8 principles
C# programming

What this book covers?
The book covers “in depth” all controls plus the testing framework from the Microsoft Windows
Phone Toolkit for Windows Phone 8 including:
o
o
o
o
o
o
o
o
o
o
o
o
o
o

o
o
o
o
o
o

AutoCompleteBox
ContextMenu
CustomMessageBox
DatePicker
DateTimeConverters
ExpanderView
HeaderedItemsControl
HubTile
ListPicker
LocalizedResources
LoopingSelector
LongListMultiSelector
Page Transitions
PhoneTextBox
Rating Control
TiltEffect
TimePicker
TurnstileFeatherEffect
ToggleSwitch
WrapPanel

www.windowsphonegeek.com


13


Windows Phone Toolkit in Depth 3nd edition
o
o

Test Framework
Obsolete Controls:
o GestureService and GestureListener*(obsolete)
o LockablePivot*(obsolete, use for WP7 only)
o LongListSelector*(obsolete, use for WP7 only)
o MultiselectList*(obsolete, use for WP7 only)
o PerformanceProgressbar*(obsolete, use for WP7 only)

Furthermore the first two chapters make a quick introduction to the main concepts related to
Windows Phone 8 application development and how to get started using external libraries like
the “Windows Phone Toolkit”.

How is this book structured?
In this book you will learn how to use the different tools and controls that the “Windows Phone
Toolkit” for Windows Phone 8 offers.
Chapter 1 is a brief introduction to the main Windows Phone concepts. You will learn the key
concepts that you need to know in order to get started with Windows Phone 8 application
development.
Chapter 2 is focused on getting started with the “Windows Phone Toolkit” for Windows Phone
8. It gives you all the necessary information from start to finish including:










What is in the toolkit?
System requirements
Installing
Windows Phone Toolkit and Visual Studio
Visual Studio Toolbox integration
Expression Blend integration
Unofficial builds
Issue Tracker

In Chapters 3 through Chapter 27 you will learn how to use each one of the toolkit controls “in
depth”. Each chapter contains the following main sections:
“Overview”: a brief description of the main features
“Getting Started”: explains how to get started using the control in XAML and C#

www.windowsphonegeek.com

14


Windows Phone Toolkit in Depth 3nd edition

“Key Properties”/ “Key Methods”/ “Key Events”: a full explanation of the available public API
(with short samples)
Examples: Depending on the importance and how complex the control is there are more or

less examples with source code and detailed explanation.

Source code
The full source code used in this book can be downloaded here:
/>All sample projects discussed in this book target Windows Phone 8.
The following conventions are used in code samples (XAML and C#):
XAML
//XAML code here

C#
//C# code here

NOTE: Important things here!

About the third edition
This is the third version of the hugely popular book “Windows Phone Toolkit In Depth" that I
wrote a while ago. I have reflected all the changes that have been made in the latest official Oct
2012 release of the toolkit for Windows Phone 8. If you are using this book with another
version of the Windows Phone Toolkit and / or Windows Phone, there might be differences in
the available APIs.
What`s new: This book is completely changed due to the fact that this 3rd edition is entirely
focused on Windows Phone 8 app development. All previous examples and APIs are updated to
the latest WP8 version of the toolkit and also all new components and APIs are covered in
depth. A couple of new controls have been introduced in the latest release of the Windows
Phone Toolkit as well as a brand new Test Framework. All this is explained in details with a lot

www.windowsphonegeek.com

15



Windows Phone Toolkit in Depth 3nd edition

of new WP8 examples, complete WP8 API guide, explanations and more. The full source code
of all examples is now structured in a single solution with a separate project for each sample.

www.windowsphonegeek.com

16



×