--- title: Styles and templates description: Learn about XAML resources in Windows Presentation Foundation (WPF) for .NET Framework. Understand the types of XAML resources related to styles and themes. author: adegeo ms.author: adegeo ms.date: 09/09/2019 ms.topic: overview dev_langs: - "csharp" - "vb" --- # Styles and templates in WPF Windows Presentation Foundation (WPF) styling and templating refer to a suite of features that let developers and designers create visually compelling effects and a consistent appearance for their product. When customizing the appearance of an app, you want a strong styling and templating model that enables maintenance and sharing of appearance within and among apps. WPF provides that model. Another feature of the WPF styling model is the separation of presentation and logic. Designers can work on the appearance of an app by using only XAML at the same time that developers work on the programming logic by using C# or Visual Basic. This overview focuses on the styling and templating aspects of the app and doesn't discuss any data-binding concepts. For information about data binding, see [Data Binding Overview](../data/data-binding-overview.md). It's important to understand resources, which are what enable styles and templates to be reused. For more information about resources, see [XAML Resources](../advanced/xaml-resources-define.md). ## Sample The sample code provided in this overview is based on a [simple photo browsing application](https://github.com/Microsoft/WPF-Samples/tree/master/Styles%20&%20Templates/IntroToStylingAndTemplating) shown in the following illustration. ![Styled ListView](./media/styles-and-templates-overview/stylingintro-triggers.png "StylingIntro_triggers") This simple photo sample uses styling and templating to create a visually compelling user experience. The sample has two elements and a control that is bound to a list of images. For the complete sample, see [Introduction to Styling and Templating Sample](https://github.com/Microsoft/WPF-Samples/tree/master/Styles%20&%20Templates/IntroToStylingAndTemplating). ## Styles You can think of a as a convenient way to apply a set of property values to multiple elements. You can use a style on any element that derives from or such as a or a . The most common way to declare a style is as a resource in the `Resources` section in a XAML file. Because styles are resources, they obey the same scoping rules that apply to all resources. Put simply, where you declare a style affects where the style can be applied. For example, if you declare the style in the root element of your app definition XAML file, the style can be used anywhere in your app. For example, the following XAML code declares two styles for a `TextBlock`, one automatically applied to all `TextBlock` elements, and another that must be explicitly referenced. [!code-xaml[SnippetDefaultTextBlockStyleBasedOn](./snippets/styles-templates-overview/csharp/Window2.xaml#SnippetDefaultTextBlockStyleBasedOn)] Here is an example of the styles declared above being used. [!code-xaml[SnippetTextBlocksExplicit](./snippets/styles-templates-overview/csharp/Window2.xaml#SnippetTextBlocksExplicit)] ![Styled textblocks](./media/styles-and-templates-overview/stylingintro-textblocks.png) ## ControlTemplates In WPF, the of a control defines the appearance of the control. You can change the structure and appearance of a control by defining a new and assigning it to a control. In many cases, templates give you enough flexibility so that you do not have to write your own custom controls. Each control has a default template assigned to the [Control.Template](xref:System.Windows.Controls.Control.Template) property. The template connects the visual presentation of the control with the control's capabilities. Because you define a template in XAML, you can change the control's appearance without writing any code. Each template is designed for a specific control, such as a . Commonly you declare a template as a resource on the `Resources` section of a XAML file. As with all resources, scoping rules apply. Control templates are a lot more involved than a style. This is because the control template rewrites the visual appearance of the entire control, while a style simply applies property changes to the existing control. However, since the template of a control is applied by setting the [Control.Template](xref:System.Windows.Controls.Control.Template) property, you can use a style to define or set a template. Designers generally allow you to create a copy of an existing template and modify it. For example, in the Visual Studio WPF designer, select a `CheckBox` control, and then right-click and select **Edit template** > **Create a copy**. This command generates a *style that defines a template*. ```xaml