VisualState 類別
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
表示控制項處於特定狀態時的視覺外觀。
public ref class VisualState : System::Windows::DependencyObject
[System.Windows.Markup.ContentProperty("Storyboard")]
[System.Windows.Markup.RuntimeNameProperty("Name")]
public class VisualState : System.Windows.DependencyObject
[<System.Windows.Markup.ContentProperty("Storyboard")>]
[<System.Windows.Markup.RuntimeNameProperty("Name")>]
type VisualState = class
inherit DependencyObject
Public Class VisualState
Inherits DependencyObject
- 繼承
- 屬性
範例
下列範例會在 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>
備註
指定 VisualState 控制項在特定狀態時的外觀。 例如,按下 時 Button ,其框線可能與一般色彩不同。 類別 VisualState 具有 Storyboard 屬性,可變更控制項的外觀。 當控制項進入 屬性所 VisualState.Name 指定的狀態時,就會 Storyboard 開始。 當控制項結束狀態時,會 Storyboard 停止 。
屬性 VisualStateGroup.States 包含 VisualState 物件。 VisualStateGroup 物件會新增至 VisualStateManager.VisualStateGroups 附加屬性,其定義于 上的 FrameworkElement 。 您可以將 物件新增 VisualState 至任何 FrameworkElement ,但通常會在 的 Control 中使用 ControlTemplate 。 如需如何為現有控制項建立 ControlTemplate 和 VisualState 物件的資訊,請參閱 建立 ControlTemplate 來自訂現有控制項的外觀。 如需在 外部 ControlTemplate 使用 VisualState 物件的範例,請參閱 VisualStateManager 類別。
建構函式
VisualState() |
初始化 VisualState 類別的新執行個體。 |
屬性
DependencyObjectType |
取得包裝 DependencyObjectType 這個實例 CLR 型別的 。 (繼承來源 DependencyObject) |
Dispatcher |
取得與這個 Dispatcher 關聯的 DispatcherObject。 (繼承來源 DispatcherObject) |
IsSealed |
取得值,這個值表示此執行個體目前是否已密封 (唯讀)。 (繼承來源 DependencyObject) |
Name |
取得或設定 VisualState 的名稱。 |
Storyboard |
取得或設定 Storyboard,可定義控制項處於 VisualState 所表示之狀態時的外觀。 |