共用方式為


VisualState.Name 屬性

定義

取得或設定 的名稱。VisualState

public:
 property System::String ^ Name { System::String ^ get(); void set(System::String ^ value); };
public string Name { get; set; }
member this.Name : string with get, set
Public Property Name As String

屬性值

這個名稱 VisualState

範例

以下範例在 PressedNormal中建立 ,VisualStateGroupCommonStatesButtonControlTemplate並對VisualState狀態 、 、 和 MouseOver加入物件。 也 Button 定義了一個狀態,稱為 Disabled 屬於 CommonStatesVisualStateGroup,但為簡潔起見,範例省略了它。 完整範例請參見 「如何建立控制項範本」。

  <!--Define the states and transitions for the common states.
      The states in the VisualStateGroup are mutually exclusive to
      each other.-->
  <VisualStateGroup x:Name="CommonStates">

    <!--The Normal state is the state the button is in
        when it is not in another state from this VisualStateGroup.-->
    <VisualState x:Name="Normal" />

    <!--Change the SolidColorBrush, BorderBrush, to red when the
        mouse is over the button.-->
    <VisualState x:Name="MouseOver">
      <Storyboard>
        <ColorAnimation Storyboard.TargetName="BorderBrush" 
                        Storyboard.TargetProperty="Color" 
                        To="Red" />
      </Storyboard>
    </VisualState>

    <!--Change the SolidColorBrush, BorderBrush, to Transparent when the
        button is pressed.-->
    <VisualState x:Name="Pressed">
      <Storyboard>
        <ColorAnimation Storyboard.TargetName="BorderBrush" 
                        Storyboard.TargetProperty="Color"
                        To="Transparent"/>
      </Storyboard>
    </VisualState>

    <!--The Disabled state is omitted for brevity.-->
  </VisualStateGroup>
</VisualStateManager.VisualStateGroups>

備註

你透過傳遞 NameVisualStateVisualStateManager到 。

當 a ControlControlTemplate中使用 時VisualStateManager,控制項作者應指定該控制項期望在其TemplateVisualStateAttributeControlTemplate類別簽章中找到哪些VisualState物件。 ControlTemplate 作者定義新 VisualState 物件,並將屬性設定 Name 為屬性指定的 TemplateVisualStateAttribute.Name 值。

若要查找 WPF 所包含控制項的視覺狀態名稱,請參閱 控制項樣式與範本。 關於如何建立 a ControlTemplateVisualState 現有控制項物件的資訊,請參見 「如何建立控制項範本」。

適用於