FrameworkContentElement.DefaultStyleKey 屬性

定義

取得或設定索引鍵,以用來在佈景主題中尋找這個控制項的樣式樣板。Gets or sets the key to use to find the style template for this control in themes.

protected public:
 property System::Object ^ DefaultStyleKey { System::Object ^ get(); void set(System::Object ^ value); };
protected internal object DefaultStyleKey { get; set; }
member this.DefaultStyleKey : obj with get, set
Protected Friend Property DefaultStyleKey As Object

屬性值

樣式索引鍵。The style key. 若要正確運做為佈景主題查詢的一部分,這個值必須是要加上樣式之項目的 TypeTo work correctly as part of theme style lookup, this value is expected to be the Type of the element being styled. 針對特定案例,null 是可接受的值。null is an accepted value for a certain case.

備註

這個屬性通常不會透過其任何一個直接 setter 來設定。This property is typically not set through any of its direct setters. 相反地,您會在每次建立新的子類別時,覆寫此相依性屬性的特定類型中繼資料。Instead, you override the type-specific metadata of this dependency property every time you create a new subclass. 當您將子類別化時,請在控制項子類別的靜態函式中,針對 DefaultStyleKeyProperty 識別碼呼叫 OverrideMetadata 方法。When you subclass, call the OverrideMetadata method against the DefaultStyleKeyProperty identifier, within the static constructor of the control subclass.

比方說,像 Bold 之類的內嵌類別其實不會在其靜態的函式中覆寫 DefaultStyleKey 中繼資料,以及公開數個實例的函式。For instance, an inline class such as Bold actually has very little implementation beyond overriding the DefaultStyleKey metadata in its static constructor, and exposing several instance constructors. Bold 標記所括住的元素會取得 BoldFontWeight 屬性,而此主題樣式是由將 DefaultStyleKey 的預設值設定為 [typeof(Bold)] 所參考。The fact that elements surrounded by the Bold tag gain a FontWeight property of Bold is implemented within the theme style that was referenced by setting the default value of DefaultStyleKey to typeof(Bold).

如果您想要讓元素或控制項故意不使用主題樣式,請將 OverridesDefaultStyle 屬性設定為 trueIf you want your element or control to deliberately not use theme styles, set the OverridesDefaultStyle property to true.

相依性屬性資訊Dependency Property Information

識別碼欄位Identifier field DefaultStyleKeyProperty
設定為 true 的中繼資料屬性Metadata properties set to true AffectsMeasure

適用於