我需要使用 ScaleTransform 在 C# 中缩放 EllipseGeometry,但它不起作用。这是代码:
XAML:
<Image x:Name="rock" Stretch="None">
<Image.Clip>
<EllipseGeometry x:Name="rockClip" RadiusX="100" RadiusY="100" Center="200,150">
<EllipseGeometry.Transform>
<ScaleTransform/>
</EllipseGeometry.Transform>
</EllipseGeometry>
</Image.Clip>
</Image>
C#:
DoubleAnimation scaleX = new DoubleAnimation();
scaleX.BeginTime = TimeSpan.FromMilliseconds(fromMills);
scaleX.Duration = new Duration(TimeSpan.FromMilliseconds(2000));
scaleX.From = 0.0;
scaleX.To = 1.0;
scaleX.SetValue(Storyboard.TargetProperty, rockClip);
scaleX.SetValue(Storyboard.TargetPropertyProperty, new PropertyPath("(EllipseGeometry.Transform).(ScaleTransform.ScaleX)"));
DoubleAnimation scaleY = new DoubleAnimation();
scaleY.BeginTime = TimeSpan.FromMilliseconds(fromMills);
scaleY.Duration = new Duration(TimeSpan.FromMilliseconds(2000));
scaleY.From = 0.0;
scaleY.To = 1.0;
scaleY.SetValue(Storyboard.TargetProperty, rockClip);
scaleY.SetValue(Storyboard.TargetPropertyProperty, new PropertyPath("(EllipseGeometry.Transform).(ScaleTransform.ScaleY)"));
Storyboard storyboard = new Storyboard();
storyboard.Children.Add(scaleX);
storyboard.Children.Add(scaleY);
storyboard.Completed += storyboard_Completed;
animation.Begin();
storyboard_Completed 事件被触发,但 EllipseGeometry 上没有动画。
问题出在哪里?
我只能以这种方式为 EllipseGeometry 设置动画:
DoubleAnimation scale = new DoubleAnimation();
scale.From = 0;
scale.To = 40;
scale.Duration = new Duration(TimeSpan.FromMilliseconds(5000));
rockClip.BeginAnimation(EllipseGeometry.RadiusXProperty, scale);
rockClip.BeginAnimation(EllipseGeometry.RadiusYProperty, scale);
我需要把这个 DoubleAnimation 放在 Storyboard 中,但我不知道怎么做。
谢谢。