Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何旋转直线';在保持起点固定的情况下,将端点绕一个圆旋转。在WPF中_Wpf_Animation_Graphics - Fatal编程技术网

如何旋转直线';在保持起点固定的情况下,将端点绕一个圆旋转。在WPF中

如何旋转直线';在保持起点固定的情况下,将端点绕一个圆旋转。在WPF中,wpf,animation,graphics,Wpf,Animation,Graphics,我试图围绕一个圆旋转一条直线(线条扫描)的端点,同时保持起点固定。 这是我编写的代码(基于MS帮助网站中给出的示例)。 什么都没有发生。 你能帮我吗 //XAML <Window x:Class="SPDisplay.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/

我试图围绕一个圆旋转一条直线(线条扫描)的端点,同时保持起点固定。 这是我编写的代码(基于MS帮助网站中给出的示例)。 什么都没有发生。 你能帮我吗

//XAML
<Window x:Class="SPDisplay.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:SPDisplay"
        mc:Ignorable="d"
        Title="Display" Height="1000" Width="1000">
    <WrapPanel Orientation="Vertical">

        <Canvas Name="sp" Height="500" Width="500">

            <Line Stroke="Black" StrokeThickness="2" Margin="0" Name="lineSweep"
                X1="0" Y1="0" X2="100" Y2="100"/>
        </Canvas>

        <Button Name="btnStartAnimation" Click="btnStartAnimation_Click">Start Animation</Button>
    </WrapPanel>
</Window>

//C#
public void btnStartAnimation_Click(object sender, EventArgs args)
{
    lineSweep.X1 = sp.Width / 2;
    lineSweep.Y1 = sp.Height / 2;
    lineSweep.X2 = sp.Width;
    lineSweep.Y2 = sp.Height / 2;

    // Create the animation path.
    PathGeometry animationPath = new PathGeometry();
    PathFigure pFigure = new PathFigure();
    pFigure.StartPoint = new Point(sp.Width, sp.Height / 2);
    PolyBezierSegment pBezierSegment = new PolyBezierSegment();
    int N = 100;            

    for (int i = 1; i < N; i++)
    {
        pBezierSegment.Points.Add(new Point(sp.Width / 2 * Math.Cos(2 * i * Math.PI / N), sp.Height / 2 * Math.Cos(2 * i * Math.PI / N)));
    }

    pFigure.Segments.Add(pBezierSegment);
    animationPath.Figures.Add(pFigure);

    PointAnimationUsingPath EndPointAnimation =
        new PointAnimationUsingPath();
    EndPointAnimation.PathGeometry = animationPath;
    EndPointAnimation.Duration = TimeSpan.FromSeconds(5);
    EndPointAnimation.RepeatBehavior = RepeatBehavior.Forever;

    animationPath.Freeze();

    Storyboard.SetTargetName(EndPointAnimation, "lineSweep");
    Storyboard.SetTargetProperty(EndPointAnimation,
        new PropertyPath(LineGeometry.EndPointProperty));

    // Create a Storyboard to contain and apply the animation.
    Storyboard pathAnimationStoryboard = new Storyboard();
    pathAnimationStoryboard.RepeatBehavior = RepeatBehavior.Forever;
    pathAnimationStoryboard.AutoReverse = true;
    pathAnimationStoryboard.Children.Add(EndPointAnimation);

    pathAnimationStoryboard.Begin(lineSweep);

}
//XAML
启动动画
//C#
public void btnStartAnimation_单击(对象发送者、事件args args)
{
lineSweep.X1=sp.宽度/2;
lineSweep.Y1=sp.高度/2;
lineSweep.X2=sp.宽度;
lineSweep.Y2=sp.高度/2;
//创建动画路径。
PathGeometry animationPath=新建PathGeometry();
PathFigure pFigure=新的PathFigure();
pFigure.StartPoint=新点(sp.Width,sp.Height/2);
PolyBezierSegment pBezierSegment=新的PolyBezierSegment();
int N=100;
对于(int i=1;i
使用a键并设置
角度的动画
属性:

<Line Margin="100,100,0,0" X1="0" X2="50" Stroke="Black">
  <Line.RenderTransform>
    <RotateTransform x:Name="LineRotateTransform" CenterX="0" CenterY="0" Angle="90" />
  </Line.RenderTransform>
</Line>