Silverlight 4 in Action
Book information
Description
Silverlight 4 in Action is a fast-paced, comprehensive tutorial that guides the reader from creating "Hello World" to coding production-quality, data-driven rich internet applications with graphics, audio, and video content. Written for a developer who already knows how to code in C#, this fluff-free book covers the basics quickly and dives into the heart of Silverlight development using XAML (a markup language for creating user interface elements) and Visual Studio 2010. You'll learn not only how to accomplish tasks, but how the underlying runtime works.In addition to the fundamentals, the book covers the new features in Silverlight like pixel shaders, webcam and microphone, and raw media, as well as WCF RIA Services and patterns like MVVM (Model-View-ViewModel). It explains developing offline and "out-of-browser" applications, managing video and audio, handling validation, navigation and deep-linking, and how each Silverlight feature fits into the overall Silverlight ecosystem.Table of ContentsIntroducing SilverlightCore XAMLThe application model and the plug-inIntegrating with the browserIntegrating with the desktopRendering, layout, and transformingPanelsHuman inputTextControls and UserControlsBindingData controls: DataGrid and DataFormInput validationNetworking and communicationsNavigation and dialogsStructuring and testing with the MVVM/ViewModel patternWCF RIA ServicesGraphics and effectsPrintingDisplaying and capturing media (including webcam/mic)Working with bitmap imagesAnimation and behaviorsResoures, styles, and control templatesCreating panels and controlsThe install experience and preloaders Silverlight 4 in Action......Page 1 brief contents......Page 6 contents......Page 8 preface......Page 20 acknowledgments......Page 22 Audience......Page 24 Part 1: Introducing Silverlight......Page 25 Part 2: Structuring your application......Page 26 Part 3: Completing the experience......Page 27 About the author......Page 28 About the title......Page 29 about the cover illustration......Page 30 Introducing Silverlight......Page 32 Introducing Silverlight......Page 34 1.1 Silverlight and the web......Page 35 1.2 Silverlight and WPF......Page 36 1.4 What’s new since the first edition......Page 37 1.4.2 Media and graphics enhancements......Page 38 1.4.3 User interaction......Page 39 1.5.1 Setting up your development environment......Page 40 1.6 Building your first Silverlight web application......Page 41 1.6.1 Project setup......Page 42 1.6.2 User interface......Page 43 1.6.3 Calling Twitter search......Page 44 1.6.4 Parsing the results and binding the ListBox......Page 45 1.6.5 Making the ListBox contents more meaningful......Page 48 1.7 Summary......Page 50 Core XAML......Page 51 2.1 XAML basics......Page 52 2.1.1 Objects......Page 53 2.1.2 Namespaces......Page 54 2.1.3 Properties......Page 57 2.1.4 Dependency properties......Page 58 2.1.5 Attached properties......Page 60 2.1.6 Events......Page 61 2.1.7 Commands......Page 63 2.1.8 Behaviors......Page 64 2.2 Object trees and namescope......Page 65 2.2.1 Object trees......Page 66 2.2.2 Namescope......Page 68 2.3.1 Markup extensions......Page 69 2.3.2 Type converters......Page 70 2.4 Loading XAML at runtime......Page 73 2.5 Tools for working in XAML......Page 76 2.6 Summary......Page 77 The application model and the plug-in......Page 78 3.1.1 Application startup process......Page 79 3.1.2 XAP......Page 81 3.1.3 The application manifest file......Page 82 3.1.4 The Silverlight application object......Page 83 3.1.6 Assembly caching......Page 86 3.2 Creating the Silverlight plug-in......Page 89 3.2.1 Using the object tag......Page 90 3.2.2 Using the Silverlight.js utility file......Page 91 3.2.3 Creating an instance of the Silverlight plug-in......Page 92 3.3 Integrating the Silverlight plug-in......Page 93 3.3.1 Relating the Silverlight application to the HTML DOM......Page 94 3.3.2 Clarifying the initial experience......Page 95 3.3.3 Handling plug-in events......Page 100 3.3.4 Sending initialization parameters......Page 102 3.4 Summary......Page 103 Integrating with the browser......Page 104 4.1 Silverlight and the HTML DOM......Page 105 4.2.1 Navigating web page contents......Page 107 4.2.2 Working with element properties......Page 108 4.2.3 Handling CSS information......Page 109 4.3 Working with the user’s browser window......Page 110 4.3.1 Prompting the user......Page 111 4.3.2 Navigating the browser window......Page 112 4.4 Bridging the scripting and managed code worlds......Page 113 4.4.1 Calling managed code from JavaScript......Page 114 4.4.2 Using JavaScript from managed code......Page 116 4.5 Hosting HTML in Silverlight......Page 117 4.5.1 Hosting the WebBrowser control......Page 118 4.5.2 Using the WebBrowserBrush......Page 123 4.6 Summary......Page 125 Integrating with the desktop......Page 126 5.1 Silverlight out of the browser......Page 127 5.1.2 The end-user experience......Page 129 5.2.1 The out-of-browser settings file......Page 132 5.2.2 Controlling the experience......Page 133 5.2.4 Checking the network state......Page 137 5.2.5 Alerting the user with Notification toast......Page 139 5.2.6 Implementation specifics......Page 140 5.3.1 Creating elevated-trust applications......Page 141 5.4.1 Accessing special folders......Page 144 5.4.2 Reading from a file......Page 145 5.5.1 Detecting COM automation availability......Page 146 5.5.3 Accessing GPS data using COM automation......Page 148 5.5.4 Automating Excel......Page 150 5.6 Controlling the host window......Page 151 5.6.1 Basic window properties......Page 152 5.6.2 Changing window chrome......Page 153 5.6.3 Minimizing, maximizing, restoring, and closing......Page 154 5.6.4 Moving......Page 155 5.6.5 Resizing......Page 156 5.7.1 Normal full-screen mode......Page 157 5.8 Storing data in isolated storage......Page 159 5.8.1 IsolatedStorageFile: the virtual filesystem......Page 160 5.8.2 Reading and writing files: the isolated storage way......Page 164 5.9 Summary......Page 167 Rendering, layout, and transforming......Page 169 6.1.1 Properties......Page 170 6.1.2 Methods......Page 176 6.2 The rendering process......Page 177 6.2.2 Per-frame rendering callback......Page 179 6.2.3 Rasterization......Page 180 6.3.1 Multipass layout—measuring and arranging......Page 186 6.3.2 The LayoutInformation class......Page 188 6.3.3 Performance considerations......Page 189 6.4 Render transforms......Page 190 6.4.2 ScaleTransform......Page 191 6.4.4 TranslateTransform......Page 192 6.4.5 TransformGroup......Page 193 6.4.6 CompositeTransform......Page 194 6.4.7 MatrixTransform......Page 195 6.5.1 PlaneProjection......Page 197 6.5.2 Matrix3dProjection......Page 199 6.6 Summary......Page 200 Panels......Page 202 7.1 Canvas......Page 203 7.1.1 Arranging content of a Canvas......Page 204 7.2 The StackPanel......Page 207 7.3 The Grid......Page 208 7.3.1 Arranging Grid content......Page 209 7.3.3 Spanning cells......Page 211 7.3.4 Sizing it up......Page 212 7.3.5 Working with the grid programmatically......Page 214 7.3.6 Customizing cell boundaries......Page 215 7.4 Summary......Page 218 Human input......Page 219 8.1.1 Understanding focus......Page 220 8.1.2 Handling keyboard events......Page 221 8.1.3 Dealing with modifier keys......Page 223 8.2.1 Mouse button and movement events......Page 224 8.2.2 Using the mouse wheel......Page 226 8.3 Using multi-touch......Page 228 8.4.2 Collecting ink......Page 230 8.4.3 Styling the ink......Page 232 8.5 Summary......Page 233 Text......Page 234 9.1 The text system......Page 235 9.1.2 Text hinting......Page 236 9.2.1 Font properties......Page 238 9.2.2 Flow control......Page 241 9.2.3 Text properties......Page 242 9.2.4 Spacing......Page 245 9.3 Embedding fonts......Page 247 9.4.1 Handling basic text input......Page 249 9.4.2 Understanding input method editors......Page 251 9.4.3 Copying text with the Clipboard API......Page 253 9.4.4 Collecting sensitive data......Page 255 9.5.1 Formatting and inline elements......Page 256 9.5.2 Working with selected text......Page 260 9.6 Summary......Page 263 Controls and UserControls......Page 265 10.1.1 Appearance......Page 266 10.1.2 Navigation and state......Page 267 10.1.3 Templating......Page 268 10.2 ContentControl......Page 269 10.2.1 The ContentPresenter......Page 270 10.3 Button controls......Page 271 10.3.2 The HyperlinkButton......Page 272 10.3.3 The RadioButton......Page 273 10.3.4 The CheckBox......Page 275 10.4 ItemsControls......Page 276 10.4.1 The ListBox......Page 277 10.4.2 The ComboBox......Page 279 10.4.3 The TabControl......Page 280 10.5 Creating UserControls......Page 283 10.5.1 Defining the appearance......Page 284 10.5.2 Defining the behavior......Page 285 10.5.3 Calling the control......Page 288 10.6 Summary......Page 289 Structuring your application......Page 290 Binding......Page 292 11.1 Binding with your data......Page 293 11.1.1 Mastering the binding syntax......Page 294 11.1.2 Choosing a binding mode......Page 296 11.2.1 Binding to a property......Page 298 11.2.2 Binding to an object......Page 299 11.2.3 Binding to a UI element......Page 301 11.2.4 Binding to an indexed element......Page 303 11.2.5 Binding to a keyed (string indexed) element......Page 304 11.2.6 Binding to an entire collection......Page 305 11.3.1 Formatting values......Page 307 11.3.2 Converting values during binding......Page 308 11.4 Creating data templates......Page 311 11.4.1 Using a DataTemplate with a ContentControl......Page 312 11.4.2 Rendering an ItemsControl with a DataTemplate......Page 313 11.5 Summary......Page 314 Data controls: DataGrid and DataForm......Page 316 12.1.1 Displaying your data......Page 317 12.1.3 Sorting items......Page 323 12.2 The DataForm......Page 324 12.2.1 Displaying your data......Page 325 12.2.2 Binding to lists of data......Page 327 12.2.3 Customizing display......Page 330 12.2.4 Customizing edit, add, and display templates......Page 331 12.2.5 Finer control over editing and committing data......Page 333 12.3.1 The Display attribute......Page 335 12.3.2 The Editable attribute......Page 337 12.4 Summary......Page 338 Input validation......Page 339 13.1 The validation example source and UI......Page 340 13.2.1 Handling exception validation errors......Page 344 13.2.2 Custom validation code......Page 345 13.2.3 Validation error display......Page 346 13.3.1 The IDataErrorInfo interface......Page 347 13.3.2 Simple validation with IDataErrorInfo......Page 348 13.3.3 Cross-field validation with IDataErrorInfo......Page 349 13.3.4 Combining exceptions and IDataErrorInfo......Page 351 13.4.1 The INotifyDataErrorInfo interface......Page 352 13.4.2 Implementing the interface......Page 353 13.4.4 Building the WCF web service......Page 354 13.4.5 Adding the client service code......Page 355 13.4.6 Property modifications......Page 356 13.5.1 Validation attributes......Page 358 13.5.2 Annotating your entity......Page 359 13.5.3 Calling external validation functions......Page 361 13.5.4 Creating custom validators......Page 362 13.6 Comparison of validation approaches......Page 363 13.7 Summary......Page 364 Networking and communications......Page 366 14.1.1 Cross-domain network access......Page 367 14.1.2 Making your application secure......Page 371 14.1.3 Limitations of the browser......Page 372 14.2.1 Using SOAP services......Page 373 14.2.2 RESTful services......Page 382 14.3.1 Manually creating the client stack......Page 386 14.3.3 Automatically setting the HTTP Referer and other headers......Page 387 14.3.4 Authentication credentials......Page 388 14.3.5 Managing cookies with the CookieContainer......Page 390 14.4.1 Reading POX......Page 391 14.4.2 Converting JSON......Page 395 14.5.1 WCF service enhancements......Page 397 14.5.2 WCF duplex services......Page 398 14.5.3 Connecting to sockets......Page 403 14.5.4 Multicast sockets......Page 405 14.6.1 Creating the receiver......Page 408 14.6.2 Creating the sender......Page 409 14.6.3 Putting it all together......Page 410 14.7 Summary......Page 412 Navigation and dialogs......Page 413 15.1 Browser navigation background......Page 414 15.1.2 Anchor hashtags......Page 415 15.1.3 Back and forth......Page 416 15.2.1 Creating a navigation application......Page 417 15.2.2 Adding a new page......Page 419 15.2.3 Changing the application theme......Page 421 15.3.1 The Page class......Page 423 15.3.2 The NavigationService class......Page 424 15.3.3 Frames and URIs......Page 427 15.3.4 Caching pages......Page 430 15.3.5 Navigating to pages in other assemblies......Page 431 15.4.1 Providing custom navigation controls......Page 434 15.5.2 Displaying a dialog box with the ChildWindow control......Page 439 15.5.3 Prompting for a file......Page 443 15.6 Summary......Page 446 Structuring and testing with the MVVM/ViewModel pattern......Page 447 16.1 Project setup and traditional code-behind approach......Page 448 16.1.1 Project and service setup......Page 449 16.1.2 A typical code-behind solution......Page 453 16.2 Model-View-ViewModel basics......Page 456 16.2.1 Keep it simple: a basic ViewModel implementation......Page 458 16.3 Factoring out reusable code......Page 464 16.3.1 Business rules and logic......Page 465 16.3.2 Data access and service calls......Page 467 16.4.1 Using commands......Page 469 16.4.2 Using the CallMethodAction behavior......Page 473 16.4.3 View-specific entities and ViewModels......Page 474 16.4.4 Interfaces, IoC, and ViewModel locators......Page 479 16.5.1 Introduction to the Silverlight Unit Testing Framework......Page 482 16.5.2 Testing the ViewModel......Page 486 16.5.3 Testing asynchronous operations......Page 487 16.6 Summary......Page 488 WCF RIA Services......Page 490 17.1 WCF RIA Services architecture, tooling, and template......Page 492 17.1.2 Creating a project with the template......Page 493 17.2 Exposing data with the domain service......Page 496 17.2.1 Creating the domain service......Page 497 17.2.2 Exposing the domain service to other clients......Page 499 17.2.3 Domain service method types......Page 503 17.2.4 Using a domain service from Silverlight......Page 507 17.3 Filtering, sorting, grouping, and paging......Page 511 17.3.1 Filtering......Page 512 17.3.2 Sorting......Page 515 17.3.3 Grouping......Page 516 17.3.4 Paging......Page 517 17.4 Updating data......Page 519 17.4.1 Using the DataForm UI......Page 520 17.4.2 The domain context......Page 521 17.4.3 The Entity class......Page 523 17.4.4 Using validation and display metadata......Page 525 17.5 Loose coupling: using presentation models......Page 527 17.5.1 Creating the employee presentation model......Page 528 17.5.2 Supporting query operations......Page 529 17.5.3 Supporting update operations......Page 531 17.5.4 Supporting insert operations......Page 533 17.6 Business logic......Page 534 17.6.1 Business logic in entities......Page 535 17.6.2 Sharing code......Page 536 17.7.1 Authentication......Page 537 17.7.2 Authorization......Page 540 17.8 Summary......Page 541 Completing the experience......Page 544 Graphics and effects......Page 546 18.1 Shapes......Page 547 18.1.2 Rectangle......Page 548 18.1.3 Ellipse......Page 549 18.1.5 Polygon......Page 550 18.2 Geometry......Page 551 18.2.1 Simple geometries......Page 552 18.2.2 Path geometries......Page 553 18.2.3 Composite geometries......Page 554 18.3 Brushes......Page 555 18.3.1 SolidColorBrush......Page 556 18.3.2 LinearGradientBrush......Page 557 18.3.3 RadialGradientBrush......Page 559 18.3.4 ImageBrush......Page 560 18.3.5 VideoBrush......Page 561 18.4 Effects......Page 562 18.4.1 Using built-in effects......Page 563 18.4.2 Creating custom pixel shaders......Page 566 18.5 Summary......Page 571 Printing......Page 573 19.1 How Silverlight printing works......Page 574 19.1.1 The PrintDocument class......Page 575 19.1.2 The PrintPage Event......Page 578 19.1.3 Rasterization......Page 580 19.2.1 Printing the content as is......Page 581 19.2.2 Rerooting the elements to fit......Page 583 19.2.3 Scaling content to fit......Page 585 19.3 Multipage printing dedicated trees......Page 587 19.3.1 Prerequisites......Page 588 19.3.2 Printing line items......Page 591 19.3.3 Adding multipage support......Page 597 19.3.4 Adding a header and footer......Page 598 19.4 Summary......Page 601 Displaying and capturing media......Page 603 20.1.1 Media source......Page 604 20.1.2 Common properties......Page 610 20.1.3 Audio specific properties......Page 612 20.1.4 Video specific properties......Page 613 20.1.5 The lifecycle of a media file......Page 614 20.2 Playlists......Page 615 20.2.1 Understanding client-side playlists......Page 616 20.2.2 Using server-side playlists......Page 618 20.3 Interactive playback......Page 619 20.3.2 Working with the timeline......Page 620 20.4.1 Requesting protected content......Page 622 20.4.3 Unlocking protected content......Page 623 20.5.1 Using the player libraries......Page 624 20.5.2 Creating the player......Page 625 20.6.1 A custom MediaStreamSource class......Page 627 20.6.2 Creating raw video......Page 629 20.6.3 Creating raw audio......Page 633 20.7.1 Gaining access to capture devices......Page 638 20.7.2 Working with video......Page 640 20.7.3 Capturing still images......Page 643 20.7.4 Getting the raw video data......Page 645 20.7.5 A note about audio......Page 647 20.8 Summary......Page 648 Working with bitmap images......Page 649 21.1 Basic imaging......Page 650 21.2 Creating images at runtime......Page 651 21.2.1 Creating from existing images......Page 652 21.2.2 Creating from UI elements......Page 654 21.2.3 A Mandelbrot fractal generator......Page 655 21.3.1 Showing an image......Page 658 21.3.2 Zooming in and out......Page 659 21.3.3 Managing the viewport......Page 661 21.3.4 Deploying multiscale images......Page 662 21.4 Dealing with dead space......Page 663 21.4.2 Uniform sizing......Page 664 21.4.3 Fill the area......Page 665 21.4.4 UniformToFill......Page 666 21.5 Summary......Page 667 Animation and behaviors......Page 668 22.1 Animation: it’s about time......Page 669 22.2.1 What type of property are you animating?......Page 670 22.2.2 Where are you starting from and where are you going?......Page 673 22.2.3 How long should the animation run?......Page 675 22.3.1 Understanding the storyboard......Page 678 22.3.2 Hitting the target......Page 679 22.3.3 Controlling the Storyboard......Page 681 22.3.4 Being resourceful......Page 683 22.4 Keyframing......Page 685 22.4.1 Interpolation: it’s about acceleration......Page 687 22.5 Easing functions......Page 691 22.5.1 Using easing functions......Page 692 22.5.2 Creating a custom easing function......Page 694 22.6 Behaviors, triggers, and actions......Page 696 22.6.1 Using existing behaviors......Page 697 22.6.2 Creating your own behavior......Page 698 22.7 Summary......Page 700 Resources, styles, and control templates......Page 701 23.1.1 Declarative resources......Page 702 23.1.2 Accessing loose resources......Page 708 23.1.3 Bundled resources......Page 709 23.2 Giving your elements style......Page 711 23.2.1 Defining the look......Page 712 23.2.2 Explicitly keyed style definitions......Page 714 23.2.3 Implicit style definitions......Page 716 23.3.1 Building a control template......Page 717 23.3.2 Creating reusable templates......Page 721 23.4.1 Understanding the components......Page 722 23.4.2 Leveraging the VisualStateManager......Page 724 23.6 Summary......Page 728 Creating panels and controls......Page 730 24.1 Creating a custom panel......Page 731 24.1.2 The OrbitPanel class......Page 732 24.1.3 Properties......Page 733 24.1.4 Custom layout......Page 736 24.1.5 Enhancements......Page 740 24.2 Creating a custom control......Page 741 24.2.1 Choosing the base type......Page 742 24.2.3 The control template contract......Page 743 24.2.4 The default template......Page 745 24.2.5 Visual states......Page 746 24.2.6 Visual states in template......Page 747 24.3 Summary......Page 749 The install experience and preloaders......Page 751 25.1 Handling the “Silverlight not installed” scenarios......Page 752 25.1.1 Creating your own install experience......Page 753 25.2.1 Creating the appearance......Page 755 25.2.2 Integrating the custom splash screen......Page 757 25.2.3 Monitoring the load progress......Page 758 25.3 Summary......Page 759 A.1 Install the AdventureWorks database......Page 760 A.1.2 Installing on SQL Server Express......Page 761 A.2 Database connection and entities......Page 762 A.2.1 Choosing the entities to create......Page 764 A......Page 766 B......Page 768 C......Page 769 D......Page 772 E......Page 774 F......Page 776 G......Page 777 I......Page 778 L......Page 780 M......Page 781 N......Page 783 O......Page 784 P......Page 785 R......Page 788 S......Page 790 T......Page 793 V......Page 795 W......Page 796 Z......Page 797 Back cover......Page 798
Similar books
Windows Store App Development: C# and XAML
2013 · EPUB
Three Sheets to the Wind: One Man's Quest for the Meaning of Beer
2011 · EPUB
Clubland: How the Working Men’s Club Shaped Britain
2022 · EPUB
Windows Store App Development: C# and XAML
2013 · PDF
Pie Fidelity: In Defence of British Food
EPUB
The Pub: A Cultural Institution — From Country Inns to Craft Beer Bars and Corner Locals
2016 · EPUB
Silverlight 4 in Action: Silverlight 4, ViewModel Pattern, and WCF RIA Services
2010 · PDF
Silverlight 5 in Action
2012 · PDF