Search and Find
Service
Title Page
1
Copyright Page
2
Contents at a Glance
4
Table of Contents
5
About the Author
21
About the Technical Reviewer
22
Acknowledgments
23
Introduction
24
Understanding Silverlight
24
Silverlight System Requirements
26
Silverlight vs. Flash
26
Silverlight and WPF
28
The Evolution of Silverlight
29
About This Book
30
What You Need to Use This Book
31
The Silverlight Toolkit
31
Code Samples
32
Feedback
32
The Last Word
32
Chapter 1: Introducing Silverlight
33
Silverlight Design Tools
33
Visual Studio vs. Expression Blend
33
Understanding Silverlight Websites
34
Creating a Stand-Alone Silverlight Project
35
Creating a Simple Silverlight Page
38
Adding Event-Handling Code
40
Testing a Silverlight Application
42
Creating an ASP.NET-Hosted Silverlight Project
44
ASP.NET Controls That Render Silverlight Content
47
Mixing ASP.NET Controls and Silverlight Content
48
Silverlight Compilation and Deployment
48
Compiling a Silverlight Application
48
Deploying a Silverlight Application
50
Silverlight Core Assemblies
52
Silverlight Add-on Assemblies
53
Assembly Caching
54
The HTML Entry Page
56
Sizing the Silverlight Content Region
58
Silverlight Parameters
58
Alternative Content
60
Creating a Friendly Install Experience
60
The Mark of the Web
62
The Last Word
63
Chapter 2: XAML
64
XAML Basics
65
XAML Namespaces
66
Core Silverlight Namespaces
66
Design Namespaces
67
Custom Namespaces
68
The Code-Behind Class
69
Naming Elements
70
Properties and Events in XAML
70
Simple Properties and Type Converters
72
Complex Properties
73
Attached Properties
75
Nesting Elements
76
Events
79
The Full Eight Ball Example
80
XAML Resources
81
The Resources Collection
81
The Hierarchy of Resources
82
Accessing Resources in Code
84
Organizing Resources with Resource Dictionaries
85
Element-to-Element Binding
87
One-Way Binding
87
Two-Way Binding
88
The Last Word
90
Chapter 3: Layout
91
The Layout Containers
91
The Panel Background
93
Borders
95
Simple Layout with the StackPanel
96
Layout Properties
98
Alignment
99
Margins
100
Minimum, Maximum, and Explicit Sizes
102
The WrapPanel and DockPanel
104
The WrapPanel
104
The DockPanel
105
The Grid
107
Fine-Tuning Rows and Columns
109
Nesting Layout Containers
110
Spanning Rows and Columns
112
The GridSplitter
113
Coordinate-Based Layout with the Canvas
116
Layering with ZIndex
118
Clipping
118
Custom Layout Containers
120
The Two-Step Layout Process
120
MeasureOverride()
121
ArrangeOverride()
122
The UniformGrid
123
Sizing Pages
128
Scrolling with the ScrollViewer
130
Scaling with the Viewbox
132
Full-Screen Mode
134
The Last Word
136
Chapter 4: Dependency Properties and Routed Events
137
Dependency Properties
137
Defining and Registering a Dependency Property
138
Dynamic Value Resolution
140
Attached Properties
141
The WrapBreakPanel Example
142
Routed Events
145
The Core Element Events
145
Event Bubbling
148
Handled (Suppressed) Events
150
An Event Bubbling Example
150
Mouse Handling
153
Right-Clicks
153
Mouse Movements
154
The Mouse Wheel
154
Capturing the Mouse
156
A Mouse Event Example
157
Mouse Cursors
160
Keyboard Handling
161
Key Presses
161
Key Modifiers
164
Focus
165
The Command Model
166
Building a Command
167
Connecting a Command
168
The Last Word
170
Chapter 5: Elements
171
The Silverlight Elements
171
Static Text
175
Font Properties
176
Font Embedding
179
Underlining
180
Runs
181
Wrapping Text
182
Trimming Text
183
Images
183
Image Sizing
184
Image Errors
185
Content Controls
185
The Content Property
187
Aligning Content
189
Buttons
190
The HyperlinkButton
190
The ToggleButton and RepeatButton
191
The CheckBox
191
The RadioButton
192
Tooltips and Pop-Ups
193
Customized Tooltips
193
The Popup
195
Items Controls
197
The ListBox
197
The ComboBox
199
The TabControl
200
Text Controls
201
The TextBox
202
The PasswordBox
204
The AutoCompleteBox
204
Filter Mode
205
Custom Filtering
206
Dynamic Item Lists
208
The RichTextBox
210
Text Elements
210
Formatting Text Elements
213
Manipulating Text Elements in Code
214
Creating a Text Editor
215
Saving and Opening Rich Text Files
218
Using Hyperlinks and Elements in a RichTextBox
219
Range-Based Controls
221
The Slider
221
The ProgressBar
222
Date Controls
222
The Last Word
226
Chapter 6: The Application Model
227
The Application Class
227
Accessing the Current Application
228
Application Properties
228
Application Events
229
Application Startup
230
Initialization Parameters
230
Application Shutdown
234
Unhandled Exceptions
234
Custom Splash Screens
236
Binary Resources
241
Placing Resources in the Application Assembly
241
Programmatically Retrieving a Resource
243
Placing Resources in the Application Package
244
Placing Resources on the Web
245
Failing to Download Resources
246
Downloading Resources with WebClient
247
Class Library Assemblies
249
Using Resources in an Assembly
249
Downloading Assemblies on Demand
250
Supporting Assembly Caching
251
The Strong Key Name
252
The .extmap.xml File
253
The Last Word
255
Chapter 7: Navigation
256
Loading User Controls
257
Embedding User Controls in a Page
257
Hiding Elements
259
Managing the Root Visual
259
Retaining Page State
261
Browser History
262
Child Windows
262
Designing a ChildWindow
264
Showing a ChildWindow
265
The Frame and Page
267
Frames
267
Browser URI Integration
270
What Happens If the Page Has More Than One Frame?
271
What Happens If the Startup Page Doesn’t Include a Frame Control?
271
What About Security?
272
History Support
272
Navigation Failure
273
URI Mapping
274
Forward and Backward Navigation
275
Hyperlinks
276
Pages
277
Navigation Properties
277
State Storage
278
Navigation Methods
279
Navigation Templates
280
Custom Content Loaders
281
Authentication and Navigation
282
Creating a Custom Content Loader
283
Using the Custom Content Loader
285
The Last Word
286
Chapter 8: Shapes and Geometries
287
Basic Shapes
287
The Shape Classes
288
Rectangle and Ellipse
289
Sizing and Placing Shapes
291
Sizing Shapes Proportionately with a Viewbox
293
Line
295
Polyline
296
Polygon
297
Line Caps and Line Joins
300
Dashes
302
Paths and Geometries
304
Line, Rectangle, and Ellipse Geometries
305
Combining Shapes with GeometryGroup
306
Curves and Lines with PathGeometry
308
Straight Lines
309
Arcs
310
Bézier Curves
312
The Geometry Mini-Language
314
Clipping with Geometry
316
Exporting Clip Art
317
Expression Design
317
Conversion
319
Save or Print to XPS
319
The Last Word
322
Chapter 9: Brushes, Transforms, and Bitmaps
323
Brushes
323
The LinearGradientBrush Class
324
The RadialGradientBrush Class
327
The ImageBrush
329
Transparency
330
Opacity Masks
333
Making the Silverlight Control Transparent
334
Transforms
338
Transforming Shapes
340
Transforms and Layout Containers
342
A Reflection Effect
343
Perspective Transforms
345
The PlaneProjection Class
346
Applying a Projection
348
Pixel Shaders
349
BlurEffect
350
DropShadowEffect
350
ShaderEffect
352
The WriteableBitmap Class
353
Generating a Bitmap
353
Capturing Content from Other Elements
356
Printing
357
Printing a Single Element
358
Printing Over Multiple Pages
360
Creating a Print Preview
363
The Last Word
366
Chapter 10: Animation
367
Understanding Silverlight Animation
367
The Rules of Animation
368
Creating Simple Animations
369
The Animation Class
369
The Storyboard Class
370
Starting an Animation with an Event Trigger
371
Starting an Animation with Code
372
Configuring Animation Properties
373
From
373
To
374
By
375
Duration
375
Animation Lifetime
375
RepeatBehavior
377
Simultaneous Animations
377
Controlling Playback
378
Animation Easing
381
Using an Easing Function
381
Easing In and Easing Out
382
Easing Function Classes
384
Animation Types Revisited
387
Animating Transforms
387
Animation Perspective Projections
390
Animating Brushes
392
Animating Pixel Shaders
393
Key-Frame Animation
395
Discrete Key Frames
396
Easing Key Frames
397
Spline Key Frames
397
Animations in Code
399
The Main Page
400
The Bomb User Control
402
Dropping the Bombs
403
Intercepting a Bomb
407
Counting Bombs and Cleaning Up
408
Encapsulating Animations
410
Page Transitions
410
The Base Class
412
The Wipe Transition
413
Frame-Based Animation
415
Animation Performance
419
Desired Frame Rate
419
Hardware Acceleration
420
Enabling Hardware Acceleration
421
Bitmap Caching
421
Evaluating Hardware Acceleration
424
The Last Word
425
Chapter 11: Sound, Video, and Deep Zoom
426
Supported File Types
426
The MediaElement
427
Controlling Playback
428
Handling Errors
429
Playing Multiple Sounds
429
Changing Volume, Balance, and Position
430
Playing Video
434
Client-Side Playlists
435
Server-Side Playlists
435
Progressive Downloading and Streaming
436
Adaptive Streaming
438
Advanced Video Playback
439
Video Encoding
439
Encoding in Expression Encoder
440
Markers
442
Adding Markers with Expression Encoder
442
Using Markers in a Silverlight Application
444
VideoBrush
447
Video Effects
448
Webcam and Microphone Input
454
Accessing a Capture Device
454
Basic Webcam Support
456
Recording Audio Snippets
459
Deep Zoom
463
Creating a Deep Zoom Image Set
465
Using a Deep Zoom Image Set in Silverlight
469
The Last Word
472
Chapter 12: Styles and Behaviors
473
Styles
473
Defining a Style
474
Applying a Style
475
Dynamic Styles
476
Style Inheritance
476
Organizing Styles
478
Automatically Applying Styles by Type
478
Behaviors
480
Getting Support for Behaviors
480
Triggers and Actions
481
Creating an Action
481
Connecting an Action to an Element
483
Design-Time Behavior Support in Blend
485
Creating a Targeted Trigger
487
Creating a Behavior
491
Finding More Behaviors
494
The Last Word
496
Chapter 13: Templates and Custom Controls
497
Template Basics
497
Creating a Template
498
Reusing Control Templates
499
The ContentPresenter
500
Template Bindings
501
Setting Templates Through Styles
502
Reusing Colors
504
The Parts and States Model
504
Understanding States with the Button Control
506
Showing a Focus Cue
510
Transitions
511
The Default Transition
512
From and to Transitions
513
Transitioning to a Steady State
514
Custom Transition
515
Understanding Parts with the Slider Control
516
Creating Templates for Custom Controls
520
Planning the FlipPanel Control
521
Creating the Solution
522
Starting the FlipPanel Class
522
Adding the Default Style with Generic.xaml
524
Choosing Parts and States
526
Starting the Default Control Template
528
The FlipButton Control
529
Defining the State Animations
530
Wiring Up the Elements in the Template
532
Using the FlipPanel
534
Using a Different Control Template
535
The Last Word
537
Chapter 14: Browser Integration
538
Interacting with HTML Elements
539
Getting Browser Information
540
The HTML Window
541
Popup Windows
542
Inspecting the HTML Document
543
Manipulating an HTML Element
545
Inserting and Removing Elements
548
Changing Style Properties
549
Handling JavaScript Events
550
Code Interaction
552
Calling Browser Script from Silverlight
553
Calling Silverlight Methods from the Browser
553
Instantiating Silverlight Objects in the Browser
555
Combining Silverlight and HTML Content
557
Sizing the Silverlight Control to Fit Its Content
557
Placing the Silverlight Control Next to an HTML Element
559
Securing HTML Interoperability
561
The Last Word
563
Chapter 15: ASP.NET Web Services
564
Building Web Services for Silverlight
564
Creating a Web Service
564
Adding a Service Reference
566
Calling the Web Service
568
Configuring the Web Service URL
571
Using a Busy Indicator
572
Web Service Data Types
574
Custom Data Classes
574
Web Service Type Sharing
576
Identifying Your Data Classes
576
Sharing the Code
577
More Advanced Web Services
581
Cross-Domain Web Service Calls
581
Monitoring the Network Connection
583
Using ASP.NET Platform Services
585
Duplex Services
587
Configuring the Service
587
The Interfaces
588
The Service
590
The Client
590
The Last Word
592
Chapter 16: Data Binding
593
Binding to Data Objects
593
Building a Data Object
594
Displaying a Data Object with DataContext
595
Storing a Data Object as a Resource
597
Null Values and Failed Bindings
598
Editing with Two-Way Bindings
598
Change Notification
600
Building a Data Service
601
Calling a Data Service
605
Binding to a Collection of Objects
607
Displaying and Editing Collection Items
607
Inserting and Removing Collection Items
612
Binding to a LINQ Expression
612
Master-Details Display
615
Validation
618
Error Notifications
619
The BindingValidationFailed Event
621
The Validation Class
623
Creating Data Objects with Built-in Validation
623
Data Formatting and Conversion
627
String Formatting
628
Value Converters
630
Formatting Strings with a Value Converter
630
Creating Objects with a Value Converter
633
Applying Conditional Formatting
635
Data Templates
637
Separating and Reusing Templates
639
More Advanced Templates
640
Changing Item Layout
641
The Last Word
642
Chapter 17: Data Controls
643
Better Data Forms
644
The Goal: Data Class Markup
644
The Label
645
The DescriptionViewer
647
The ValidationSummary
649
Data Annotations
651
Raising Annotation Errors
652
The Annotation Attributes
653
Required
654
StringLength
654
Range
654
RegularExpression
655
CustomValidation
657
The DataGrid
659
Creating a Simple Grid
660
How Columns Are Resized and Rearranged
662
Defining Columns
663
The DataGridCheckBoxColumn
665
The DataGridTemplateColumn
665
Formatting and Styling Columns
666
Controlling Column Width
668
Formatting Rows
670
Row Details
673
Freezing Columns
674
Selection
675
Sorting
676
DataGrid Editing
677
Editing with Templates
677
Validation and Editing Events
679
The PagedCollectionView
681
Sorting
682
Filtering
682
Grouping
683
Paging
686
The TreeView
689
Filling a TreeView
689
A Data-Bound TreeView
689
The Last Word
692
Chapter 18: File Access
693
Isolated Storage
694
The Scope of Isolated Storage
694
What to Put in Isolated Storage
695
Using Isolated Storage
695
Opening an Isolated Store
695
File Management
696
Writing and Reading Data
697
Requesting More Space
699
Storing Objects with XmlSerializer
701
Storing Application Settings
704
Accessing Files Outside of Isolated Storage
705
Reading Files with OpenFileDialog
706
Writing Files with SaveFileDialog
708
Transmitting Files with a Web Service
708
The File Service
709
The Silverlight Client
711
Dragging and Dropping Files
714
The Last Word
718
Chapter 19: Multithreading
719
Understanding Multithreading
719
The Goals of Multithreading
720
The DispatcherTimer
721
The Thread Class
721
Marshaling Code to the User Interface Thread
723
Creating a Thread Wrapper
726
Creating the Worker Class
727
Using the Thread Wrapper
729
Cancellation Support
731
The BackgroundWorker
732
Creating the BackgroundWorker
733
Running the BackgroundWorker
734
Tracking Progress
736
Supporting Cancellation
738
The Last Word
740
Chapter 20: Networking
741
Interacting with the Web
742
Cross-Domain Access
742
HTML Scraping
744
REST and Other Simple Web Services
749
Using Network Credentials
753
Processing Different Types of Data
753
XML
753
Services That Return XML Data
754
Navigating Over an XDocument
757
Querying an XDocument with LINQ
759
Services That Require XML Data
761
Services That Return SOAP Data
764
Services That Return JSON Data
764
RSS
767
Sockets
770
Understanding Sockets and TCP
770
The Policy Server
772
The Policy File
773
The PolicyServer Classes
774
The PolicyConnection Classes
776
The Messaging Server
777
The Messenger Client
781
Connecting to the Server
782
Sending Messages
784
Receiving Messages
785
Local Connections
786
Sending a Message
787
Receiving a Message
788
The Last Word
789
Chapter 21: Out-of-Browser Applications
790
Understanding Out-of-Browser Support
791
Creating an Out-of-Browser Application
792
Installing an Out-of-Browser Application
794
Customizing Icons
797
Tracking Application State
798
Removing and Updating an Application
802
Silent Installation
803
Out-of-Browser Application Features
804
The WebBrowser Control
804
Showing HTML Content
806
The WebBrowserBrush
807
Interacting with JavaScript Code
807
Notification Windows
808
Controlling the Main Window
811
Elevated Trust
813
Installing an Elevated Trust Application
814
The Abilities of an Elevated Trust Application
817
Window Customization
818
File Access
825
COM
827
The Last Word
831
Index
832
All prices incl. VAT