Book Image

Mastering Windows Presentation Foundation

By : Sheridan Yuen
Book Image

Mastering Windows Presentation Foundation

By: Sheridan Yuen

Overview of this book

Windows Presentation Foundation is rich in possibilities when it comes to delivering an excellent user experience. This book will show you how to build professional-grade applications that look great and work smoothly. We start by providing you with a foundation of knowledge to improve your workflow – this includes teaching you how to build the base layer of the application, which will support all that comes after it. We’ll also cover the useful details of data binding. Next, we cover the user interface and show you how to get the most out of the built-in and custom WPF controls. The final section of the book demonstrates ways to polish your applications, from adding practical animations and data validation to improving application performance. The book ends with a tutorial on how to deploy your applications and outlines potential ways to apply your new-found knowledge so you can put it to use right away.
Table of Contents (19 chapters)
Mastering Windows Presentation Foundation
Credits
About the Author
About the Reviewer
www.PacktPub.com
Customer Feedback
Preface

Preface

While it can be easy to construct a basic form using WPF, it takes a lot more to fully understand what WPF can do for us and how best to use it. It has a steep learning curve and it can be difficult to comprehend this very different way of working. This book aims to help you to get over that initial hill and continue to fully enable you to implement any given requirement.

This book will start by providing you the foundation knowledge on how to improve your workflow and what to do when you have problems. It will build upon this foundation by introducing the base layer of the application that will serve all that comes after it. We will then take a detour to cover data binding in detail.

The book will then turn to the User Interface (UI) and how to get the most out of the built-in and custom WPF controls. It will make clear which customization methods are best to utilize in a wide range of scenarios, avoiding the need to rewrite existing functionality. Other tips and tricks will also be provided to enable you to create your own visually stunning UIs.

The final section of the book will introduce the concluding ways for you to polish your applications, from adding practical animations and data validation, to improving application performance. The book will end by explaining how to deploy the applications that you have been working so hard on and discuss other things that you can now achieve with your new found knowledge.

What this book covers

Chapter 1, A Smarter Way of Working with WPF, introduces the Model, View, View Model (MVVM) software architectural pattern and the benefits of using it with WPF.

Chapter 2, Debugging WPF Applications, provides essential tips on various methods of debugging WPF applications, ensuring the ability to iron out any problems that may occur.

Chapter 3, Writing Custom Application Frameworks, introduces the indispensable concept of application frameworks, with early examples that will be built upon as the book progresses. By the end of the book, you will have a fully functioning Framework with which to build your applications upon.

Chapter 4, Becoming Proficient with Data Binding, demystifies data binding and clearly demonstrates how to use it in a practical application. A plethora of examples will help you to understand which binding syntax to use in any given situation and to be confident that their bindings will work as expected.

Chapter 5, Using The Right Controls for The Job, explains which controls to use in particular situations and describes the various ways to modify them when required. It clearly outlines how to customize existing controls and how to create custom controls when required.

Chapter 6, Mastering Practical Animations, explains the ins and outs of WPF Animations, detailing lesser known functionality. It concludes with a number of ideas for practical animations and continues to build upon the custom application framework.

Chapter 7, Creating Visually Stunning User Interfaces, offers advice for getting the most out of the WPF visuals, while remaining practical, and provides handy tips on making applications stand out from the crowd.

Chapter 8, Implementing Responsive Data Validation, presents a number of methods of data validation to suit every situation and continues to build upon the custom application framework. It covers full, partial, instant, and delayed validation and a variety of different ways to display validation errors.

Chapter 9, Completing That Great User Experience, provides tips for creating applications with a great user experience. Concepts introduced here, such as asynchronous data access and keeping the end users well informed, will substantially improve the existing custom application framework.

Chapter 10, Improving Application Performance, lists a number of ways to increase the performance of WPF applications from freezing resources to implementing virtualization. Readers that follow these tips and tricks can rest assured that their WPF applications will perform as optimally as they can.

Chapter 11, Deploying Your Masterpiece Application, covers the final requirement for all professional applications—deployment. It includes the older method of using the Windows Installer software, along with the more common and up-to-date method of using ClickOnce functionality.

Chapter 12, What Next?, summarizes what you have learned from this book and suggests what you can do with many of your various new skills. It provides you with further ideas on extending the application framework.

What you need for this book

As with all WPF development, you'll need to have the .NET Framework and a version of Microsoft's Visual Studio integrated development environment software installed on your computer.

You'll be able to use versions as old as 2010, but in order to use the code in the book that takes advantage of the latest .NET Framework improvements, you'll need to use one of the newer versions. Note that any edition of Visual Studio can be used, from the top of the line Enterprise edition to the free Community (2015) edition.

Who this book is for

This book is for working developers with a basic to moderate level of knowledge about Windows Presentation Foundation and for those interested in improving their practical day to day WPF skills. It will also be of special interest to individuals wanting to know more about application architecture and those wanting to improve the look of their user interfaces.

Conventions

In this book, you will find a number of text styles that distinguish between different kinds of information. Here are some examples of these styles and an explanation of their meaning.

Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "There are two other useful properties declared by the Grid class."

A block of code is set as follows:

public string Name
{
  get { return name; }
  set
  {
    if (name != value)
    {
      name = value;
      NotifyPropertyChanged("Name");
    }
  }
}

Any command-line input or output is written as follows:

System.Windows.Data Error: 17 : Cannot get 'Item[]' value (type 
'ValidationError') from '(Validation.Errors)' (type 
'ReadOnlyObservableCollection`1'). 
BindingExpression:Path=(Validation.Errors)[0].ErrorContent; 
DataItem='TextBox' (Name=''); target element is 'TextBox' (Name=''); 
target property is 'ToolTip' (type 'Object') 
ArgumentOutOfRangeException:'System.ArgumentOutOfRangeException: 
Specified argument was out of the range of valid values.

New terms and important words are shown in bold. Words that you see on the screen, for example, in menus or dialog boxes, appear in the text like this: "The Cancel button has been declared in the second row and column."

Note

Warnings or important notes appear in a box like this.

Tip

Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book-what you liked or disliked. Reader feedback is important for us as it helps us develop titles that you will really get the most out of. To send us general feedback, simply e-mail [email protected], and mention the book's title in the subject of your message. If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide at www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code

You can download the example code files for this book from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

You can download the code files by following these steps:

  1. Log in or register to our website using your e-mail address and password.
  2. Hover the mouse pointer on the SUPPORT tab at the top.
  3. Click on Code Downloads & Errata.
  4. Enter the name of the book in the Search box.
  5. Select the book for which you're looking to download the code files.
  6. Choose from the drop-down menu where you purchased this book from.
  7. Click on Code Download.

Once the file is downloaded, please make sure that you unzip or extract the folder using the latest version of:

  • WinRAR / 7-Zip for Windows
  • Zipeg / iZip / UnRarX for Mac
  • 7-Zip / PeaZip for Linux

The code bundle for the book is also hosted on GitHub at https://github.com/PacktPublishing/Mastering-Windows-Presentation-Foundation. We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!

Downloading the color images of this book

We also provide you with a PDF file that has color images of the screenshots/diagrams used in this book. The color images will help you better understand the changes in the output. You can download this file from https://www.packtpub.com/sites/default/files/downloads/MasteringWindowsPresentationFoundation_ColorImages.pdf.

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books-maybe a mistake in the text or the code-we would be grateful if you could report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded to our website or added to any list of existing errata under the Errata section of that title.

To view the previously submitted errata, go to https://www.packtpub.com/books/content/support and enter the name of the book in the search field. The required information will appear under the Errata section.

Piracy

Piracy of copyrighted material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works in any form on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at [email protected] with a link to the suspected pirated material.

We appreciate your help in protecting our authors and our ability to bring you valuable content.

Questions

If you have a problem with any aspect of this book, you can contact us at [email protected], and we will do our best to address the problem.