You can define a style inline in the XAML for a control, or as a reusable resource.

Defining styles as a reusable resource

Style definition locations

An individual page’s XAML file (will override a same named resource in App.xaml)

Will override a same named resource in App.xaml if present.

In the App.xaml file

In a separate resource dictionary XAML file

Can be shared across apps, and more than one resource dictionary can be merged in a single app).

Scope is determined by where the resource dictionary is referenced.

Style definitions

TargetType attribute

String that specifies a FrameworkElement type to apply the style to.

Must specify a FrameworkElement-derived type that’s defined by the Windows Runtime or a custom type that’s available in a referenced assembly.

If you try to apply a style to a control and the control’s type doesn’t match the TargetType attribute of the style you’re trying to apply, an exception occurs.

Setter elements

A collection of one or more Setter elements.  Each requires a Property and a Value.

x:Key

If a style contains the x:Key attribute, you can only apply it to a control by setting the Style property of the control to the keyed style. A style without an x:Key attribute is automatically applied to every control of its target type, that doesn’t otherwise have an explicit style setting.

Inheriting from other styles

Use the BasedOn property

UK Electronic Designer
USEFUL?
We benefit hugely from resources on the web so we decided we should try and give back some of our knowledge and resources to the community by opening up many of our company’s internal notes and libraries through mini sites like this. We hope you find the site helpful.
Please feel free to comment if you can add help to this page or point out issues and solutions you have found, but please note that we do not provide support on this site. If you need help with a problem please use one of the many online forums.