FrameworkElement.FocusVisualStyle FrameworkElement.FocusVisualStyle FrameworkElement.FocusVisualStyle FrameworkElement.FocusVisualStyle Property

定義

取得或設定屬性,這個屬性可自訂外觀、效果或其他樣式特性,以在這個項目捕捉到鍵盤焦點時套用至項目。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.

public:
 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

XAML 值XAML Values

resourceExtensionresourceExtension
下列其中一項:、或。One of the following: , or . 請參閱XAML 資源See XAML Resources.

styleResourceKeystyleResourceKey
識別所要求之樣式的索引鍵。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

適用於

另請參閱