--- title: "How to: Apply a FocusVisualStyle to a Control" ms.date: "03/30/2017" helpviewer_keywords: - "properties [WPF], FocusVisualStyle" - "FocusVisualStyle property [WPF]" ms.assetid: 363de99e-8ecc-438c-ac4a-f9147432ebd6 --- # How to: Apply a FocusVisualStyle to a Control This example shows you how to create a focus visual style in resources and apply the style to a control, using the property. ## Example The following example defines a style that creates additional control compositing that only applies when that control is keyboard focused in the [!INCLUDE[TLA#tla_ui](../../../includes/tlasharptla-ui-md.md)]. This is accomplished by defining a style with a , then referencing that style as a resource when setting the property. An external rectangle resembling a border is placed outside of the rectangular area. Unless otherwise modified, the sizing of the style uses the and of the rectangular control where the focus visual style is applied. This example sets negative values for the to make the border appear slightly outside the focused control. [!code-xaml[FEFocusVisualStyle#XAML](~/samples/snippets/csharp/VS_Snippets_Wpf/FEFocusVisualStyle/CS/page1.xaml#xaml)] A is additive to any control template style that comes either from an explicit style or a theme style; the primary style for a control can still be created by using a and setting that style to the property. Focus visual styles should be used consistently across a theme or a UI, rather than using a different one for each focusable element. For details, see [Styling for Focus in Controls, and FocusVisualStyle](styling-for-focus-in-controls-and-focusvisualstyle.md). ## See also - - [Styling and Templating](/dotnet/desktop-wpf/fundamentals/styles-templates-overview) - [Styling for Focus in Controls, and FocusVisualStyle](styling-for-focus-in-controls-and-focusvisualstyle.md)