Pro WPF 4.5 in C#

Windows Presentation Foundation in .NET 4.5

4th Edition

By Matthew MacDonald

Pro WPF 4.5 in C# Cover Image

This book shows you how Windows Presentation Foundation really works. It provides you with the no-nonsense, practical advice that you need in order to build high-quality WPF applications quickly and easily.

Full Description

  • ISBN13: 978-1-4302-4365-6
  • 1112 Pages
  • User Level: Intermediate
  • Publication Date: December 2, 2012
  • Available eBook Formats: EPUB, MOBI, PDF
  • Print Book Price: $59.99
  • eBook Price: $41.99
Buy eBook Buy Print Book Add to Wishlist

Related Titles

Full Description

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.

What you’ll learn

  • Understand the fundamentals of WPF programming from XAML to controls and data flow.
  • Develop realistic application scenarios to see navigation, localization and deployment in action.
  • Explore the advanced user interface controls that WPF provides.
  • Learn to manage documents from within WPF: Text layout, printing, and document packaging are all covered.
  • Use graphics and multimedia to add punch to your applications

Who this book is for

This book is designed for developers encountering WPF for the first time in their professional lives. A working knowledge of C# and the basic architecture of .NET is helpful to follow the examples easily, but all concepts will be explained from the ground up.

Table of Contents

Table of Contents

  1. Introducing WPF
  2. XAML
  3. Layout
  4. Dependency Properties
  5. Routed Events
  6. Controls
  7. The Application
  8. Element Binding
  9. Commands
  10. Resources
  11. Styles and Behaviors
  12. Shapes, Brushes, and Transforms
  13. Geometries and Drawings
  14. Effects and Visuals
  15. Animation Basics
  16. Advanced Animation
  17. Control Templates
  18. Custom Elements
  19. Data Binding
  20. Formatting
  21. Bound Data
  22. Data Views
  23. Lists, Trees, and Grids
  24. Windows Pages and Navigation
  25. Menus, Toolbars, and Ribbons
  26. Sound and Video
  27. 3-D Drawing
  28. Documents
  29. Printing
  30. Interacting with Windows Forms
  31. Multithreading
  32. The Add-in Model
  33. ClickOnce Deployment
Source Code/Downloads

Downloads are available to accompany this book.

Your operating system can likely extract zipped downloads automatically, but you may require software such as WinZip for PC, or StuffIt on a Mac.

Errata

Please Login to submit errata.

On page Ch. 18:
The following code regarding visual states does not work:

<ControlTemplate TargetType="{x:Type local:FlipPanel}">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
</Grid.RowDefinitions>

<!-- This is the front content. -->
<Border BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
CornerRadius="{TemplateBinding CornerRadius}"
Background="{TemplateBinding Background}">
<ContentPresenter Content="{TemplateBinding FrontContent}">
</ContentPresenter>
</Border>

<!-- This is the back content. -->
<Border BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
CornerRadius="{TemplateBinding CornerRadius}"
Background="{TemplateBinding Background}">
<ContentPresenter Content="{TemplateBinding BackContent}">
</ContentPresenter>
</Border>

<!-- This the flip button. -->
<ToggleButton Grid.Row="1" x:Name="FlipButton" Margin="0,10,0,0">
</ToggleButton>

</Grid>
</ControlTemplate>

This is because the author fails to add a Name attribute to the two borders representing the FrontContent and BackContent. This causes the Control Template to throw an InvalidOperationException when ChangeVisualState is called due to BackContent not being in the Name Scope of the XAML page. The solution is add the name attribute like so:

<ControlTemplate TargetType="{x:Type local:FlipPanel}">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
</Grid.RowDefinitions>

<!-- This is the front content. -->
<Border BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
CornerRadius="{TemplateBinding CornerRadius}"
Background="{TemplateBinding Background}" Name="FrontContent">
<ContentPresenter Content="{TemplateBinding FrontContent}">
</ContentPresenter>
</Border>

<!-- This is the back content. -->
<Border BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
CornerRadius="{TemplateBinding CornerRadius}"
Background="{TemplateBinding Background}" Name="BackContent">
<ContentPresenter Content="{TemplateBinding BackContent}">
</ContentPresenter>
</Border>

<!-- This the flip button. -->
<ToggleButton Grid.Row="1" x:Name="FlipButton" Margin="0,10,0,0">
</ToggleButton>

</Grid>
</ControlTemplate>

On page 103:
For the Scrollbar example (specific to the RangeBase class), in the text for the OnMinimumChanged() method, I believe there is typo in one of the statements:

e.g.
...
base1.CoerceMaximum(RangeBase.MaximumProperty);
base1.CoerceValue(RangeBase.ValueProperty);
....

I believe the second statement is accurate, but the first should be

base1.CoerceValue(RangeBase.MaximumProperty);

Since CoerceMaximum() method being called is static and private, and cannot be called in this manner without throwing an exception.

On page 115:
I think

object tag = ((FrameworkElement)sender).Tag;

should read

object tag = ((FrameworkElement)e.Source).Tag;

On page 139:
The code provided does not compile; the line "Point center = new Point(element.ActualWidth / 2, element.ActualHeight / 2);" gives 2 errors.

On page 233:
The second parameter of BindingOperations.GetBinding & BindingOperations.GetBindingExpression methods should be a dependency property instead of a regular property, so the corresponding statements should read:

Binding binding = BindingOperations.GetBinding(lblSampleText, TextBlock.FontSizeProperty);

&

BindingExpression expression = BindingOperations.GetBindingExpression(lblSampleText,
TextBlock.FontSizeProperty);

On page 260:
In the complete XAML markup example in the middle of the page, there is one missing XAML namespace mapping for the local namespace that's referenced in the command binding for the new command.

I believe something like below should be added to the Window element:

<Window ...
xmlns:local="clr-namespace:Commands"
...>
...
</Window>

On page 336:
This new pattern will match only URLs that contain three segments, the first of which must be Customers.

Should be:

This new pattern will match only URLs that contain three segments, the first of which must be public.

On page 559:
Stored procedure name in first sentence of second paragraph should be "GetProductByID" instead of ""GetProduct". A more significant problem is that this stored procedure in the database does not return "CategoryName" and so the "GetProduct" method fails.

On page 560:
Actual code for "GetProduct" method retrieves "CategoryID" and "CategoryName" as well and hence fails because "CategoryName" is not returned by the stored procedure.