pro silverlight 4 in c# - Pdf 20

MacDonald
Companion
eBook Available
this print for content only—size & color not accurate
  CYAN
  MAGENTA
  YELLOW
  BLACK
  PANTONE 123 C
BOOKS FOR PROFESSIONALS BY PROFESSIONALS
®
Pro Silverlight 4 in C#
Dear Reader,
Silverlight is a revolutionary browser plug-in that allows developers to create
rich client applications that run inside the browser. Like Adobe Flash, Silverlight
supports event handling, two-dimensional drawing, video playback, network-
ing, and animation. Unlike Flash, Silverlight is tailored to .NET developers and
supports pure C# code.
The most exciting part of Silverlight is its cross-platform muscle. Unlike
ordinary .NET applications, Silverlight applications run seamlessly in non-
Microsoft browsers (like Firefox, Safari, and Chrome) and on non-Microsoft
platforms (like Mac OS X). Essentially, Silverlight is a scaled-down, browser-
hosted version of .NET—and that’s made it the most hotly anticipated technol-
ogy that Microsoft has released in years.
In this book, you’ll master Silverlight from the ground up. No Silverlight
experience is required—but if you’ve worked with Silverlight 3, you’ll appreci-
ate the “What’s New” boxes that point out new features at the start of every
chapter. By the end of this book, you’ll have a solid understanding of the com-
plete Silverlight platform, and you’ll be able to build anything from a slick busi-
ness front-end to a browser-based game.
Welcome aboard!

Beginning
Silverlight 4 in C#
www.apress.com
SOURCE CODE ONLINE
Companion eBook

See last page for details
on $10 eBook version
ISBN 978-1-4302-2979-7
9 781430 229797
5 49 9 9
Silverlight 4 in C#
Full Color Inside
Pro
7 x 9.125 spine = 2.09375" 912 page count
THE EXPERT’S VOICE
®
 IN SILVERLIGHT
Pro
Silverlight 4
in C#
Matthew MacDonald
Create cross-platform .NET applications for the browser
Full Color Inside
www.it-ebooks.info
www.it-ebooks.info


Trademarked names, logos, and images may appear in this book. Rather than use a trademark
symbol with every occurrence of a trademarked name, logo, or image we use the names, logos,
and images only in an editorial fashion and to the benefit of the trademark owner, with no
intention of infringement of the trademark.
The use in this publication of trade names, trademarks, service marks, and similar terms, even if
they are not identified as such, is not to be taken as an expression of opinion as to whether or
not they are subject to proprietary rights.
President and Publisher: Paul Manning
Lead Editor: Ewan Buckingham
Technical Reviewer: Fabio Claudio Ferracchiati
Editorial Board: Clay Andres, Steve Anglin, Mark Beckner, Ewan Buckingham, Gary Cornell,
Jonathan Gennick, Jonathan Hassell, Michelle Lowman, Matthew Moodie, Duncan
Parkes, Jeffrey Pepper, Frank Pohlmann, Douglas Pundick, Ben Renow-Clarke, Dominic
Shakeshaft, Matt Wade, Tom Welsh
Coordinating Editors: Anne Collett and Debra Kelly
Copy Editor: Kim Wimpsett
Compositor: Mary Sudul
Indexer: BIM Indexing & Proofreading Services
Artist: April Milne
Cover Designer: Anna Ishchenko
Distributed to the book trade worldwide by Springer Science+Business Media, LLC., 233 Spring
Street, 6th Floor, New York, NY 10013. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail
, or visit www.springeronline.com.
For information on translations, please e-mail , or visit www.apress.com.
Apress and friends of ED books may be purchased in bulk for academic, corporate, or
promotional use. eBook versions and licenses are also available for most titles. For more
information, reference our Special Bulk Sales–eBook Licensing web page at
www.apress.com/info/bulksales.
The information in this book is distributed on an “as is” basis, without warranty. Although every
precaution has been taken in the preparation of this work, neither the author(s) nor Apress shall

■ Chapter 16: Data Binding 569
■ Chapter 17: Data Controls 619
■ Chapter 18: File Access 669
■ Chapter 19: Multithreading 695
■ Chapter 20: Networking 717
■ Chapter 21: Out-of-Browser Applications 767
■ Index 809

www.it-ebooks.info
■ CONTENTS

vi
Contents
■ Contents at a Glance v
■ About the Author xxii
■ About the Technical Reviewer xxiii
■ Acknowledgments xxiv
■ Introduction xxv
■ Chapter 1: Introducing Silverlight 1
Silverlight Design Tools 1

Visual Studio vs. Expression Blend 1
Understanding Silverlight Websites 2
Creating a Stand-Alone Silverlight Project 3

Creating a Simple Silverlight Page 6
Adding Event-Handling Code 8
Testing a Silverlight Application 10
Creating an ASP.NET-Hosted Silverlight Project 12
ASP.NET Controls That Render Silverlight Content 15

The Resources Collection 50
The Hierarchy of Resources 51
Accessing Resources in Code 53
Organizing Resources with Resource Dictionaries 54
Element-to-Element Binding 56
One-Way Binding 56
Two-Way Binding 57
The Last Word 59
■ Chapter 3: Layout 61
The Layout Containers 61

The Panel Background 63
Borders 65
Simple Layout with the StackPanel 66
Layout Properties 68
Alignment 69
Margins 70
Minimum, Maximum, and Explicit Sizes 72
The WrapPanel and DockPanel 74
The WrapPanel 74
The DockPanel 75
www.it-ebooks.info
■ CONTENTS

viii
The Grid 77
Fine-Tuning Rows and Columns 79
Nesting Layout Containers 80
Spanning Rows and Columns 82
The GridSplitter 83

www.it-ebooks.info
■ CONTENTS
ix
Keyboard Handling 131
Key Presses 131
Key Modifiers 134
Focus 135
The Command Model 136
Building a Command 137
Connecting a Command 138
The Last Word 140
■ Chapter 5: Elements 141
The Silverlight Elements 141

Static Text 145
Font Properties 146
Underlining 150
Runs 151
Wrapping Text 152
Trimming Text 153
Images 153
Image Sizing 154
Image Errors 155
Content Controls 155
The Content Property 157
Aligning Content 159
Buttons 160
The HyperlinkButton 160
The ToggleButton and RepeatButton 161
The CheckBox 161

Custom Splash Screens 206
Binary Resources. 211
Placing Resources in the Application Assembly. 211
Placing Resources in the Application Package . 214
Placing Resources on the Web 215
Class Library Assemblies . 219
Using Resources in an Assembly 219
Downloading Assemblies on Demand 220
Supporting Assembly Caching 221
The Last Word . 225
■ Chapter 7: Navigation . 227
Loading User Controls 228
Embedding User Controls in a Page 228
Hiding Elements. 230
Managing the Root Visual 230
www.it-ebooks.info
■ CONTENTS
xi
Retaining Page State 232
Browser History 233
Child Windows 233
Designing a ChildWindow 235
Showing a ChildWindow 236
The Frame and Page 238
Frames 238
URI Mapping 245
Forward and Backward Navigation 246
Hyperlinks 247
Pages 248
Navigation Templates 251

Save or Print to XPS 291
The Last Word 294
■ Chapter 9: Brushes, Transforms, and Bitmaps 295
Brushes 295

The LinearGradientBrush Class 296
The RadialGradientBrush Class 299
The ImageBrush 301
Transparency 302
Opacity Masks 305
Making the Silverlight Control Transparent 306
Transforms 310
Transforming Shapes 312
Transforms and Layout Containers 314
A Reflection Effect 315
Perspective Transforms 317
The PlaneProjection Class 318
Applying a Projection 320
Pixel Shaders 321
BlurEffect 322
DropShadowEffect 322
ShaderEffect 324
The WriteableBitmap Class 325
Generating a Bitmap 325
Capturing Content from Other Elements 328
Printing 329
Printing a Single Element 330
Printing Over Multiple Pages 332
Creating a Print Preview 335
The Last Word 338

Intercepting a Bomb 379
Counting Bombs and Cleaning Up 380
Encapsulating Animations 382
Page Transitions 382
The Base Class 384
The Wipe Transition 385
Frame-Based Animation 387
www.it-ebooks.info
■ CONTENTS

xiv
Animation Performance 391
Desired Frame Rate 391
Hardware Acceleration 392
The Last Word 397
■ Chapter 11: Sound, Video, and Deep Zoom 399
Supported File Types 399

The MediaElement 400
Controlling Playback 401
Handling Errors 402
Playing Multiple Sounds 402
Changing Volume, Balance, and Position 403
Playing Video 407
Client-Side Playlists 408
Server-Side Playlists 408
Progressive Downloading and Streaming 409
Adaptive Streaming 411
Advanced Video Playback 412
Video Encoding 412

■ Chapter 13: Templates and Custom Controls 471
Template Basics 471

Creating a Template 472
Reusing Control Templates 473
The ContentPresenter 474
Template Bindings 475
Setting Templates Through Styles 476
Reusing Colors 478
The Parts and States Model 478
Understanding States with the Button Control 480
Showing a Focus Cue 484
Transitions 485
Understanding Parts with the Slider Control 490
Creating Templates for Custom Controls 494
Planning the FlipPanel Control 495
Creating the Solution 496
Starting the FlipPanel Class 496
Adding the Default Style with Generic.xaml 498
Choosing Parts and States 500
Starting the Default Control Template 502
The FlipButton Control 503
Defining the State Animations 504
Wiring Up the Elements in the Template 506
Using the FlipPanel 508
www.it-ebooks.info
■ CONTENTS

xvi
Using a Different Control Template 509

More Advanced Web Services 556
Cross-Domain Web Service Calls 556
Monitoring the Network Connection 558
Using ASP.NET Platform Services 560
www.it-ebooks.info
■ CONTENTS
xvii
Duplex Services 562
Configuring the Service 562
The Interfaces 563
The Service 565
The Client 565
The Last Word 567
■ Chapter 16: Data Binding 569
Binding to Data Objects 569

Building a Data Object 570
Displaying a Data Object with DataContext 571
Storing a Data Object as a Resource 573
Null Values and Failed Bindings 574
Editing with Two-Way Bindings 574
Change Notification 576
Building a Data Service 577
Calling a Data Service 581
Binding to a Collection of Objects 583
Displaying and Editing Collection Items 583
Inserting and Removing Collection Items 588
Binding to a LINQ Expression 588
Master-Details Display 591
Validation 594

How Columns Are Resized and Rearranged 638
Defining Columns 639
Formatting and Styling Columns 642
Controlling Column Width 644
Formatting Rows 646
Row Details 649
Freezing Columns 650
Selection 651
Sorting 652
DataGrid Editing 653
Editing with Templates 653
Validation and Editing Events 655
The PagedCollectionView 657
Sorting 658
Filtering 658
Grouping 659
Paging 662
The TreeView 665
Filling a TreeView 665
A Data-Bound TreeView 665
The Last Word 668
www.it-ebooks.info
■ CONTENTS
xix
■ Chapter 18: File Access 669
Isolated Storage 670

The Scope of Isolated Storage 670
What to Put in Isolated Storage 671
Using Isolated Storage 671

■ CONTENTS
xx
■ Chapter 20: Networking 717
Interacting with the Web 718
Cross-Domain Access. 718
HTML Scraping . 720
REST and Other Simple Web Services 725
Using Network Credentials 729
Processing Different Types of Data 729
XML . 729
Services That Return XML Data 730
Services That Require XML Data 737
Services That Return SOAP Data 740
Services That Return JSON Data 740
RSS. 743
Sockets . 746
Understanding Sockets and TCP 746
The Policy Server. 748
The Messaging Server 753
The Messenger Client . 757
Local Connections . 762
Sending a Message. 763
Receiving a Message . 764
The Last Word . 765
■ Chapter 21: Out-of-Browser Applications 767
Understanding Out-of-Browser Support 768
Creating an Out-of-Browser Application 769
Installing an Out-of-Browser Application 771
Customizing Icons . 774
Tracking Application State 775

www.it-ebooks.info
■ CONTENTS
xxiii
About the Technical Reviewer
■ Fabio Claudio Ferracchiati is a prolific writer on cutting-edge technologies. Fabio has
contributed to more than a dozen books on .NET, C#, Visual Basic, and ASP.NET. He is a .NET
Microsoft Certified Solution Developer (MCSD) and lives in Rome, Italy.

www.it-ebooks.info


Nhờ tải bản gốc

Tài liệu, ebook tham khảo khác

Music ♫

Copyright: Tài liệu đại học © DMCA.com Protection Status