10.1. Resource Basics

WPF allows you to define resources in code or in a variety of places in your markup (along with specific controls, in specific windows, or across the entire application).

Resources have a number of important benefits:

  • Efficiency. Resources let you define an object once and use it in several places in your markup. This streamlines your code and makes it marginally more efficient.

  • Maintainability. Resources let you take low-level formatting details (such as font sizes) and move them to a central place where they're easy to change. It's the XAML equivalent of creating constants in your code.

  • Adaptability. Once certain information is separated from the rest of your application and placed in a resource section, it becomes possible ...

Get Pro WPF in C# 2010: Windows Presentation Foundation in .NET 4 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.