VisualStateGroup.States 屬性

定義

取得互斥 VisualState 物件的集合。

C#
public System.Collections.IList States { get; }

屬性值

IList

互斥 VisualState 物件的集合。

範例

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

XAML
<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>

適用於

產品 版本
.NET Framework 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8
Windows Desktop 3.0, 3.1, 5, 6, 7