[英]Can I separately bind the X and Y properties of Point at xaml?
[英]Can I animate the X- and Y- coordinates of a WPF Bezier curve control point separately?
我正在尝试在WPF中创建动画的Bezier曲线,我打算通过平滑且缓慢地为端点和控制点设置动画来使它“活着”。 我不希望任何点都遵循明显的可预测路径,例如简单的椭圆或圆形。
通过使用两个不同的DoubleAnimation(例如分别对Canvas.Top和Canvas.Left进行动画处理),我在其他更简单的动画中也取得了成功。
但是在Bezier片段中,控制点和端点以Point()实例的形式给出,我似乎无法弄清楚如何分别为这些Point实例的X和Y坐标设置动画。 尽管(例如)BezierSegment.ControlPoint2有一个PropertyPath,但该点的X坐标似乎没有一个。
我已经看过通过继承PointAnimationBase来实现自己的自定义点动画,但是很难浏览文档以了解它们如何联系在一起-那里没有很多示例。
从PointAnimationBase继承的自定义动画是否正确,我该如何将其绑定到BezierSegment的控制点? 还是应该看完全不同的东西才能达到效果?
自定义PointAnimation似乎是一种明智的方法。
以下XAML显示了标准PointAnimation如何动画化QuadraticBezierSegment的Point1
属性:
<Path Stroke="Black" StrokeThickness="3">
<Path.Data>
<PathGeometry>
<PathGeometry.Figures>
<PathFigure StartPoint="100,200">
<PathFigure.Segments>
<QuadraticBezierSegment Point2="200,200"/>
</PathFigure.Segments>
</PathFigure>
</PathGeometry.Figures>
</PathGeometry>
</Path.Data>
<Path.Triggers>
<EventTrigger RoutedEvent="Loaded">
<BeginStoryboard>
<Storyboard>
<PointAnimation
Storyboard.TargetProperty="Data.Figures[0].Segments[0].Point1"
From="150,200" To="150,0" Duration="0:0:1"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Path.Triggers>
</Path>
自定义PointAnimation将要求您实现GetCurrentValueCore方法并返回一个点实例,该实例表示动画的当前值,具体取决于animationClock参数提供的当前时间:
public class MyPointAnimation : PointAnimationBase
{
protected override Point GetCurrentValueCore(
Point defaultOriginValue, Point defaultDestinationValue,
AnimationClock animationClock)
{
double x = ... // as function of animationClock
double y = ... // as function of animationClock
return new Point(x, y);
}
protected override Freezable CreateInstanceCore()
{
return new MyPointAnimation();
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.