VisualState.Storyboard 屬性

定義

取得或設定 Storyboard,可定義控制項處於 VisualState 所表示之狀態時的外觀。

public:
 property System::Windows::Media::Animation::Storyboard ^ Storyboard { System::Windows::Media::Animation::Storyboard ^ get(); void set(System::Windows::Media::Animation::Storyboard ^ value); };
public System.Windows.Media.Animation.Storyboard Storyboard { get; set; }
member this.Storyboard : System.Windows.Media.Animation.Storyboard with get, set
Public Property Storyboard As Storyboard

屬性值

Storyboard

Storyboard,可定義控制項處於 VisualState 所表示之狀態時的外觀。 預設為 null

範例

下列範例會為 包含一個 GridButton 建立簡單 ControlTemplate 。 呼叫 VisualState MouseOver 的 具有Storyboard,當使用者將滑鼠放在 上方 Button 時,會將 的 Grid 色彩從綠色變更為紅色。 包含 VisualState 呼叫 Normal 的 ,如此一來,當使用者將滑鼠移離按鈕時,會 Grid 返回綠色。

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

備註

當控制項進入 屬性所 VisualState.Name 指定的狀態時,就會 Storyboard 開始。 當控制項結束狀態時,會 Storyboard 停止 。

適用於