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 的名稱。
範例
下列範例會在 VisualStateGroup 的 中 CommonStates
Button ControlTemplate 建立 ,並針對狀態、 Normal
、 Pressed
和 MouseOver
新增 VisualState 物件。 Button也會定義 稱為 Disabled
的狀態 CommonStates
VisualStateGroup ,但範例會省略它以求簡潔。 如需整個範例,請參閱 建立 ControlTemplate 來自訂現有控制項的外觀。
<!--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 VisualState 至 VisualStateManager 來指定專案應該輸入的視覺狀態。
Control當 在 中使用 VisualStateManager 時 ControlTemplate ,控制項作者應該指定控制項預期在其類別簽章上 ControlTemplate TemplateVisualStateAttribute 尋找的物件 VisualState 。 ControlTemplate 作者會定義新的 VisualState 物件,並將 屬性設定 Name 為 屬性所 TemplateVisualStateAttribute.Name 指定的值。
若要尋找 WPF 隨附之控制項的視覺狀態名稱,請參閱 控制項樣式和範本。 如需如何為現有控制項建立 ControlTemplate 和 VisualState 物件的資訊,請參閱 建立 ControlTemplate 來自訂現有控制項的外觀。