Pro Wpf 4.5 in C#: Windows Presentation Foundation in .Net 4.5

This document was uploaded by one of our users. The uploader already confirmed that they had the permission to publish it. If you are author/publisher or own the copyright of this documents, please report to us by using this DMCA report form.

Simply click on the Download Book button.

Yes, Book downloads on Ebookily are 100% Free.

Sometimes the book is free on Amazon As well, so go ahead and hit "Search on Amazon"

Microsoft's Windows Presentation Foundation (WPF) provides you with a development framework for building high-quality user experiences for the Windows operating system. It blends together rich content from a wide range of sources and allows you unparalleled access to the processing power of your Windows computer.

Pro WPF 4.5 in C# provides a thorough, authoritative guide to how WPF really works. Packed with no-nonsense examples and practical advice you'll learn everything you need to know in order to use WPF in a professional setting. The book begins by building a firm foundation of elementary concepts, using your existing C# skills as a frame of reference, before moving on to discuss advanced concepts and demonstrate them in a hands-on way that emphasizes the time and effort savings that can be gained.

Author(s): Matthew MacDonald
Edition: 4
Publisher: Apress
Year: 2012

Language: English
Pages: 1078
Tags: microsoft, programming, development

Cover
Contents at a Glance
Contents
About the Author
About the Technical Reviewer
Acknowledgments
Introduction
About This Book
Chapter Overview
What You Need to Use This Book
Code Samples and URLs
Feedback
Part I: Fundamentals
Chapter 1: Introducing WPF
The Evolution of Windows Graphics
DirectX: The New Graphics Engine
Hardware Acceleration and WPF
WPF: A Higher-Level API
Resolution Independence
WPF Units
System DPI
Bitmap and Vector Graphics
The Architecture of WPF
The Class Hierarchy
WPF 4.5
The WPF Toolkit
Visual Studio 2012
The Last Word
Chapter 2: XAML
Understanding XAML
Graphical User Interfaces Before WPF
The Variants of XAML
XAML Compilation
XAML Basics
XAML Namespaces
The Code-Behind Class
Properties and Events in XAML
Simple Properties and Type Converters
Complex Properties
Markup Extensions
Attached Properties
Nesting Elements
Special Characters and Whitespace
Events
The Full Eight-Ball Example
Using Types from Other Namespaces
Loading and Compiling XAML
Code-Only
Code and Uncompiled XAML
Code and Compiled XAML
XAML Only
The Last Word
Chapter 3: Layout
Understanding Layout in WPF
The WPF Layout Philosophy
The Layout Process
The Layout Containers
Simple Layout with the StackPanel
Layout Properties
Alignment
Margin
Minimum, Maximum, and Explicit Sizes
The Border
The WrapPanel and DockPanel
The WrapPanel
The DockPanel
Nesting Layout Containers
The Grid
Fine-Tuning Rows and Columns
Layout Rounding
Spanning Rows and Columns
Splitting Windows
Shared Size Groups
The UniformGrid
Coordinate-Based Layout with the Canvas
Z-Order
The InkCanvas
Layout Examples
A Column of Settings
Dynamic Content
A Modular User Interface
The Last Word
Chapter 4: Dependency Properties
Understanding Dependency Properties
Defining a Dependency Property
Registering a Dependency Property
Adding a Property Wrapper
How WPF Uses Dependency Properties
Shared Dependency Properties
Attached Dependency Properties
Property Validation
The Validation Callback
The Coercion Callback
The Last Word
Chapter 5:Routed Events
Understanding Routed Events
Defining, Registering, and Wrapping a Routed Event
Sharing Routed Events
Raising a Routed Event
Handling a Routed Event
Event Routing
The RoutedEventArgs Class
Bubbling Events
Handling a Suppressed Event
Attached Events
Tunneling Events
WPF Events
Lifetime Events
Input Events
Keyboard Input
Handling a Key Press
Focus
Getting Key State
Mouse Input
Mouse Clicks
Capturing the Mouse
Drag-and-Drop
Multitouch Input
The Levels of Multitouch Support
Raw Touch
Manipulation
Inertia
The Last Word
Part II: Deeper Into WPF
Chapter 6: Controls
The Control Class
Background and Foreground Brushes
Fonts
Mouse Cursors
Content Controls
The Content Property
Aligning Content
The WPF Content Philosophy
Labels
Buttons
Tooltips
Specialized Containers
The ScrollViewer
The GroupBox
The TabItem
The Expander
Text Controls
Multiple Lines of Text
Text Selection
Spell Checking
The PasswordBox
List Controls
The ListBox
The ComboBox
Range-Based Controls
The Slider
The ProgressBar
Date Controls
The Last Word
Chapter 7: The Application
The Application Life Cycle
Creating an Application Object
Deriving a Custom Application Class
Application Shutdown
Application Events
Application Tasks
Showing a Splash Screen
Handling Command-Line Arguments
Accessing the Current Application
Interacting Between Windows
Single-Instance Applications
Assembly Resources
Adding Resources
Retrieving Resources
Resource-Aware Classes
Pack URIs
Resources in Other Assemblies
Content Files
Localization
Building Localizable User Interfaces
Preparing an Application for Localization
Managing the Translation Process
The Last Word
Chapter 8: Element Binding
Binding Elements Together
The Binding Expression
Binding Errors
Binding Modes
Creating Bindings with Code
Retrieving Bindings in Code
Multiple Bindings
Binding Updates
Binding Delays
Binding to Objects That Aren’t Elements
Source
RelativeSource
DataContext
The Last Word
Chapter 9: Commands
Understanding Commands
The WPF Command Model
The ICommand Interface
The RoutedCommand Class
The RoutedUICommand Class
The Command Library
Executing Commands
Command Sources
Command Bindings
Using Multiple Command Sources
Fine-Tuning Command Text
Invoking a Command Directly
Disabling Commands
Controls with Built-in Commands
Advanced Commands
Custom Commands
Using the Same Command in Different Places
Using a Command Parameter
Tracking and Reversing Commands
The Last Word
Chapter 10: Resources
Resource Basics
The Resources Collection
The Hierarchy of Resources
Static and Dynamic Resources
Nonshared Resources
Accessing Resources in Code
Application Resources
System Resources
Resource Dictionaries
Creating a Resource Dictionary
Using a Resource Dictionary
Sharing Resources Between Assemblies
The Last Word
Chapter 11: Styles and Behaviors
Style Basics
Creating a Style Object
Setting Properties
Attaching Event Handlers
The Many Layers of Styles
Automatically Applying Styles by Type
Triggers
A Simple Trigger
An Event Trigger
Behaviors
Getting Support for Behaviors
Understanding the Behavior Model
Creating a Behavior
Using a Behavior
Design-Time Behavior Support in Blend
The Last Word
Part III: Drawing and Animation
Chapter 12: Shapes, Brushes, and Transforms
Understanding Shapes
The Shape Classes
Rectangle and Ellipse
Sizing and Placing Shapes
Scaling Shapes with a Viewbox
Line
Polyline
Polygon
Line Caps and Line Joins
Dashes
Pixel Snapping
Using Brushes
The SolidColorBrush
The LinearGradientBrush
The RadialGradientBrush
The ImageBrush
A Tiled ImageBrush
The VisualBrush
The BitmapCacheBrush
Using Transforms
Transforming Shapes
Transforming Elements
Transparency
Making an Element Partially Transparent
Using Opacity Masks
The Last Word
Chapter 13: Geometries and Drawings
Paths and Geometries
Line, Rectangle, and Ellipse Geometries
Combining Shapes with GeometryGroup
Fusing Geometries with CombinedGeometry
Drawing Curves and Lines with PathGeometry
Using the Geometry Mini-Language
Clipping with Geometry
Drawings
Displaying a Drawing
Exporting Clip Art
The Last Word
Chapter 14: Effects and Visuals
Visuals
Drawing Visuals
Wrapping Visuals in an Element
Hit Testing
Complex Hit Testing
Effects
BlurEffect
DropShadowEffect
ShaderEffect
The WriteableBitmap Class
Generating a Bitmap
Writing to a WriteableBitmap
Using More-Efficient Pixel Writing
The Last Word
Chapter 15: Animation Basics
Understanding WPF Animation
Timer-Based Animation
Property-Based Animation
Basic Animation
The Animation Classes
Animations in Code
Simultaneous Animations
Animation Lifetime
The Timeline Class
Storyboards
The Storyboard
Event Triggers
Overlapping Animations
Synchronized Animations
Controlling Playback
Monitoring Progress
Animation Easing
Using an Easing Function
Easing In and Easing Out
Easing Function Classes
Creating a Custom Easing Function
Animation Performance
Desired Frame Rate
Bitmap Caching
The Last Word
Chapter 16: Advanced Animation
Animation Types Revisited
Animating Transforms
Animating Brushes
Animating Pixel Shaders
Key-Frame Animation
Discrete Key-Frame Animations
Easing Key Frames
Spline Key-Frame Animations
Path-Based Animation
Frame-Based Animation
Storyboards in Code
Creating the Main Window
Creating the Bomb User Control
Dropping the Bombs
Intercepting a Bomb
Counting Bombs and Cleaning Up
The Last Word
Part IV: Templates and Custom elements
Chapter 17: Control Templates
Understanding Logical Trees and Visual Trees
Understanding Templates
The Chrome Classes
Dissecting Controls
Creating Control Templates
A Simple Button
Template Bindings
Triggers That Change Properties
Triggers That Use Animation
Organizing Template Resources
Refactoring the Button Control Template
Applying Templates with Styles
Applying Templates Automatically
Working with User-Selected Skins
Building More Complex Templates
Nested Templates
Modifying the Scrollbar
Exploring the Control Template Examples
Visual States
The Last Word
Chapter 18: Custom Elements
Understanding Custom Elements in WPF
Building a Basic User Control
Defining Dependency Properties
Defining Routed Events
Adding Markup
Using the Control
Supporting Commands
Taking a Closer Look at User Controls
Creating a Lookless Control
Refactoring the Color Picker Code
Refactoring the Color Picker Markup
Streamlining the Control Template
Supporting Visual States
Starting the FlipPanel Class
Choosing Parts and States
The Default Control Template
Using the FlipPanel
Using a Different Control Template
Creating Custom Panels
The Two-Step Layout Process
The Canvas Clone
A Better Wrapping Panel
Custom-Drawn Elements
The OnRender() Method
Evaluating Custom Drawing
Creating a Custom-Drawn Element
Creating a Custom Decorator
The Last Word
Part V: Data
Chapter 19: Data Binding
Binding to a Database with Custom Objects
Building a Data Access Component
Building a Data Object
Displaying the Bound Object
Updating the Database
Change Notification
Binding to a Collection of Objects
Displaying and Editing Collection Items
Inserting and Removing Collection Items
Binding to the ADO.NET Objects
Binding to a LINQ Expression
Improving Performance in Long Lists
Virtualization
Item Container Recycling
Cache Length
Deferred Scrolling
Validation
Validation in the Data Object
Custom Validation Rules
Reacting to Validation Errors
Getting a List of Errors
Showing a DifferenError Indicator
Validating Multiple Values
Data Providers
The ObjectDataProvider
The XmlDataProvider
The Last Word
Chapter 20: Formatting Bound Data
Data Binding Redux
Data Conversion
Using the StringFormat Property
Introducing Value Converters
Formatting Strings with a Value Converter
Creating Objects with a Value Converter
Applying Conditional Formatting
Evaluating Multiple Properties
List Controls
List Styles
The ItemContainerStyle
A ListBox with Check Boxes or Radio Buttons
Alternating Item Style
Style Selectors
Data Templates
Separating and Reusing Templates
Using More Advanced Templates
Varying Templates
Template Selectors
Templates and Selection
Changing Item Layout
The ComboBox
The Last Word
Chapter 21: Data Views
The View Object
Retrieving a View Object
Navigating with a View
Creating a View Declaratively
Filtering, Sorting, and Grouping
Filtering Collections
Filtering the DataTable
Sorting
Grouping
Live Shaping
The Last Word
Chapter 22: Lists, Trees, and Grids
The ListView
Creating Columns with the GridView
Creating a Custom View
The TreeView
Creating a Data-Bound TreeView
Binding a DataSet to a TreeView
Just-in-Time Node Creation
The DataGrid
Resizing and Rearranging Columns
Defining Columns
Formatting and Styling Columns
Formatting Rows
Displaying Row Details
Freezing Columns
Selection
Sorting
Editing
The Last Word
Part VI: Windows, Pages, and Rich Controls
Chapter 23: Windows
The Window Class
Showing a Window
Positioning a Window
Saving and Restoring Window Location
Window Interaction
Window Ownership
The Dialog Model
Common Dialog Boxes
Nonrectangular Windows
A Simple Shaped Window
A Transparent Window with Shaped Content
Moving Shaped Windows
Resizing Shaped Windows
Putting It All Together: A Custom Control Template for Windows
Programming the Windows Taskbar
Using Jump Lists
Changing the Taskbar Icon and Preview
The Last Word
Chapter 24: Pages and Navigation
Page-Based Navigation
Page-Based Interfaces
Creating a Simple Page-Based Application with NavigationWindow
The Page Class
Hyperlinks
Hosting Pages in a Frame
Hosting Pages in Another Page
Hosting Pages in a Web Browser
The Page History
A Closer Look at URIs in WPF
Navigation History
Maintaining Custom Properties
The Navigation Service
Programmatic Navigation
Navigation Events
Managing the Journal
Adding Custom Items to the Journal
Using Page Functions
XAML Browser Applications
Creating an XBAP
Deploying an XBAP
Updating an XBAP
XBAP Security
Full-Trust XBAPs
Combination XBAP/Stand-Alone Applications
Coding for Different Security Levels
Embedding an XBAP in a Web Page
The WebBrowser Control
Navigating to a Page
Building a DOM Tree
Scripting a Web Page with .NET Code
The Last Word
Chapter 25: Menus, Toolbars, and Ribbons
Menus
The Menu Class
Menu Items
The ContextMenu Class
Menu Separators
Toolbars and Status Bars
The ToolBar
The StatusBar
Ribbons
Adding the Ribbon
The Application Menu
Tabs, Groups, and Buttons
Rich Tooltips
Keyboard Access with KeyTips
Ribbon Sizing
The Quick Access Toolbar
The Last Word
Chapter 26: Sound and Video
Playing WAV Audio
The SoundPlayer
The SoundPlayerAction
System Sounds
The MediaPlayer
The MediaElement
Playing Audio Programmatically
Handling Errors
Playing Audio with Triggers
Playing Multiple Sounds
Changing Volume, Balance, Speed, and Position
Synchronizing an Animation with Audio
Playing Video
Video Effects
Speech
Speech Synthesis
Speech Recognition
The Last Word
Chapter 27: 3-D Drawing
3-D Drawing Basics
The Viewport
3-D Objects
The Camera
Deeper into 3-D
Shading and Normals
More Complex Shapes
Model3DGroup Collections
Materials Revisited
Texture Mapping
Interactivity and Animations
Transforms
Rotations
A Flyover
The Trackball
Hit Testing
2-D Elements on 3-D Surfaces
The Last Word
Part VII: Documents and Printing
Chapter 28: Documents
Understanding Documents
Flow Documents
Understanding Flow Elements
Formatting Content Elements
Constructing a Simple Flow Document
Using Block Elements
Using Inline Elements
Interacting with Elements Programmatically
Text Justification
Read-Only Flow Document Containers
Zooming
Creating Pages and Columns
Loading Documents from a File
Printing
Editing a Flow Document
Loading a File
Saving a File
Formatting Selected Text
Getting Individual Words
Fixed Documents
Annotations
Understanding the Annotation Classes
Enabling the Annotation Service
Creating Annotations
Examining Annotations
Reacting to Annotation Changes
Storing Annotations in a Fixed Document
Customizing the Appearance of Sticky Notes
The Last Word
Chapter 29: Printing
Basic Printing
Printing an Element
Transforming Printed Output
Printing Elements Without Showing Them
Printing a Document
Manipulating the Pages in a Document Printout
Custom Printing
Printing with the Visual Layer Classes
Custom Printing with Multiple Pages
Print Settings and Management
Maintaining Print Settings
Printing Page Ranges
Managing a Print Queue
Printing Through XPS
Creating an XPS Document for a Print Preview
Writing to an In-Memory XPS Document
Printing Directly to the Printer via XPS
Asynchronous Printing
The Last Word
Part VIII: Additional Topics
Chapter 30: Interacting with Windows Forms
Assessing Interoperability
Mixing Windows and Forms
Adding Forms to a WPF Application
Adding WPF Windows to a Windows Forms Application
Showing Modal Windows and Forms
Showing Modeless Windows and Forms
Enabling Visual Styles for Windows Forms Controls
Creating Windows with Mixed Content
Understanding WPF and Windows Forms “Airspace”
Hosting Windows Forms Controls in WPF
Using WPF and Windows Forms User Controls
Hosting WPF Controls in Windows Forms
Access Keys, Mnemonics, and Focus
Property Mapping
The Last Word
Chapter 31: Multithreading
Understanding the Multithreading Model
The Dispatcher
The DispatcherObject
The BackgroundWorker
A Simple Asynchronous Operation
Creating the BackgroundWorker
Running the BackgroundWorker
Tracking Progress
Supporting Cancellation
The Last Word
Chapter 32: The Add-in Model
Choosing Between MAF and MEF
Understanding the Add-in Pipeline
How the Pipeline Works
The Add-in Folder Structure
Preparing a Solution That Uses the Add-in Model
Creating an Application That Uses Add-Ins
The Contract
The Add-in View
The Add-In
The Add-in Adapter
The Host View
The Host Adapter
The Host
More Add-Ins
Interacting with the Host
Visual Add-Ins
The Last Word
Chapter 33: ClickOnce Deployment
Understanding Application Deployment
The ClickOnce Installation Model
ClickOnce Limitations
Setting Up a Simple ClickOnce Publication
Setting the Publisher and Production
Starting the Publish Wizard
Understanding the Deployed File Structure
Installing a ClickOnce Application
Updating a ClickOnce Application
Additional ClickOnce Options
Publish Version
Updates
File Associations
Publish Options
The Last Word
Index
A
B
C
D
E
F
G
H
I
J
K
L
M
N
O
P
Q
R
S
T
U
V
W
X, Y
Z