Tải bản đầy đủ

Silverlight 4 in action

IN ACTION
Revised Edition of
Silverlight 2 in Action

Pete Brown

MANNING
www.it-ebooks.info


Silverlight 4 in Action

www.it-ebooks.info


Download from Wow!
eBook
www.it-ebooks.info


Silverlight 4 in Action

SILVERLIGHT 4, MVVM, AND WCF RIA SERVICES

PETE BROWN

Revised Edition of Silverlight 2 in Action
by Chad Campbell and John Stockton

MANNING
Greenwich
(74° w. long.)

www.it-ebooks.info


For online information and ordering of this and other Manning books, please visit
www.manning.com. The publisher offers discounts on this book when ordered in quantity.
For more information, please contact
Special Sales Department
Manning Publications Co.
180 Broad Street
Suite 1323
Stamford, CT 06901
Email: orders@manning.com
©2010 by Manning Publications Co. All rights reserved.
No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in
any form or by means electronic, mechanical, photocopying, or otherwise, without prior written
permission of the publisher.

Many of the designations used by manufacturers and sellers to distinguish their products are
claimed as trademarks. Where those designations appear in the book, and Manning
Publications was aware of a trademark claim, the designations have been printed in initial caps
or all caps.
Recognizing the importance of preserving what has been written, it is Manning’s policy to have
the books we publish printed on acid-free paper, and we exert our best efforts to that end.
Recognizing also our responsibility to conserve the resources of our planet, Manning books are
printed on paper that is at least 15 percent recycled and processed without the use of elemental
chlorine.

Manning Publications Co.
180 Broad Street, Suite 1323


Stamford, CT 06901

Development editor:
Copyeditor:
Cover designer:
Typesetter:

Jeff Bleiel
Benjamin Berg
Marija Tudor
Gordan Salinovic

ISBN 9781935182375
Printed in the United States of America
1 2 3 4 5 6 7 8 9 10 – MAL – 15 14 13 12 11 10

www.it-ebooks.info


brief contents
PART 1

PART 2

INTRODUCING SILVERLIGHT . .............................................1
1



Introducing Silverlight 3

2



Core XAML

3



The application model and the plug-in

4



Integrating with the browser

73

5



Integrating with the desktop

95

6



Rendering, layout, and transforming

7



Panels

8



Human input 188

9



Text

10



Controls and UserControls

20
47

138

171
203
234

STRUCTURING YOUR APPLICATION ...................................259
11



Binding

261

12



Data controls: DataGrid and DataForm

13



Input validation

14



Networking and communications

308
335

v

www.it-ebooks.info
Download from Wow! eBook

285


vi

PART 3

BRIEF CONTENTS

15



Navigation and dialogs

382

16



Structuring and testing with the MVVM/ViewModel
pattern 416

17



WCF RIA Services

459

COMPLETING THE EXPERIENCE ........................................513
18



Graphics and effects

515

19



Printing

20



Displaying and capturing media

21



Working with bitmap images

22



Animation and behaviors

23



Resources, styles, and control templates

24



Creating panels and controls

25



The install experience and preloaders

542
572

618

637
670

699
720

www.it-ebooks.info
Download from Wow! eBook


contents
preface xix
acknowledgments xxi
about this book xxiii
about the cover illustration

xxix

PART 1 INTRODUCING SILVERLIGHT ...................................1

1

Introducing Silverlight
1.1
1.2
1.3
1.4

3

Silverlight and the web 4
Silverlight and WPF 5
Types of Silverlight applications 6
What’s new since the first edition 6
Features for business and client applications 7 Media and
graphics enhancements 7 User interaction 8 Text 9




1.5



Getting started with Silverlight development 9
Setting up your development environment 9

1.6



Helpful sites

Building your first Silverlight web application

10

10

Project setup 11 User interface 12 Calling Twitter search 13
Parsing the results and binding the ListBox 14 Making the ListBox
contents more meaningful 17






1.7

Summary

19
vii

www.it-ebooks.info
Download from Wow! eBook


viii

CONTENTS

2

Core XAML 20
2.1

XAML basics

21

Objects 22 Namespaces 23 Properties 26 Dependency
properties 27 Attached properties 29 Events 30
Commands 32 Behaviors 33












2.2

Object trees and namescope
Object trees 35

2.3

Namescope 37



XAML extensions and type converters 38
Markup extensions

2.4
2.5
2.6

3

34

38



Type converters 39

Loading XAML at runtime 42
Tools for working in XAML 45
Summary 46

The application model and the plug-in 47
3.1

The Silverlight application model 48
Application startup process 48 XAP 50 The application
manifest file 51 The Silverlight application object 52
Application dependencies 55 Assembly caching 55








3.2

Creating the Silverlight plug-in 58
Using the object tag 59 Using the Silverlight.js utility
file 60 Creating an instance of the Silverlight plug-in




3.3

Integrating the Silverlight plug-in

61

62

Relating the Silverlight application to the HTML DOM 63
Clarifying the initial experience 64 Handling plug-in
events 69 Sending initialization parameters 71




3.4

4

Summary

72

Integrating with the browser
4.1
4.2

73

Silverlight and the HTML DOM 74
Managing the web page from managed code

76

Navigating web page contents 76 Working with element properties
Handling CSS information 78 Accessing the query string 79




4.3

Working with the user’s browser window 79
Prompting the user 80 Navigating the browser window 81
Discovering the browser properties 82


4.4

Bridging the scripting and managed code worlds
Calling managed code from JavaScript
managed code 85

83



82

Using JavaScript from

www.it-ebooks.info
Download from Wow! eBook

77


ix

CONTENTS

4.5

Hosting HTML in Silverlight 86
Hosting the WebBrowser control

4.6

5

Summary

Using the WebBrowserBrush

92

95

Silverlight out of the browser

96

Capabilities and restrictions 98

5.2



94

Integrating with the desktop
5.1

87



The end-user experience 98

Creating out-of-browser applications 101
The out-of-browser settings file 101 Controlling the experience 102
Customizing icons 106 Checking the network state 106 Alerting
the user with Notification toast 108 Implementation specifics 109








5.3

Escaping the sandbox—elevated trust 110
Creating elevated-trust applications 110
mode 113

5.4

Local file access

Detecting elevated trust

113

Accessing special folders
to a file 115

5.5



COM automation

113



Reading from a file 114



Writing

115

Detecting COM automation availability 115 Using COM
automation to make Silverlight talk 117 Accessing GPS data
using COM automation 117 Automating Excel 119






5.6

Controlling the host window

120

Basic window properties 121 Changing window chrome 122
Minimizing, maximizing, restoring, and closing 123
Moving 124 Resizing 125




5.7

Running in full screen

126

Normal full-screen mode 126

5.8



Elevated trust full-screen mode 128

Storing data in isolated storage

128

IsolatedStorageFile: the virtual filesystem 129 Reading and writing
files: the isolated storage way 133 Administering isolated storage 136




5.9

6

Summary

136

Rendering, layout, and transforming 138
6.1

The UIElement and FrameworkElement
Properties 139

6.2



Methods

The rendering process

139

145

146

Clock tick 148 Per-frame rendering callback
Rasterization 149


148

www.it-ebooks.info
Download from Wow! eBook


x

CONTENTS

6.3

The layout system

155

Multipass layout—measuring and arranging 155 The
LayoutInformation class 157 Performance considerations




6.4

158

Render transforms 159
RotateTransform 160 ScaleTransform 160 SkewTransform 161
TranslateTransform 161 TransformGroup 162 CompositeTransform 163 MatrixTransform 164










6.5

3D projection transforms
PlaneProjection 166

6.6

7

Summary



166

Matrix3dProjection

168

169

Panels 171
7.1
7.2
7.3

Canvas 172 Arranging content of a Canvas
The StackPanel 176
The Grid 177


173

Arranging Grid content 178 Positioning Grid content 180
Spanning cells 180 Sizing it up 181 Working with the grid
programmatically 183 Customizing cell boundaries 184








7.4

8

Summary

187

Human input 188
8.1

Capturing the keyboard

189

Understanding focus 189 Handling keyboard events 190
Dealing with modifier keys 192


8.2

Mouse input 193
Mouse button and movement events 193

8.3
8.4

Using multi-touch 197
Collecting ink drawings 199
Creating the InkPresenter 199
ink 201

8.5

9

Using the mouse wheel



Summary



Collecting ink 199



Styling the

202

Text 203
9.1

The text system

204

Subpixel text rendering

9.2

Displaying text

205



Text hinting

205

207

Font properties 207
Spacing 214



Flow control

210



Text properties

www.it-ebooks.info
Download from Wow! eBook

211

195


xi

CONTENTS

9.3
9.4

Embedding fonts 216
Entering and editing text 218
Handling basic text input 218 Understanding input method
editors 220 Copying text with the Clipboard API 222
Collecting sensitive data 224




9.5

Entering and displaying rich text
Formatting and inline elements 225

9.6

10

Summary

234

Control 235
Appearance

10.2

Working with selected text 229

232

Controls and UserControls
10.1

225


235



Navigation and state

236



Templating



The

237

ContentControl 238
The ContentPresenter 239

10.3

Button controls

240

The Button 241 The HyperlinkButton 241
RadioButton 242 The CheckBox 244




10.4

ItemsControls
The ListBox

10.5

245
246



The ComboBox

Creating UserControls

Summary



The TabControl 249

252

Defining the appearance 253
Calling the control 257

10.6

248



Defining the behavior 254

258

PART 2 STRUCTURING YOUR APPLICATION .......................259

11

Binding
11.1

261

Binding with your data

262

Mastering the binding syntax

11.2

263



Choosing a binding mode

Understanding your binding source

265

267

Binding to a property 267 Binding to an
object 268 Binding to a UI element 270 Binding to an
indexed element 272 Binding to a keyed (string indexed)
element 273 Binding to an entire collection 274










11.3

Customizing the display

276

Formatting values 276 Converting values during binding 277
Providing default fallback values 280 Handling null values 280




www.it-ebooks.info
Download from Wow! eBook


xii

CONTENTS

11.4

Creating data templates

280

Using a DataTemplate with a ContentControl
an ItemsControl with a DataTemplate 282

11.5

12

Summary

281



Rendering

283

Data controls: DataGrid and DataForm 285
12.1

The DataGrid 286
Displaying your data 286
items 292

12.2

The DataForm



Editing grid data

292



Sorting

293

Displaying your data 294 Binding to lists of data 296
Customizing display 299 Customizing edit, add, and display
templates 300 Finer control over editing and committing
data 302






12.3

Annotating for display

304

The Display attribute 304

12.4

13

Summary

The Editable attribute

306

307

Input validation
13.1
13.2



308

The validation example source and UI 309
Exception-based property validation 313
Handling exception validation errors 313 Custom validation
code 314 Validation error display 315




13.3

Synchronous validation with IDataErrorInfo

316

The IDataErrorInfo interface 316 Simple validation with
IDataErrorInfo 317 Cross-field validation with IDataErrorInfo
Combining exceptions and IDataErrorInfo 320




13.4

Asynchronous validation with INotifyDataErrorInfo

321

The INotifyDataErrorInfo interface 321 Implementing the
interface 322 Binding support 323 Building the WCF web
service 323 Adding the client service code 324 Property
modifications 325








13.5



Annotating for validation

327

Validation attributes 327 Annotating your entity 328
Calling external validation functions 330 Creating custom
validators 331




13.6
13.7

Comparison of validation approaches
Summary 333

332

www.it-ebooks.info
Download from Wow! eBook

318


xiii

CONTENTS

14

Networking and communications
14.1

335

Trust, security, and browser limitations

336

Cross-domain network access 336 Making your application
secure 340 Limitations of the browser 341




14.2

Connecting to data sources
Using SOAP services 342

14.3

The client HTTP stack

342

RESTful services



351

355

Manually creating the client stack 355 Automatically using the
client stack 356 Automatically setting the HTTP Referer and
other headers 356 Authentication credentials 357
Managing cookies with the CookieContainer 359






14.4

Making the data usable
Reading POX 360

14.5



360

Converting JSON

Using advanced services

364

366

WCF service enhancements 366 WCF duplex services
Connecting to sockets 372 Multicast sockets 374

367





14.6

Connecting to other Silverlight applications
Creating the receiver 377
all together 379

14.7

15

Summary

Creating the sender 378

Putting it

Browser navigation background 383


Anchor hashtags 384



Back and forth

The Navigation Application template 386
Creating a navigation application 386
Changing the application theme 390

15.3



382

Browser journals 384

15.2

377

381

Navigation and dialogs
15.1



Navigating to pages



Adding a new page

388

392

The Page class 392 The NavigationService class 393 Frames
and URIs 396 Caching pages 399 Navigating to pages in
other assemblies 400






15.4



Navigation out of the browser

403

Providing custom navigation controls 403

15.5

Showing dialogs and pop-ups

408

The Popup control 408 Displaying a dialog box with the
ChildWindow control 408 Prompting for a file 412




15.6

Summary

415
www.it-ebooks.info

Download from Wow! eBook

385


xiv

CONTENTS

16

Structuring and testing with the MVVM/ViewModel
pattern 416
16.1

Project setup and traditional code-behind approach
Project and service setup

16.2

418

A typical code-behind solution



Model-View-ViewModel basics
Factoring out reusable code
Business rules and logic

16.4

434

422

425

Keep it simple: a basic ViewModel implementation

16.3

417

427

433
Data access and service calls 436



Better separation from the UI

438

Using commands 438 Using the CallMethodAction behavior 442
View-specific entities and ViewModels 443 Interfaces, IoC, and
ViewModel locators 448




16.5

Testing

451

Introduction to the Silverlight Unit Testing Framework 451 Testing
the ViewModel 455 Testing asynchronous operations 456




16.6

17

Summary

457

WCF RIA Services 459
17.1

WCF RIA Services architecture, tooling, and
template 461
RIA Services tooling support 462
template 462

17.2



Creating a project with the

Exposing data with the domain service

465

Creating the domain service 466 Exposing the domain service to
other clients 468 Domain service method types 472 Using a
domain service from Silverlight 476




17.3

Filtering, sorting, grouping, and paging 480
Filtering 481

17.4



Updating data



Sorting

484



Grouping

485



Paging 486

488

Using the DataForm UI 489 The domain context 490 The
Entity class 492 Using validation and display metadata 494






17.5

Loose coupling: using presentation models

496

Creating the employee presentation model 497 Supporting query
operations 498 Supporting update operations 500 Supporting
insert operations 502




17.6



Business logic 503
Business logic in entities 504



Sharing code

505

www.it-ebooks.info
Download from Wow! eBook


xv

CONTENTS

17.7

Authentication and authorization
Authentication

17.8

Summary

506

506

Authorization



509

510

PART 3 COMPLETING THE EXPERIENCE ............................513

18

Graphics and effects 515
18.1

Shapes

516

Lines 517 Rectangle 517
Polygon 519


18.2

Geometry

Brushes

518

Polyline



519

520

Simple geometries
geometries 523

18.3

Ellipse



521



Path geometries

522



Composite

524

SolidColorBrush 525 LinearGradientBrush 526 RadialGradientBrush 528 ImageBrush 529 VideoBrush 530






18.4

Effects

531

Using built-in effects

18.5

19

Summary

Printing
19.1



532



Creating custom pixel shaders 535

540

542

How Silverlight printing works
The PrintDocument class 544
Rasterization 549

19.2

543
The PrintPage Event 547

Printing onscreen Information
Printing the content as is 550
Scaling content to fit 554

19.3





550

Rerooting the elements to fit 552

Multipage printing dedicated trees

556

Prerequisites 557 Printing line items 560 Adding multipage
support 566 Adding a header and footer 567






19.4

20

Summary

570

Displaying and capturing media
20.1

Audio and video

572

573

Media source 573 Common properties 579
properties 581 Video specific properties 582
media file 583







www.it-ebooks.info
Download from Wow! eBook

Audio specific
The lifecycle of a


xvi

CONTENTS

20.2

Playlists

584

Understanding client-side playlists 585
playlists 587

20.3

Interactive playback

588

Controlling the play state

20.4

Using server-side



589

Using protected content

Working with the timeline 589



591

Requesting protected content 591 Retrieving the PlayReady
components 592 Unlocking protected content 592




20.5

Using the Silverlight Media Framework 593
Using the player libraries 593

20.6

Creating the player



594

Working with raw media 596
A custom MediaStreamSource class 596
video 598 Creating raw audio 602



Creating raw



20.7

Using the webcam

607

Gaining access to capture devices 607 Working with video 609
Capturing still images 612 Getting the raw video data 614
A note about audio 616




20.8

21

Summary

617

Working with bitmap images
21.1
21.2

618

Basic imaging 619
Creating images at runtime

620

Creating from existing images 621 Creating from UI elements
A Mandelbrot fractal generator 624


21.3

Deep Zoom

623

627

Showing an image 627 Zooming in and out 628 Managing
the viewport 630 Deploying multiscale images 631






21.4

Dealing with dead space
Filling the space 633
UniformToFill 635

21.5

22

Summary

Uniform sizing

633



Fill the area 634

636

Animation and behaviors
22.1
22.2



632

637

Animation: it’s about time 638
Mastering the timeline 639
What type of property are you animating? 639 Where are you
starting from and where are you going? 642 How long should the
animation run? 644




www.it-ebooks.info
Download from Wow! eBook


xvii

CONTENTS

22.3

Storyboarding

647

Understanding the storyboard 647 Hitting the target 648
Controlling the Storyboard 650 Being resourceful 652




22.4

Keyframing

654

Interpolation: it’s about acceleration

22.5

Easing functions

660

Using easing functions 661
function 663

22.6

23

Creating a custom easing



Behaviors, triggers, and actions
Using existing behaviors

22.7

656

Summary

666

665

Creating your own behavior



669

Resources, styles, and control templates
23.1

Being resourceful

670

671

Declarative resources 671
Bundled resources 678

23.2

Accessing loose resources



677

Giving your elements style 680
Defining the look 681 Explicitly keyed style definitions
Implicit style definitions 685


23.3

23.4

Creating templates

24

Building a control template
templates 690

686

Dealing with visual states

691

Sharing your visual states
Summary 697

Creating panels and controls
24.1

683

686

Understanding the components
VisualStateManager 693

23.5
23.6

667



Creating reusable

691



Leveraging the

697

699

Creating a custom panel 700
Project setup 701 The OrbitPanel class 701
Custom layout 705 Enhancements 709




Properties 702



24.2

Creating a custom control 710
Choosing the base type 711 Properties 712 The control template
contract 712 The default template 714 Visual states 715
Visual states in template 716




24.3

Summary





718
www.it-ebooks.info

Download from Wow! eBook


xviii

CONTENTS

25

The install experience and preloaders
25.1

Handling the “Silverlight not installed” scenarios
Creating your own install experience

25.2

720

Using a custom preloader

721

722

724

Creating the appearance 724 Integrating the custom splash
screen 726 Monitoring the load progress 727




25.3
appendix

Summary

728

Database, connection, and data model setup
index 735

729

www.it-ebooks.info
Download from Wow! eBook


preface
My background is in client application development. I started on the Commodore 64
in seventh grade in the 1980s, later moved to DOS with dBase, QuickBasic, and C++,
and eventually Windows programming using C++, Borland Delphi 1.0, PowerBuilder,
Visual Basic 3-6, and .NET.
Though I’ve written plenty of pure HTML/JavaScript web applications, I’ve always
preferred client programming over strict web programming because I felt HTML/
JavaScript programming treated the immensely powerful PC as a dumb terminal,
squandering its CPU cycles for applications that were almost entirely network bound
in performance. Only recently is this changing.
Back when web applications started to become more popular, customers loved the
flexibility of the blank canvas of HTML versus the old battleship gray look, as well as
the ease of deployment of web applications. On the client development side, we had
some things that came close (WPF for appearance, for one) but nothing that combined the ease of deployment with the modern look.
For a while, it looked like the world was going to move to relatively dumb web
applications, treating the local PC as just a keyboard and display—a disappointing
move to say the least.
Back in 2006, long before I took my job as a Silverlight and WPF Community PM
with Microsoft, I attend the first Microsoft MIX conference in Las Vegas. On March 21,
day two of the conference, I attended some sessions about WPF/E, the product that
would later be named Silverlight. Even then, Microsoft had a strong vision for Silverlight, a vision that included desktops, mobile devices, and set-top boxes. It was

xix

www.it-ebooks.info
Download from Wow! eBook


xx

PREFACE

planned to be a lightweight version of WPF optimized for cross-platform scenarios,
which would both take advantage of client-side processing power (when the .NET CLR
was incorporated) as well as provide the ease of deployment of a traditional web application. This was exactly what I was looking for!
I was pretty jazzed about WPF/E at the time. I was also a little concerned about
making the case for adoption. I took a wait-and-see approach. When Silverlight 1.0
CTPs and betas hit the street, I was less than impressed, because they were JavaScript
only. I wasn’t a big fan of JavaScript at the time and felt WPF/E wouldn’t make any
meaningful impact until they delivered on the promise of the CLR inside the browser.
Nevertheless, early in 2007 I took on a project to create a carbon offset calculator in
WPF/E, to be hosted in SharePoint on a public internet site.
Then, we had MIX07 and the name Silverlight was given to WPF/E. Along with it,
Microsoft introduced Silverlight 1.1 alpha—a version that worked with managed code
and included a cross-platform version of the .NET CLR. Yay! No JavaScript! (Hey, this
was before jQuery proved to me that JavaScript can also be awesome.) Right at that
point, I lobbied the project sponsors to let us work in Silverlight 1.1a. I also spoke with
some contacts at Microsoft and received permission to go live with the Silverlight 1.1a
application, happily foisting alpha code on unsuspecting users.
Despite, or perhaps because of, having to code many primitives from scratch (we
needed buttons and drop-down lists, none of which existed in Silverlight 1.1a), I was
completely hooked. It felt like the old days of DOS programming when you had to spelunk without much support and make up your own tricks for how to best accomplish
things. It was the Wild West of programming. (And, by that, I mean the Wild West with
giant Steampunk spiders added into the mix.)
I still had (and have) a place in my heart for Silverlight’s big brother WPF, but it
was easy to see that Silverlight was going to take the world by storm. WPF is still an
incredibly powerful technology, but it tends to appeal more to niche users and ISVs as
opposed to the broad group building web-based applications for a living.
The two of us on the carbon calculator development team released the first Silverlight managed code application ever to go live. It included video, Windows Live Maps
integration, web services integration with SharePoint, carbon offset calculations of
course, and a completely data-driven, configurable UI with SharePoint as the backend, supporting everything.
At the time, there was no real ecosystem around Silverlight, and the idea of using real
designers on client applications in the Microsoft stack hadn’t yet caught on. Despite the
primitive UI we designed, I’m still impressed with what we put together. I was thrilled to
be able to use .NET skills in something that was truly unique in the .NET space.
Later that year, Silverlight 1.1a would be updated to a stronger subset of WPF and
rebranded as Silverlight 2, laying the groundwork required for Silverlight 4, a release
that continues to impress and engage me every day I use it.
PETE BROWN

www.it-ebooks.info
Download from Wow! eBook


acknowledgments
A book like this is a team effort from start to finish. Though my name may be on the
cover, there’s no way I could’ve completed this without the support and hard work of
many others. I’d like to thank:














Chad Campbell and John Stockton for creating such an excellent first edition.
Without their hard work covering Silverlight 2, I would never have thought to
create a Silverlight 4 edition.
Marshal Agnew, Brendan Clark, and Jordan Parker on the Silverlight product
team for their help in digging into the darkest recesses of the rendering and
layout system. If not for these folks, I wouldn’t have been able to provide the
level of detail chapter 6 includes.
David Ferguson and Seema Ramchandani, both on the Silverlight product
team, for help on performance questions around transformations.
Tim Heuer on the Silverlight product team for help on the Silverlight installation experience covered in chapter 25.
Jeff Handley on the WCF RIA Services product team for reviewing the RIA Services chapter on a really tight schedule.
Ashish Shetty on the Silverlight product team for encouraging my Silverlight
blogging very early on, including much of the app model and startup process
content that ended up in this book.
Tom McKearney, Tad Van Fleet, Al Pascual, and Ben Hayat for their excellent
tech reviews. They caught a ton of mistakes, including differences between Silverlight 2, 3, and 4, and changes from the early builds through to the release of
Silverlight 4.
xxi

www.it-ebooks.info
Download from Wow! eBook


xxii

ACKNOWLEDGMENTS





René Schulte for keeping my imaging and pixel shader sections honest and up
to date. René is the go-to guy for working with bitmaps and shaders.
Mike Street on the forums for his helpful and thorough review of many of the
chapters on the forums. Mike was a great unofficial tech reviewer for this book.

In addition, there were numerous editors, proofreaders, and reviewers at Manning
Publications who deserve thanks for their hard work. I dropped on them a book twice
as large as they were expecting with a third of the production time they normally take.
People like Benjamin Berg, Mary Piergies, Nermina Miller, Gordan Salinovic, and others worked tirelessly to get this book published in time. I thank them and the rest of
the folks at Manning for not freaking out when the book missed two deadlines, came
in three months late, and at twice the expected length.
Unique in this thanks is my editor, Jeff Bleiel. This was the first book I’ve written,
so I wasn’t sure what to expect. A good editor can make the difference between a horrible authoring experience and a good one. Jeff definitely made that difference,
respected our different areas of expertise, and kept the book on track. He was my
interface with Manning and my mentor as an author. Jeff made a positive contribution
to this book and to my writing in general.
In addition to the individuals who helped me with the book itself, there are those
who have made it possible through their presence or actions.
Most of all, I’d like to thank my wife Melissa for being a single mom for most
of 2010 and my children Ben and Abby for understanding when mom told them
“Papa’s writing and can’t play right now.” Writing a book this size, for a product that
revs every 10 to 12 months, is an undertaking that involves your whole family.
I’d like to thank my manager at Microsoft, Scott Hanselman, for making sure I had
time to finish the book. This book took an incredible amount of time to write and, if
not for Scott offering me some flexibility, it simply wouldn’t have been completed.
Of course, I thank the Silverlight and WPF community, my Twitter followers, the
Silverlight and WPF insiders, the MVPs, and all the people who’ve read and commented on my blog posts since Silverlight was first released. The community support
for and excitement around these technologies kept me motivated to create the best
book possible.
My gratitude also to my mum for encouraging me in my computer work and for
helping me get that first job writing a database application from scratch in C++. I
wouldn’t be where I am today without her.
I’d like to thank my dad, who passed away during the writing of this book. He
never quite understood what I was doing with the Commodore in my room, typing in
all that hex code from the back of a magazine, but he supported me from the start
and encouraged me to pursue a career doing what I love.
Finally, I’d like to thank you, my readers.

www.it-ebooks.info
Download from Wow! eBook


about this book
The overall goal of this book is to inform and educate you about the exciting and powerful Silverlight 4 platform. Think of it as a guided tour through the Silverlight 4 plugin, runtime libraries, and SDK. After you’ve read this book, you should be able to confidently design, develop, and deliver your first rich interactive applications using Silverlight. To facilitate the learning process, I’ve structured the book to get you
developing as soon as possible, while providing quality, in-depth content.
Within each chapter, I’ve included a collection of devices to help you build a firm
understanding of Silverlight. The following list explains how each agent helps along
the journey:






Figures—Visual depictions that summarize data and help with the connection of
complex concepts.
Listings—Small, concise pieces of code primarily used for showing syntactical
formats. These individual segments generally can’t be run on their own.
Tables—Easy-to-read summaries.

In addition to these learning devices, my personal site http://10rem.net contains links
to the code samples used in this book. Additionally, http://silverlightinaction. com, the
web site for the first edition, includes assets, images, and services used in this book.

Audience
This book is intended for developers who want to create nontrivial applications using
Microsoft Silverlight 4. Though Silverlight provides numerous avenues for interactions

xxiii

www.it-ebooks.info
Download from Wow! eBook


xxiv

ABOUT THIS BOOK

with designers, this book primarily targets people who live and breathe inside Visual Studio. Team members in the integration role (those who take designs and implement in
Silverlight) will also find the information valuable and useful.
This book assumes you have at least a passing familiarity with common web standards such as HTML, CSS, XML, and JavaScript. In addition, this book assumes you
have a background using the .NET framework and Microsoft Visual Studio. Although
we’ll be using C# as the primary development language, we won’t be reviewing the
C# language or explaining basic programming constructs such as classes, methods,
and variables.
Experience with previous versions of Silverlight isn’t required for this book.

The bits: what you need
This book provides ample opportunity for hands-on learning. But, it also provides a
great deal of flexibility by allowing you to learn the material without using the handson content or optional tools. If you want to get the greatest value out of this book and
use the hands-on opportunities, the following tools are recommended:







Visual Studio 2010 Pro or higher, or Visual Studio Web Developer 2010 (free)
Silverlight 4 tools for Visual Studio 2010, including the Silverlight 4 SDK and
WCF RIA Services 1.0
The Silverlight toolkit
Microsoft Expression Blend 4 (optional)
Microsoft Expression Blend 4 SDK for Silverlight 4 (installed with Blend 4) for
creating and using behaviors

You’ll find links to all of these tools at http://silverlight.net/GetStarted.

Roadmap
This book is designed to give you a guided tour of Silverlight 4. This tour will focus on
three main areas: introducing Silverlight, structuring your application, and completing the experience.

Part 1: Introducing Silverlight
Chapter 1 introduces Silverlight. The introduction shows you the advantages of Silverlight and explains its place in the desktop and web applications arenas. The chapter
wraps up with a walkthrough of building your first Silverlight application.
Chapter 2 covers one of the most fundamental parts of Silverlight: XAML. Though
most of the book covers XAML in one form or another, this chapter takes you from the
fundamentals all the way through the visual and logical trees, the dependency property system, and XAML extensions.
Chapter 3 explains how the Silverlight plug-in and application startup process
work. You’ll learn about the application object, the .xap file, and caching assemblies.
We’ll also look at how to instantiate the plug-in and use it on a web page.

www.it-ebooks.info
Download from Wow! eBook


Tài liệu bạn tìm kiếm đã sẵn sàng tải về

Tải bản đầy đủ ngay

×