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 属性以指定转换的发生方式。 例如,可以指定缓动函数来加速或减速转换。 有关详细信息,请参阅 缓动函数

适用于