FrameworkContentElement.FocusVisualStyle Property

Gets or sets an object that enables customization of appearance, effects, or other style characteristics that will apply to this element when it captures keyboard focus. This is a dependency property.

Namespace: System.Windows
Assembly: PresentationFramework (in presentationframework.dll)
XML Namespace:

public Style FocusVisualStyle { get; set; }
/** @property */
public Style get_FocusVisualStyle ()

/** @property */
public void set_FocusVisualStyle (Style value)

public function get FocusVisualStyle () : Style

public function set FocusVisualStyle (value : Style)

<object FocusVisualStyle="{resourceExtension styleResourceKey}"/>
 resourceExtension  One of the following: StaticResource, or DynamicResource. See Resources Overview.  styleResourceKey  The key that identifies the style being requested. The key refers to an existing resource in a ResourceDictionary. 

Property Value

The desired style to apply on focus. The default value as declared in the dependency property is an empty static Style. However, the effective value at runtime is often (but not always) a style as supplied by theme support for controls.

Identifier field


Metadata properties set to true


When setting this property in XAML, styles are almost always defined as a resource, rather than inline as an element, and that resource is usually referenced as a StaticResourceExtension.

Note that this property affects visual appearance but does not report so in metadata. This is because the visual appearance change is event-driven and may not apply at all times, and thus should not generally report any visual or layout information in metadata.

This example shows you how to create a focus-specific style in resources that is applied to the control, using the FocusVisualStyle property.

The following example defines a style that creates additional control compositing that only applies when that control is focused in the user interface (UI). This is accomplished by defining a style with a ControlTemplate, then referencing that style as a resource when setting the FocusVisualStyle. Note that in this case the FocusVisualStyle is additive to any normal style; the fact that you create a new ControlTemplate does not impact the normal styling of the button, as it would had you attempted to create a style with a ControlTemplate and setting that style to the Style property. In this case an external rectangle resembling a border is placed outside of the rectangular area that is bound to the actual height and width of the rectangular control being focused. Negative values are set on Top and Left to make the border appear outside the focused control, somewhat like a highlight.


Conceptually, the visual behavior of focus applied to a control should be coherent from control to control. The most sensible way to ensure coherence is to only change the focus visual style if you are composing an entire theme, where each control that is defined in the theme will get either the very same Style, or some variation of a Style that at least is visually coherent from control to control. Setting this property on invididual control styles and not as part of a theme is not the intended usage of this property because it may lead to a confusing user experience regarding keyboard focus. If you are intending control-specific behaviors that are deliberately not coherent across a theme, a much better approach is to use triggers in styles for individual input state properties, such as IsFocused or IsKeyboardFocusWithin.

    <Style x:Key="MyFocusVisual">
      <Setter Property="Control.Template">
            <Rectangle Margin="-2"  StrokeThickness="1" Stroke="Red" StrokeDashArray="1 2"/>
  <StackPanel Background="Ivory" Orientation="Horizontal">
	  <Canvas Width="10"/>
	  <Button Width="100" Height="30" FocusVisualStyle="{DynamicResource MyFocusVisual}">Focus Here</Button>
	  <Canvas Width="100"/>
	  <Button Width="100" Height="30" FocusVisualStyle="{DynamicResource MyFocusVisual}">Focus Here</Button>

For the complete sample, see Creating a FocusVisualStyle Sample.

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0

Community Additions