TemplateVisualStateAttribute 類別

定義

表示控制項可以處於特定狀態,而且 VisualState 是控制項的 ControlTemplate 中的預期項目。

public ref class TemplateVisualStateAttribute sealed : Attribute
[System.AttributeUsage(System.AttributeTargets.Class, AllowMultiple=true)]
public sealed class TemplateVisualStateAttribute : Attribute
[<System.AttributeUsage(System.AttributeTargets.Class, AllowMultiple=true)>]
type TemplateVisualStateAttribute = class
    inherit Attribute
Public NotInheritable Class TemplateVisualStateAttribute
Inherits Attribute
繼承
TemplateVisualStateAttribute
屬性

範例

下列範例顯示 控制項的 NumericUpDown 類別簽章。 這個範例會指定控制項使用四種 NumericUpDown 視覺狀態。 名為 PositiveNegative 的兩個狀態位於名為 ValueStatesVisualStateGroup 中。 其他兩個狀態名稱 Focused 為 和 Unfocused ,位於名為 FocusedStatesVisualStateGroup 中。 如需整個範例,請參閱 建立具有可自訂外觀的控制項

[TemplatePart(Name = "UpButtonElement", Type = typeof(RepeatButton))]
[TemplatePart(Name = "DownButtonElement", Type = typeof(RepeatButton))]
[TemplateVisualState(Name = "Positive", GroupName = "ValueStates")]
[TemplateVisualState(Name = "Negative", GroupName = "ValueStates")]
[TemplateVisualState(Name = "Focused", GroupName = "FocusedStates")]
[TemplateVisualState(Name = "Unfocused", GroupName = "FocusedStates")]
public class NumericUpDown : Control
<TemplatePart(Name:="UpButtonElement", Type:=GetType(RepeatButton))> _
<TemplatePart(Name:="DownButtonElement", Type:=GetType(RepeatButton))> _
<TemplateVisualState(Name:="Positive", GroupName:="ValueStates")> _
<TemplateVisualState(Name:="Negative", GroupName:="ValueStates")> _
<TemplateVisualState(Name:="Focused", GroupName:="FocusedStates")> _
<TemplateVisualState(Name:="Unfocused", GroupName:="FocusedStates")> _
Public Class NumericUpDown
    Inherits Control

備註

控制項作者會使用這個屬性來指定 VisualState 屬於其控制項 的 ControlTemplateVisualStateGroup 物件。 例如,假設您建立新的控制項,其具有兩個名為 FocusedUnfocused 的視覺狀態,這兩者都位於 VisualStateGroup 具名 FocusStates 的 中。 若要指定作者 ControlTemplate 可以使用這些視覺狀態,請將兩個 TemplateVisualStateAttribute 屬性新增至控制項的類別簽章。 指定 GroupName 屬性為 FocusStates ,且 Name 屬性適用于 Focused 一個 和 Unfocused 另一個屬性。

建構函式

TemplateVisualStateAttribute()

初始化 TemplateVisualStateAttribute 類別的新執行個體。

屬性

GroupName

取得或設定狀態所屬的群組之名稱。

Name

取得或設定控制項可以處於的狀態名稱。

TypeId

在衍生類別中實作時,取得這個 Attribute 的唯一識別碼。

(繼承來源 Attribute)

方法

Equals(Object)

傳回值,這個值指出此執行個體是否與指定的物件相等。

(繼承來源 Attribute)
GetHashCode()

傳回這個執行個體的雜湊碼。

(繼承來源 Attribute)
GetType()

取得目前執行個體的 Type

(繼承來源 Object)
IsDefaultAttribute()

在衍生類別中覆寫時,表示這個執行個體的值是衍生類別的預設值。

(繼承來源 Attribute)
Match(Object)

在衍生類別中覆寫時,會傳回值,表示這個執行個體是否等於指定物件。

(繼承來源 Attribute)
MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
ToString()

傳回代表目前物件的字串。

(繼承來源 Object)

明確介面實作

_Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

將一組名稱對應至一組對應的分派識別項 (Dispatch Identifier)。

(繼承來源 Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

擷取物件的類型資訊,可以用來取得介面的類型資訊。

(繼承來源 Attribute)
_Attribute.GetTypeInfoCount(UInt32)

擷取物件提供的類型資訊介面數目 (0 或 1)。

(繼承來源 Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

提供物件所公開的屬性和方法的存取權。

(繼承來源 Attribute)

適用於