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.


這個屬性會影響視覺外觀,但不會 AffectsRender 在中繼資料中報告。This 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 Attribute UsageXAML 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. 索引鍵是指中的現有資源 ResourceDictionaryThe key refers to an existing resource in a ResourceDictionary.


在技術上,屬性元素語法是可行的,但不建議使用。Property element syntax is technically possible, but not recommended. 請參閱 內嵌樣式和範本See Inline Styles and Templates. 使用 TemplateBinding 或的系結參考 Binding 也可以,但不常見。A binding reference using TemplateBinding or Binding is also possible, but uncommon.

相依性屬性資訊Dependency Property Information

識別碼欄位Identifier field FocusVisualStyleProperty
中繼資料屬性設定為 trueMetadata properties set to true None