public void Transform(double from, double to, FrameworkElement target, double duration)
{
Storyboard sb = new Storyboard();
ScaleTransform scale = new ScaleTransform();
target.RenderTransform = scale;
target.RenderTransformOrigin = new Point(0.5, 0.5);
DoubleAnimation dX = new DoubleAnimation();
dX.To = to;
dX.From = from;
dX.EasingFunction = new PowerEase() { EasingMode = EasingMode.EaseOut };
dX.Duration = TimeSpan.FromSeconds(duration);
sb.Children.Add(dX);
DoubleAnimation dY = new DoubleAnimation();
dY.To = to;
dY.From = from;
dY.EasingFunction = new PowerEase() { EasingMode = EasingMode.EaseOut };
dY.Duration = TimeSpan.FromSeconds(duration);
sb.Children.Add(dY);
DoubleAnimation dao = new DoubleAnimation();
dao.To = to;
dao.Duration = TimeSpan.FromSeconds(duration);
sb.Children.Add(dao);
Storyboard.SetTarget(dX, scale);
Storyboard.SetTargetProperty(dX, new PropertyPath("ScaleX"));
Storyboard.SetTarget(dY, scale);
Storyboard.SetTargetProperty(dY, new PropertyPath("ScaleY"));
Storyboard.SetTarget(dao, target);
Storyboard.SetTargetProperty(dao, new PropertyPath("Opacity"));
sb.Begin();
}
调用方法 如下
Transform(1, 0.75, _item, 0.2);
_item 是listboxitem 类型