VisualState.Name 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得或設定 的名稱。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>
備註
你透過傳遞 Name 的 VisualStateVisualStateManager到 。
當 a Control 在 ControlTemplate中使用 時VisualStateManager,控制項作者應指定該控制項期望在其TemplateVisualStateAttributeControlTemplate類別簽章中找到哪些VisualState物件。 ControlTemplate 作者定義新 VisualState 物件,並將屬性設定 Name 為屬性指定的 TemplateVisualStateAttribute.Name 值。
若要查找 WPF 所包含控制項的視覺狀態名稱,請參閱 控制項樣式與範本。 關於如何建立 a ControlTemplate 和 VisualState 現有控制項物件的資訊,請參見 「如何建立控制項範本」。