O'Reilly logo

Professional Visual Basic 2012 and .NET 4.5 Programming by Todd Herman, Gastón Hillar, David McCarter, Rob Windsor, Billy Hollis, Bill Sheldon

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Resources in XAML

Efficient developers like to create capabilities once, and then reuse them as necessary. The usual object-oriented techniques for reuse are available in XAML, because the .NET Framework provides them. But XAML also includes a special capability to create constructs for reuse, in the form of XAML resources.

If you are an experienced .NET developer, the term resources may already be familiar to you. .NET supports resources for capabilities such as localization. Resource files in .NET normally have the extension .resx. However, that's a completely separate concept from XAML resources. This section has nothing to do with .resx files, localization, or any of the subjects you might normally associate with .NET resources.

In XAML, the term resources has a different meaning. XAML resources are objects that are declared once and then available for use in several places. Resources are usually declared in XAML, but as with all other XAML objects, they can also be created in code. In this chapter, you will work exclusively with XAML resources created in XAML.

The Resources Property

XAML elements have a property named Resources, and it holds a dictionary of objects called a ResourceDictionary. Any type of object can go in the dictionary.

Because it's a dictionary, every item in a ResourceDictionary needs a key. This key is normally supplied with another helper capability in the x: namespace, which is the x:Key attribute.

To see the syntax, suppose our UserControl in the original ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required