在画布上我有一个由RotateTransform通过动画旋转的椭圆。我希望添加一条线,其一端连接到椭圆上的一个点。我可以以某种方式绑定到椭圆上的一个点吗?
答案 0 :(得分:1)
您可以同时为Ellipse和线设置动画,如下所示:
<Canvas xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Canvas.Resources>
<PathGeometry x:Key="lineEndPath">
<PathFigure StartPoint="25,50">
<ArcSegment IsLargeArc="True" Point="100,50" Size="25,25" SweepDirection="Clockwise"/>
<ArcSegment IsLargeArc="True" Point="25,50" Size="25,25" SweepDirection="Clockwise"/>
</PathFigure>
</PathGeometry>
</Canvas.Resources>
<Canvas.Triggers>
<EventTrigger RoutedEvent="Canvas.Loaded">
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Duration="0:0:5" From="0" RepeatBehavior="Forever" Storyboard.TargetName="rotTF" Storyboard.TargetProperty="Angle" To="360"/>
<PointAnimationUsingPath Duration="0:0:5" PathGeometry="{StaticResource lineEndPath}" RepeatBehavior="Forever" Storyboard.TargetName="lineEndPoint" Storyboard.TargetProperty="Point"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Canvas.Triggers>
<Ellipse Width="75" Height="50" Canvas.Left="25" Canvas.Top="25" Stroke="Black">
<Ellipse.RenderTransform>
<RotateTransform x:Name="rotTF" CenterX="37.5" CenterY="25"/>
</Ellipse.RenderTransform>
</Ellipse>
<Path Stroke="Black" StrokeThickness="1.0">
<Path.Data>
<PathGeometry>
<PathFigure StartPoint="0,0">
<LineSegment x:Name="lineEndPoint"/>
</PathFigure>
</PathGeometry>
</Path.Data>
</Path>
<Path Data="{StaticResource lineEndPath}" Stroke="Black" StrokeDashArray="2,0,0" StrokeThickness="1.0"/>
</Canvas>
我们使用LineSegment为PointAnimationUsingPath的一端设置动画,并将路径设置为圆圈(由虚线显示)。
答案 1 :(得分:0)
我不确定问题是什么。您可以在Canvas中添加另一个正确排列的元素,并将变换应用到将旋转这两个元素的画布吗?
如果你问是否有任何方法可以在线上说“排队”,那么不,你现在就不能这样做。对于像这样的复杂布局,您可以使用KaXaml / Bland进行试验和错误,或者使用Illustrator进行布局,然后导出到XAML。
答案 2 :(得分:0)
假设我理解正确,你将不得不弄清楚改变你的线的终点的数学。对不起,不要随便知道公式,但你基本上会在椭圆上找到你的点,然后根据旋转的角度找出它的位置,然后用这些信息改变你的线的终点。
答案 3 :(得分:0)
为了通过Line连接边缘的两个元素,我使用了Connecting two WPF canvas elements by a line, without using anchors?中解释的边界框方法。