VisualStateGroup 類別

定義

包含互斥的 VisualState 物件與 VisualTransition 物件,用於從某一個狀態移動至另一個狀態。

public ref class VisualStateGroup : System::Windows::DependencyObject
[System.Windows.Markup.ContentProperty("States")]
[System.Windows.Markup.RuntimeNameProperty("Name")]
public class VisualStateGroup : System.Windows.DependencyObject
[<System.Windows.Markup.ContentProperty("States")>]
[<System.Windows.Markup.RuntimeNameProperty("Name")>]
type VisualStateGroup = class
    inherit DependencyObject
Public Class VisualStateGroup
Inherits DependencyObject
繼承
屬性

範例

下列範例會為 Button 包含一個 Grid 的 建立簡單 ControlTemplate 。 它也包含名為 CommonStatesVisualStateGroup ,其會 MouseOver 定義 和 Normal 狀態。 VisualStateGroup也有 , VisualTransition 指定當使用者將滑鼠指標移至 上方時,需要一半秒 Grid 的時間,才能將 變更為綠色。 Button

<ControlTemplate TargetType="Button">
  <Grid >
    <VisualStateManager.VisualStateGroups>
      <VisualStateGroup x:Name="CommonStates">

        <VisualStateGroup.Transitions>

          <!--Take one half second to trasition to the MouseOver state.-->
          <VisualTransition To="MouseOver" 
            GeneratedDuration="0:0:0.5"/>
        </VisualStateGroup.Transitions>

        <VisualState x:Name="Normal" />

        <!--Change the SolidColorBrush, ButtonBrush, to red when the
            mouse is over the button.-->
        <VisualState x:Name="MouseOver">
          <Storyboard>
            <ColorAnimation Storyboard.TargetName="ButtonBrush" 
              Storyboard.TargetProperty="Color" To="Red" />
          </Storyboard>
        </VisualState>
      </VisualStateGroup>
    </VisualStateManager.VisualStateGroups>
    <Grid.Background>
      <SolidColorBrush x:Name="ButtonBrush" Color="Green"/>
    </Grid.Background>
  </Grid>
</ControlTemplate>

備註

每個 VisualStateGroup 都包含 物件的集合 VisualStateVisualState包含 物件的集合 Storyboard ,指定控制項在特定狀態時控制項的外觀變更方式。 例如, Button 當按下時,它的外觀可能會與未按下時稍有不同。 定義的 Button 兩種狀態會對應至按下 ("Pressed") ,以及未 ("Normal") 時。

您可以在 控制項上設定 VisualStateManager.VisualStateGroups 附加屬性,以新增 VisualState 至 控制項。 您會將彼此互斥的狀態放在相同的 VisualStateGroup 中。 例如, CheckBox 有兩 VisualStateGroup 個 物件。 其中一個包含狀態、 NormalMouseOver Pressed 、 和 Disabled 。 另一個包含狀態、 CheckedUnCheckedIndeterminateCheckBox可以同時處於狀態 MouseOverUnChecked 但不能同時處於 MouseOverPressed 狀態。

雖然您可以將物件新增 VisualState 至任何元素,但它們是讓其他人重新定義 的視覺行為 Control 特別有用的方法。 如果您建立使用 的 ControlTemplate 自訂控制項,您可以藉由在其類別定義上加入 , TemplateVisualStateAttribute 來指定控制項可以位於哪些狀態。 然後,為控制項建立新 ControlTemplate 物件的任何人都可以將物件新增 VisualState 至範本。 TemplateVisualStateAttribute可讓設計工具公開控制項的狀態,例如Visual Studio和Blend for Visual Studio。 相同 TemplateVisualStateAttribute.GroupName 狀態屬於相同的 VisualStateGroup

如需如何在 中使用 VisualStateGroup ControlTemplate 物件的詳細資訊,請參閱 建立 ControlTemplate 來自訂現有控制項的外觀。 如需如何建立使用 之 VisualStateManager 控制項的詳細資訊,請參閱 建立具有可自訂外觀的控制項

Transitions屬性包含 VisualTransition 物件,這些物件會在 中 VisualStateGroup 定義的狀態之間轉換控制項時套用。

建構函式

VisualStateGroup()

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

屬性

CurrentState

取得目前套用至控制項的 VisualState

DependencyObjectType

取得包裝 DependencyObjectType 這個實例 CLR 型別的 。

(繼承來源 DependencyObject)
Dispatcher

取得與這個 Dispatcher 關聯的 DispatcherObject

(繼承來源 DispatcherObject)
IsSealed

取得值,這個值表示此執行個體目前是否已密封 (唯讀)。

(繼承來源 DependencyObject)
Name

取得或設定 VisualStateGroup 的名稱。

States

取得互斥 VisualState 物件的集合。

Transitions

取得 VisualTransition 物件的集合。

方法

CheckAccess()

判斷呼叫的執行是否可以存取這個 DispatcherObject

(繼承來源 DispatcherObject)
ClearValue(DependencyProperty)

清除屬性的區域數值。 要清除的屬性是由 DependencyProperty 識別項所指定。

(繼承來源 DependencyObject)
ClearValue(DependencyPropertyKey)

清除唯讀屬性的區域數值。 要清除的屬性是由 DependencyPropertyKey 所指定。

(繼承來源 DependencyObject)
CoerceValue(DependencyProperty)

強制轉型所指定相依性屬性的值。 完成方式是叫用存在於呼叫 DependencyObject 之相依性屬性的屬性中繼資料中所指定的任何 CoerceValueCallback 函式。

(繼承來源 DependencyObject)
Equals(Object)

判斷提供的 DependencyObject 和目前的 DependencyObject 是否相等。

(繼承來源 DependencyObject)
GetHashCode()

取得這個 DependencyObject 的雜湊碼。

(繼承來源 DependencyObject)
GetLocalValueEnumerator()

建立特定的列舉值,以判斷哪些相依性屬性在此 DependencyObject 上具有本機設定的值。

(繼承來源 DependencyObject)
GetType()

取得目前執行個體的 Type

(繼承來源 Object)
GetValue(DependencyProperty)

傳回 DependencyObject 的這個執行個體上之相依性屬性的目前有效值。

(繼承來源 DependencyObject)
InvalidateProperty(DependencyProperty)

重新評估指定相依性屬性的有效值。

(繼承來源 DependencyObject)
MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
OnPropertyChanged(DependencyPropertyChangedEventArgs)

每當這個 DependencyObject 上任何相依性屬性的有效值已更新時叫用。 已變更的特定相依性屬性會在事件資料中報告。

(繼承來源 DependencyObject)
ReadLocalValue(DependencyProperty)

傳回相依性屬性的區域值 (如果存在)。

(繼承來源 DependencyObject)
SetCurrentValue(DependencyProperty, Object)

設定相依性屬性的值,而不需要變更其值來源。

(繼承來源 DependencyObject)
SetValue(DependencyProperty, Object)

設定相依性屬性的區域值 (由相依性屬性的識別碼所指定)。

(繼承來源 DependencyObject)
SetValue(DependencyPropertyKey, Object)

設定唯讀相依性屬性的區域數值 (由相依性屬性的 DependencyPropertyKey 識別項所指定)。

(繼承來源 DependencyObject)
ShouldSerializeProperty(DependencyProperty)

傳回值,這個值表示序列化程序是否應該序列化所提供相依性屬性的值。

(繼承來源 DependencyObject)
ToString()

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

(繼承來源 Object)
VerifyAccess()

請強制執行可以存取這個 DispatcherObject 的呼叫執行緒。

(繼承來源 DispatcherObject)

事件

CurrentStateChanged

在控制項轉換至不同狀態之後發生。

CurrentStateChanging

在控制項開始轉換至不同狀態時發生。

適用於