FrameworkElement.FocusVisualStyle 属性


获取或设置一个属性,该属性允许自定义此元素在捕获到键盘焦点时要应用于此元素的外观、效果或其他样式特征。Gets or sets a property that enables customization of appearance, effects, or other style characteristics that will apply to this element when it captures keyboard focus.

 property System::Windows::Style ^ FocusVisualStyle { System::Windows::Style ^ get(); void set(System::Windows::Style ^ value); };
public System.Windows.Style FocusVisualStyle { get; set; }
member this.FocusVisualStyle : System.Windows.Style with get, set
Public Property FocusVisualStyle As Style



要应用于焦点的所需样式。The desired style to apply on focus. 该依赖属性中声明的默认值是一个空的静态 StyleThe default value as declared in the dependency property is an empty static Style. 但是,运行时的有效值通常是(但并非总是)控件的主题支持所提供的样式。However, the effective value at run time is often (but not always) a style as supplied by theme support for controls.


此属性会影响视觉外观,但不会在元数据中报告 AffectsRenderThis property affects visual appearance but does not report AffectsRender in metadata. 这是因为视觉外观更改是事件驱动的,可能不会在任何时候都适用,因此通常不会在元数据中报告任何视觉对象或布局信息。This is because the visual appearance change is event-driven and may not apply at all times, and therefore should not generally report any visual or layout information in metadata.

从概念上讲,应用于控件的焦点的视觉行为应与控件一致。Conceptually, the visual behavior of focus applied to a control should be coherent from control to control. 强制一致性的最明智方式是仅在编写整个主题时更改焦点视觉样式。The most sensible way to enforce coherence is to only change the focus visual style if you are composing an entire theme. 对单个控件样式设置此属性,而不是主题的一部分,这并不是此属性的预期用法,因为这可能会导致与键盘焦点有关的用户体验混乱。Setting this property on individual 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. 如果要在主题中特意不连贯特定于控件的行为,一种更好的方法是在样式中使用各个输入状态属性(例如 IsFocusedIsKeyboardFocusWithin)的触发器,并以不会直观干扰任何现有焦点视觉样式的方式执行此操作。If you are intending control-specific behavior that is 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, and to do so in a way that does not visually interfere with any existing focus visual style. 有关 FocusVisualStyle 和替代焦点属性的设计意图的详细信息,请参阅为控件中的焦点设置样式和 FocusVisualStyleFor more information on the design intention of FocusVisualStyle and alternative focus properties, see Styling for Focus in Controls, and FocusVisualStyle.

XAML 特性用法XAML Attribute Usage

<object FocusVisualStyle="{resourceExtension styleResourceKey}"/>  

XAML 属性元素用法XAML Property Element Usage


以下项之一:、或。One of the following: , or . 请参阅XAML 资源See XAML Resources.

标识所请求的样式的键。The key that identifies the style being requested. 该键引用 ResourceDictionary中的现有资源。The key refers to an existing resource in a ResourceDictionary.


属性元素语法在技术上是可行的,但不建议这样做。Property element syntax is technically possible, but not recommended. 请参阅内联样式和模板See Inline Styles and Templates. 也可以使用TemplateBindingBinding 的绑定引用,但情况并不常见。A binding reference using TemplateBinding or Binding is also possible, but uncommon.

依赖项属性信息Dependency Property Information

标识符字段Identifier field FocusVisualStyleProperty
元数据属性设置为 trueMetadata properties set to true None