共用方式為


VisualTransition.GeneratedEasingFunction 屬性

定義

取得或設定用於轉換狀態的自訂數學公式。

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

屬性值

用於轉換狀態的自訂數學公式。

範例

下列範例會建立 , VisualTransition 當使用者按下 滑鼠按鍵上方 Canvas 時,會導致 Rectangle 垂直移動 。 此範例會將 GeneratedEasingFunction 屬性設定為 BounceEase 物件,使 Rectangle 在到達其目的地時出現退回。 當使用者 VisualTransition 放開按鈕時所使用的 ,有另一個 BounceEase 物件會導致 Rectangle 在返回其原始位置之前退回。

<Canvas Name="canvasRoot" Background="Tan" Width="100" Height="250"
        MouseDown="Canvas_MouseEvent" MouseUp="Canvas_MouseEvent">

  <VisualStateManager.VisualStateGroups>
    <VisualStateGroup Name="CanvasStates">
      <VisualState Name="CanvasButtonUp" />
      <VisualState Name="CanvasButtonDown">
        <Storyboard>
          <!--The VisualTransition is responsible for animating the
              Rectangle falling. This DoubleAnitmation specifies where
              the Rectangle is when the animation completes.-->
          <DoubleAnimation To="200" 
                           Storyboard.TargetName="myRectangle" 
                           Storyboard.TargetProperty="(Canvas.Top)"/>
        </Storyboard>
      </VisualState>
      <VisualStateGroup.Transitions>
        <VisualTransition To="CanvasButtonUp" GeneratedDuration="00:00:01">
          <VisualTransition.GeneratedEasingFunction>
            <BounceEase Bounces="4" EasingMode="EaseIn" Bounciness="2"/>
          </VisualTransition.GeneratedEasingFunction>
        </VisualTransition>
        <VisualTransition To="CanvasButtonDown" GeneratedDuration="00:00:01">
          <VisualTransition.GeneratedEasingFunction>
            <BounceEase Bounces="3" EasingMode="EaseOut" Bounciness="2"/>
          </VisualTransition.GeneratedEasingFunction>
        </VisualTransition>

      </VisualStateGroup.Transitions>
    </VisualStateGroup>
  </VisualStateManager.VisualStateGroups>

  <Rectangle Name="myRectangle"  
             Canvas.Top="30" Canvas.Left="30"
             Fill="Blue" Width="30" Height="30"/>
</Canvas>

下列範例顯示 和 MouseUp 事件的事件處理常式 MouseDown 。 此範例會 GoToElementState 呼叫 方法來變更 VisualState 畫布的 。

bool isMouseDown;

private void Canvas_MouseEvent(object sender, MouseEventArgs e)
{
    isMouseDown = !isMouseDown;

    if (isMouseDown)
    {
        VisualStateManager.GoToElementState(canvasRoot, "CanvasButtonDown", true);
    }
    else
    {
        VisualStateManager.GoToElementState(canvasRoot, "CanvasButtonUp", true);
    }
}
Private isMouseDown As Boolean

Private Sub Canvas_MouseEvent(ByVal sender As Object, ByVal e As MouseEventArgs)

    isMouseDown = Not isMouseDown

    If isMouseDown Then
        VisualStateManager.GoToElementState(canvasRoot, "CanvasButtonDown", True)
    Else

        VisualStateManager.GoToElementState(canvasRoot, "CanvasButtonUp", True)
    End If
End Sub

備註

您可以設定 GeneratedEasingFunction 屬性來指定轉換的發生方式。 例如,您可以指定 Easing 函式來加速或減速轉換。 如需詳細資訊,請參閱 Easing 函式

適用於