Home > Store > Programming > ASP .NET

Silverlight 2 Unleashed

Register your product to gain access to bonus material or receive a coupon.

Silverlight 2 Unleashed

Best Value Purchase

Book + eBook Bundle

  • Your Price: $59.39
  • List Price: $98.98
  • Includes EPUB, MOBI, and PDF
  • About eBook Formats
  • This eBook includes the following formats, accessible from your Account page after purchase:

    ePub EPUB The open industry format known for its reflowable content and usability on supported mobile devices.

    MOBI MOBI The eBook format compatible with the Amazon Kindle and Amazon Kindle applications.

    Adobe Reader PDF The popular standard, used most often with the free Adobe® Reader® software.

    This eBook requires no passwords or activation to read. We customize your eBook by discretely watermarking it with your name, making it uniquely yours.

More Purchase Options

Book

  • Your Price: $43.99
  • List Price: $54.99
  • Usually ships in 24 hours.

eBook (Watermarked)

  • Your Price: $35.19
  • List Price: $43.99
  • Includes EPUB, MOBI, and PDF
  • About eBook Formats
  • This eBook includes the following formats, accessible from your Account page after purchase:

    ePub EPUB The open industry format known for its reflowable content and usability on supported mobile devices.

    MOBI MOBI The eBook format compatible with the Amazon Kindle and Amazon Kindle applications.

    Adobe Reader PDF The popular standard, used most often with the free Adobe® Reader® software.

    This eBook requires no passwords or activation to read. We customize your eBook by discretely watermarking it with your name, making it uniquely yours.

Description

  • Copyright 2009
  • Dimensions: 7x9-1/8
  • Pages: 608
  • Edition: 1st
  • Book
  • ISBN-10: 0-672-33014-8
  • ISBN-13: 978-0-672-33014-8

Full Color Code samples appear as they do in Visual Studio and Expression Blend!

Printed entirely in color, with helpful figures and syntax coloring to make code samples appear as they do in Visual Studio and Expression Blend!

Silverlight is Microsoft’s new web-based User Interface (UI) technology, based on Windows Presentation Foundation (WPF), which is introducing many revolutionary concepts in the world of UI development. Silverlight uses XAML, with tools like Expression Design and Expression Blend, to create astonishing UI effects (such as gradients, compositions, and animations.) In addition to the richness of the UI elements, Silverlight 2 allows the use of C# or VB in addition to JavaScript to automate web pages. With Silverlight, you have the power of .NET on multiple platforms (IE and Firefox on Windows, Firefox and Safari on Macintosh, and Firefox on Linux). The author brings you up to speed very quickly with numerous hands-on examples.

  • Use XAML to create state-of-the-art user interfaces
  • Create XAML transforms and animations
  • Design compelling user experiences with Microsoft Expression Blend
  • Integrate media into your rich Internet applications
  • Program Silverlight with both JavaScript and .NET languages
  • Deploy Silverlight content to web pages
  • Encode videos with Expression Media Encoder
  • Make the most of Silverlight elements, resources, and styles
  • Use templates to quickly change your application’s look and feel
  • Efficiently debug Silverlight code
  • Use design tools to create graphics that import seamlessly into Silverlight

Laurent Bugnion has been a software engineer since 1996. He has worked with many programming languages and environments, including C, C++, Java, HTML/CSS/JavaScript, and, since 2002, the Microsoft .NET platform. He has been honored twice as a Microsoft MVP: first for ASP.NET and now for Client Application Development. He blogs about Silverlight and related technologies at http://blog.galasoft.ch.

ON THE WEB:

Download all examples and source code presented in this book from informit.com/title/9780672330148

Category: Microsoft Programming/Web Programming

Covers: Microsoft® Silverlight 2

User Level: Beginning—Intermediate

Downloads

Downloads

Download the book code

Sample Content

Online Sample Chapter

Introducing Silverlight 2

Sample Pages

Download the sample pages

Table of Contents

  

Introduction      1

    About Code in This Book.... 1

    One Year Older..... 2

1     Introducing Silverlight     3

    Where Does Silverlight Come From?... 4

        Automating Web Pages with JavaScript.. 4

        Cascading Style Sheets... 5

        Progressing to DHTML... 6

        Communicating in a Richer Way with AJAX. 7

    Using Third-Party Plug-Ins.... 7

        Using Java Applets.... 7

        Using ActiveX Controls... 8

        Using Flash Applications... 8

    Running on Multiple Platforms... 9

    Making the Web Application Secure... 10

    Introducing Silverlight.net.... 11

    What Do You Need to Run Silverlight?.. 11

    Updating Your Runtime—Automatically.. 12

    Trying Silverlight Demos.... 12

        Playing Chess Against Silverlight.. 13

        Planning Your Trips with the Airline Application. 14

        DeepZooming into the Hard Rock Café.. 15

        Finding More Demos... 15

    What Do You Need to Develop Silverlight?.. 16

        Expression Studio.... 16

        Visual Studio 2008.... 17

    Reading the Documentation... 17

        Browsing the Online Reference.. 18

        Finding More Documentation... 18

        Learning with Tutorials... 18

    Looking into Silverlight’s Future... 19

        Is ASP.NET/HTML/JavaScript Dead?.. 19

    Summary..... 20

2     Understanding XAML     21

    Using XML for Data.... 21

    Using XML for User Interfaces... 23

    Understanding XML Namespaces... 23

    Defining Additional Namespaces... 24

    Creating a Canvas with Children... 25

    Attaching Properties: Canvas.Left and Canvas.Top.. 26

    Documenting Your Markup with XML Comments. 27

    Testing XAML Markup.... 27

        Using SilverlightPad... 27

        Using KaXaml.... 29

    Setting Properties in XAML.... 30

    Changing Brushes.... 32

    Composing Scenes in XAML... 32

    Saving Typing, Saving Space... 34

    Summary..... 35

3     Playing with XAML Transforms and Animations   37

    Transforming Visuals.... 37

    Types of Transforms.... 39

        RotateTransform.... 39

        TranslateTransform.... 40

        ScaleTransform.... 41

        SkewTransform.... 42

        MatrixTransform.... 43

    Composing Transforms.... 44

    Creating a Basic Animation.... 46

    Understanding the Animation’s Elements.. 47

    Adding a Scale Animation.... 49

    Using Other Types of Animations... 50

        Navigating the Property Path... 51

    Deploying the Scene to a Web Page... 52

    Summary..... 52

4     Expression Blend      53

    The Expression Studio in Short... 53

    Installing Expression Blend.... 54

    Starting Expression Blend.... 54

    Setting Options..... 55

    Creating a New Project.... 56

    Understanding the Panels.... 57

    Looking at the Files.... 58

    Executing in the Web Browser... 59

    Working with Shapes.... 59

    Using the Properties Panel.... 60

    Using the Color Picker.... 61

        Creating a LinearGradientBrush... 61

        Changing the Gradient Vector... 62

        Creating a RadialGradientBrush... 63

    Creating a 3D Border Effect Using RadialGradientBrush. 63

    Resetting Properties to Their Default Value.. 64

    Composing the Elements Hierarchy... 64

    Summary..... 65

5     Using Media      67

    Mixing Colors..... 67

        Why FF?..... 68

    Seeing Through the Transparency Channel.. 69

    Seeing Through the Opacity... 71

    Using Vector Graphics.... 72

    Adding Media to Your Scenes... 74

        Laying Out the Application... 74

        Adding Pictures.... 76

        Adding Video.... 76

        Testing the Result Quickly in a Web Browser. 77

        Refining the Layout.... 78

        Adding Yet Another Image... 79

    Controlling Sound and Video... 80

        Switching Auto-Play Off... 80

        Creating an Endless Loop... 80

        Pausing and Playing the Video.. 82

        Setting a “Hand” Cursor... 82

    Checking the Other Properties... 83

        Filling the Space.... 83

        Hiding the Media from Mouse Input.. 83

    Using Media to Write.... 84

        Writing with Video.... 84

        Writing with Images... 85

    Transforming Media.... 86

    Using Web-Based Media.... 86

    Summary..... 87

6     Blending a Little More     89

    Creating Transforms.... 89

    Creating an OpacityMask.... 90

    Using Paths..... 92

        Creating a Path from Scratch... 92

        Using Splines to Modify a Path.. 93

        Combining Shapes... 93

    Clipping Path..... 94

        Paths in XAML.... 95

    Grouping Controls.... 95

        Grouping Elements... 95

        Trying Other Panels... 96

        Scrolling the Thumbnails... 97

    Making a User Control.... 98

        Creating a User Control... 98

        Using the User Control... 100

    Working on the Thumbnails Gallery... 101

        Adding a Display Frame... 101

        Adding a Reflection under the Thumbnails. 102

        Reflecting Video.... 104

        Just One Last Thing... 104

    Summary..... 105

7     Deploying to a Web Page     107

    Creating a Test Page.... 107

    Understanding the object Tag... 109

        Attributes.... 109

        Parameters.... 110

        Modifying the Attributes and Parameters. 111

        Deploying with JavaScript... 114

    Detecting Silverlight.... 114

    Integrating Silverlight in an Existing Web Page.. 115

        Understanding the Original Code.. 116

        Getting the XAP file... 117

        Modifying the Markup... 117

        Testing the Result... 119

        Referencing a XAP on Another Web Server. 119

    Getting Web Space.... 120

        Web Server Requirements... 121

        Finding a Provider.... 121

    Getting Started with FTP.... 122

        Setting Up an FTP Client... 122

        Connecting to Your Server... 123

    Copying Your Silverlight Application... 124

        Testing Your Work... 126

    Summary..... 126

8     Programming Silverlight with JavaScript   129

    Learning the Basics.... 130

        Comments.... 130

        Semicolons.... 130

        Case Sensitivity.... 131

        Variables.... 131

        Functions.... 132

        Prototype, this, new... 132

        Types..... 132

        Built-In Objects and Libraries.. 133

        alert..... 133

        undefined.... 134

        null..... 135

        Handling Events.... 135

    Understanding the Concept of Objects.. 136

        Interfacing with Other Instances.. 137

        Storing Stuff Globally... 137

    Using the Literal Notation JSON... 138

        Creating Objects with JSON... 139

    Static Members..... 140

    Loading Scripts in a Web Page... 141

    Understanding the Context... 142

    Integrating Silverlight in an Existing Web Page Using JavaScript 143

        Finding Silverlight.js... 144

        Using Silverlight.js... 144

        Detecting Silverlight Versions.. 149

        Detecting JavaScript... 150

        Modifying the Web Page During Runtime. 150

    Debugging..... 150

    Summary..... 151

 9     Understanding .NET     153

    History of .NET..... 153

        Versions, Versions, Versions.. 154

        Managed Versus Unmanaged.. 155

    Downloading and Installing Visual Studio 2008. 156

    Creating a Silverlight 2 Application in Visual Studio 2008. 156

        Building and Running the Application.. 157

        Finding Compilation Errors... 158

        Exploring the Files... 158

        Running the (Empty) Application.. 161

    Intellisense..... 162

    Programming C# with Basic Constructs.. 163

        Types..... 163

        Type Conversion.... 165

        if then else.... 166

        for..... 167

        foreach..... 168

        while..... 169

        do…while.... 170

        switch…case.... 170

        Operators.... 171

    Summary..... 174

10     Progressing with .NET     175

    Programming with Objects in C#... 175

        Breaking Your Problem into Smaller Ones. 175

        Namespaces and the using Directive.. 176

        Visibility..... 177

        Properties.... 178

        Inheritance.... 180

    Adding Interactivity to the Thumbnails Application. 181

        Adding Event Handlers in Code.. 181

        Displaying the Expanded Media.. 182

    Overloading Methods.... 185

    Raising Events and Using Delegates.. 186

        Creating an EventArgs... 187

        Declaring the Event... 188

        Subscribing to the Event... 189

    Storing Data on the Client.... 190

        Understanding the Isolated Storage Security Restrictions 190

        Creating Objects.... 190

        Reading from the Isolated Storage.. 195

        Writing to the Isolated Storage.. 195

        Updating the User Interface... 196

        Multibrowser Compatibility... 197

    Summary..... 197

11     Progressing with Animations    199

    Animating Elements in Blend... 199

        Testing the Application... 201

        Editing the Animation’s Properties.. 202

        Easing In and Out.... 203

    Synchronizing Animations.... 204

        Understanding the Animation Elements. 204

    Reversing a Storyboard.... 206

    PointAnimation..... 206

    Starting and Stopping the Animation... 208

    Working on the Thumbnails Gallery... 210

        Making a Scenario... 210

        Setting the Stage.... 210

        Making the Draft Animation... 211

        Easing the Translate Animation.. 212

        Triggering the Animation in Code.. 213

        Creating the “Fading” Animation in Code. 219

    Summary..... 221

12     Encoding Videos with Expression Encoder   223

    Before We Start….... 223

    Introducing Expression Encoder... 224

    Setting Options..... 224

    Understanding the Panels... 225

    Importing a Video.... 226

    Saving your Changes.... 227

    Specifying the Output Type... 227

        Editing the Video Size and Aspect.. 228

        Advanced Processing and Codec Settings. 230

        Adding a Leader and Trailer Video.. 230

    Testing Before Encoding.... 231

    Setting Metadata.... 232

        Adding Your Own Metainformation.. 232

        Creating Chapters... 233

        Creating Captions... 234

    Encoding the Video for Silverlight... 235

    Checking the Result.... 236

        Playing the Video in Full Screen.. 237

    Advanced Parameters.... 237

    Summary..... 238

13     Progressing with Videos     239

    Why Streaming?.... 239

    Publishing on Your Own Website... 240

        Copying the Files.... 240

    Adding an Overlay.... 241

        Adding an Icon or a Video... 242

        Setting Advanced Properties... 242

        Adding an XAML Overlay... 243

    Letting Your Users Choose the Player.. 245

        Copying the Files.... 245

        Modifying the Files... 245

        Creating the Video... 247

        How Does It Work?... 249

    Publishing on Microsoft Silverlight Streaming Servers. 250

        Signing Up.... 250

        Installing, Setting Up the Plug-in, Publishing. 251

        Testing the Output... 251

    Adding the Application in an Existing Web Page. 252

        Using an iframe.... 253

        Using JavaScript and a Live Control.. 254

    Firing Script Commands (and Catching Them).. 254

    Modifying the Player Template in Blend.. 256

        Adding a Full Screen Button... 256

        Handling the Event in Script... 258

        Testing the Result... 259

    Summary..... 259

 14     Letting .NET and JavaScript Talk     261

    Making .NET Available to JavaScript... 261

        Using the ScriptableMember Attribute.. 261

        Registering the Object... 262

    Handling .NET Events in JavaScript... 263

        Preparing the scriptable Class.. 263

        Raising the Event.... 264

        Subscribing to the Event on the JavaScript Side. 265

        Testing the Code.... 267

    Calling JavaScript Methods from .NET.. 267

    Calling .NET Methods from JavaScript.. 269

    Adding a “Login” Dialog to the Thumbnails Application. 270

        Extending the User Object... 270

        Handling Multiple Users... 274

        Modifying the Page Class... 278

        Adding a “Login” Label... 280

        Adding a Web Project... 282

        Checking the Media Files’ Build Action.. 282

        Adding the HTML Login Dialog.. 283

        Blending the Silverlight Application with HTML. 285

        Catching the .NET Event... 285

        Wiring Up the Scripts... 287

        Handling the HTML Events... 288

    Summary..... 289

15     Digging into Silverlight Elements    291

    Exploring the Class Hierarchy... 291

        Exploring the Object... 292

        Exploring the DependencyObject.. 292

        Exploring the UIElement... 292

        Exploring the FrameworkElement.. 293

    Choosing XAML or Code-Behind... 293

    Packing and Laying out with Panels... 296

        Composing Elements... 297

        Discovering the Canvas... 297

        Using a Canvas to Drag an Element.. 298

        Stacking Elements in a StackPanel.. 301

        Using a StackPanel for “Flow Layout”.. 301

        Using a Grid to Align Elements.. 302

        Setting Up a Minimum and Maximum Size. 305

        Adding Elements to a Grid... 305

        Adding Elements to a Grid in Code-Behind. 307

    Scrolling and Bordering.... 307

        Using a ScrollViewer to Scroll Big Areas. 307

        Surrounding an Element with a Border.. 308

    Using Pop-Ups..... 310

    Drawing Shapes.... 311

        The Data Property.... 312

    Summary..... 313

16     Digging Deeper into Silverlight Elements   315

    Understanding the Control Class... 315

        Enabling and Disabling Controls.. 316

        Styling and Templating Controls.. 316

        About Fonts.... 317

    Discovering Basic Controls... 317

        Presenting and Inputting Text.. 317

        Discovering the ButtonBase... 319

        Scrolling and Dragging... 320

        Presenting Media.... 324

    Picking Dates with Calendar and DatePicker.. 325

        Using the Calendar.... 325

        Using the DatePicker... 326

        Catching Errors.... 327

    Writing with Ink..... 327

    Making a Simple Drawing Application.. 328

        Preparing the Scene... 328

        Handling the Events... 330

        Running the Application... 335

    Presenting Data with ItemsControls... 335

        Using the TabControl... 336

    Deep Zooming Your Image Collection.. 337

        How Does It Work?... 337

        Creating a DeepZoom Image Pyramid.. 337

        The MultiScaleImage Control.. 339

    Summary..... 340

17     Using Resources, Styling, and Templating   341

    Storing Items in Collections... 342

        Implementing Interfaces... 342

    Using ResourceDictionaries in Silverlight.. 343

        Storing Resources... 344

        Using Resources in Code-Behind.. 345

        What’s the Point Anyway?... 345

        Using Resources in XAML... 345

        Storing Resources in App.xaml.. 347

    Styling a Control.... 348

        Creating a Style.... 348

        Using a Style.... 349

        Priority of Property Setters... 349

        Creating a Style in Blend... 350

        Editing a Style in Blend... 351

    Styling the Thumbnails Application... 352

        Styling the TextBlocks... 352

        Styling the Thumbnails... 353

        Moving Resources in Blend... 354

    Embedding Fonts in the Application... 354

        Embedding a Font in Blend... 354

        Embedding a Font in Visual Studio.. 356

    Templating the Lookless Control... 356

        But the Control Has a Look!... 357

        Editing the Template... 357

        Modifying the States... 358

        Binding the Template to the Control.. 359

        Presenting Content... 360

    Summary..... 361

18     Data Binding and Using Data Controls    363

    Understanding Data Binding... 363

        Creating a Data Object... 364

        Creating the Data Object in Resources. 365

        Writing to the Data Object with a Binding. 366

        Getting Notified, Finding Binding Errors. 367

        Converting Values in Bindings.. 368

    Digging in the Binding Class... 369

    Setting the DataContext.... 370

    Using Data Controls.... 372

        Using a ListBox.... 372

        Using the DataGrid.... 380

    Using XML Data Sources.... 386

    Summary..... 386

19     Creating User Controls and Custom Controls   387

    Creating a Thumbnails Viewer User Control.. 387

        Creating the Data Objects... 388

        Packing the ThumbnailsViewerControl.. 391

        Communicating with the Outside World. 393

    Creating the Items and Designing a DataTemplate. 397

        Creating the Media Instances in XAML.. 397

        Designing a DataTemplate... 399

        Removing the Test Data Source.. 401

        Moving the Media Files... 401

        Connecting the ThumbnailsViewer to the Real Data 403

        Raising and Handling the SelectionChanged Event 403

    Creating a MediaInfoDisplay Custom Control.. 405

        Making a Blueprint... 405

        Creating the “Shell”... 406

        Handling the States... 410

        Handling the Part.... 411

        Applying the Template... 413

    Summary..... 414

20     Taking Silverlight 2 One Step Further    415

    Creating a Default Template for the MediaInfoDisplay Control 415

    Using the MediaInfoDisplay Control... 417

        Adding Test Data.... 417

        Adding the Control to the Scene.. 418

        Creating a Template... 419

        Making Transitions... 420

        Removing the Test Data... 421

        Wiring Up.... 421

        Digging Deeper.... 422

    Scrolling the Items.... 422

    Creating a New RepeatButton Template.. 425

        Creating the Template... 425

        Changing the Transitions... 426

        Binding the Template... 427

        Testing the New Button... 427

        Styling the RepeatButton... 427

        Styling the Other Button... 428

    Exporting Classes to an External Assembly and Refactoring 429

        Creating a Silverlight Class Library.. 429

        Using an External Class Library.. 432

    Talking About the Application Object... 434

    Using Generics..... 436

    Summary..... 437

21     Taking Silverlight 2 Even Further    439

    Registering Multiple JavaScript Event Handlers. 440

    Finding Silverlight Elements in JavaScript.. 441

    Accessing the HTML Page From .NET.. 443

    Exchanging Data Between .NET and JavaScript. 445

        Attempting Conversion... 446

        Passing Standard Formats... 448

    Converting the ScriptObject Class.. 449

    Passing Initialization Parameters... 453

        Setting Initialization Parameters.. 453

        Retrieving Initialization Parameters.. 453

    Attaching .NET Events to HTML Elements.. 454

        Using the HtmlEventArgs Class.. 456

    Publishing Directly from Visual Studio.. 457

    Debugging Your Silverlight Application.. 458

        Comparing Debug Version and Release Version 458

        Creating the Release Version.. 458

        Stepping Through the Code... 459

        Inspecting and Modifying Variables.. 462

        Debugging in a Web Site Project.. 463

        Debugging JavaScript... 463

        Debugging Running Applications.. 464

        Debugging Silverlight Running on a Macintosh. 465

    Summary..... 465

22     Connecting to the Web     467

    Creating and Loading an XML File... 467

        Removing the Media Information from the Application 467

        Showing and Hiding a Startup Screen.. 468

        Loading the XML Media Information File. 469

        Sending the Request... 471

        Getting a Response... 472

        Reading an XML File with LINQ.. 473

        Parsing Enums.... 476

        Triggering the Request... 477

        Handling the Results... 477

        Testing the Application... 480

    Loading a Zip File and Showing Progress.. 480

        Creating the Zip File... 480

        Extending the MediaEx Class to Store the Stream. 481

        Loading the Zip File... 482

        Reading the Zipped Files... 483

        Updating the UI.... 486

    Making Requests to WCF Services... 488

        Moving the User and DataFile Classes to the Server 488

        Changing the DataFile to Run on the Server. 489

        Creating the WCF Service... 491

        Implementing the Service... 492

        Updating the Client Application.. 494

    More Connectivity.... 497

    Summary..... 498

23     Placing Cross-domain Requests and Handling Exceptions 499

    Placing Cross-domain Requests... 499

        Using the Flash Cross-domain Policy File. 500

        Using the Silverlight Cross-domain Policy File. 501

        Understanding the Restrictions.. 502

    Communicating with Third-Party Services.. 503

        Accepting the Flickr Terms of Services.. 503

        Getting a Flickr API Key... 504

        Preparing and Sending the Request.. 504

        Handling the Response... 508

        Updating the UI.... 514

    Placing POST Requests.... 516

    Throwing and Catching Exceptions... 517

        Bubbling Exceptions... 518

        Understanding an Exception’s Properties. 521

        Catching Unhandled Exceptions.. 522

        Creating Custom Exceptions... 523

        Handling Silverlight Errors in JavaScript. 524

    Summary..... 525

24     Silverlight: Continuing the Journey    527

    Updating a Service Reference... 527

    Killing a Process.... 528

        Killing the Process in Debug Mode.. 530

    About Protecting Your Work... 530

        Protecting Your Work Anyway.. 530

    Binding in Special Configurations... 531

        Setting a Binding in Blend... 531

        Handling Validation Errors... 533

        Binding Through a Converter, ConverterParameter, ConverterCulture 534

        Binding to an Object Rather Than a Property. 535

    Using the ASP.NET Controls Silverlight and MediaPlayer. 536

        Using the Silverlight ASP.NET Control.. 537

        Using the MediaPlayer ASP.NET Control. 538

    Creating Unit Tests for Silverlight... 541

        Installing the Silverlight Unit Test Framework. 541

        Creating a New Silverlight Test Application. 542

        Creating the TryFindResource Extension Method. 544

        Making the Test Pass... 545

        Implementing Recursion... 545

        Learning More About Unit Test.. 548

        Reusing Microsoft Unit Tests.. 549

    Making or Buying XAML Resources... 549

        Using Expression Design... 549

        Finding XAML Resources Online.. 550

        Converting Files to XAML... 551

    Using Third-Party Controls and Libraries.. 552

    Reading Silverlight-Related Blogs... 553

    Summary..... 553

TOC, 0672330148, 10/3/08

More Information

ONE MONTH ACCESS!

WITH PURCHASE


Get unlimited 30-day access to thousands of Books & Training Videos about technology, professional development and digital media If you continue your subscription after your 30-day trial, you can receive 30% off a monthly subscription to the Safari Library for up to 12 months.