Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/328.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
C# “绘制线”;“慢慢地”;以编程方式使用wpf_C#_Wpf_Drawing - Fatal编程技术网

C# “绘制线”;“慢慢地”;以编程方式使用wpf

C# “绘制线”;“慢慢地”;以编程方式使用wpf,c#,wpf,drawing,C#,Wpf,Drawing,我有多个点,我想用WPF画连接这些点的线,但我想看到它们画得很慢,我需要以编程的方式来做,我该怎么做? 谢谢。您可以尝试以下方法: <Grid> <Grid.Triggers> <EventTrigger RoutedEvent="MouseDown"> <EventTrigger.Actions> <BeginStoryboard>

我有多个点,我想用WPF画连接这些点的线,但我想看到它们画得很慢,我需要以编程的方式来做,我该怎么做?

谢谢。

您可以尝试以下方法:

<Grid>
    <Grid.Triggers>
        <EventTrigger RoutedEvent="MouseDown">
            <EventTrigger.Actions>
                <BeginStoryboard>
                    <Storyboard TargetName="MyLine">
                        <DoubleAnimation Storyboard.TargetProperty="X2" To="100" Duration="0:0:5"/>
                        <DoubleAnimation Storyboard.TargetProperty="Y2" To="100" Duration="0:0:5"/>
                    </Storyboard>
                </BeginStoryboard>
            </EventTrigger.Actions>
        </EventTrigger>
    </Grid.Triggers>
        <Line X1="10" Y1="10" X2="20" Y2="20" Stroke="Black" Name="MyLine"/>
</Grid>
<Grid>
    <Grid.Triggers>
        <EventTrigger RoutedEvent="Loaded">
            <EventTrigger.Actions>
                <BeginStoryboard>
                    <Storyboard>
                        <DoubleAnimation Storyboard.TargetName="Line1" Storyboard.TargetProperty="X2" To="100" Duration="0:0:5"/>
                        <DoubleAnimation Storyboard.TargetName="Line1" Storyboard.TargetProperty="Y2" To="100" Duration="0:0:5"/>
                        <DoubleAnimation Storyboard.TargetName="Line2" Storyboard.TargetProperty="X2" To="200" Duration="0:0:5" BeginTime="0:0:5"/>
                        <DoubleAnimation Storyboard.TargetName="Line2" Storyboard.TargetProperty="Y2" To="0" Duration="0:0:5" BeginTime="0:0:5"/>
                    </Storyboard>
                </BeginStoryboard>
            </EventTrigger.Actions>
        </EventTrigger>
    </Grid.Triggers>
        <Line X1="10" Y1="10" X2="10" Y2="10" Stroke="Black" Name="Line1"/>
    <Line X1="100" Y1="100" X2="100" Y2="100" Stroke="Black" Name="Line2"/>
</Grid>

当你点击这条线时,你会看到它在增长。你可以将这个故事板的开头附加到任何你想要的事件或代码上,我只是为了演示而使用了mousedown

如果要绘制多条线,可以执行以下操作:

<Grid>
    <Grid.Triggers>
        <EventTrigger RoutedEvent="MouseDown">
            <EventTrigger.Actions>
                <BeginStoryboard>
                    <Storyboard TargetName="MyLine">
                        <DoubleAnimation Storyboard.TargetProperty="X2" To="100" Duration="0:0:5"/>
                        <DoubleAnimation Storyboard.TargetProperty="Y2" To="100" Duration="0:0:5"/>
                    </Storyboard>
                </BeginStoryboard>
            </EventTrigger.Actions>
        </EventTrigger>
    </Grid.Triggers>
        <Line X1="10" Y1="10" X2="20" Y2="20" Stroke="Black" Name="MyLine"/>
</Grid>
<Grid>
    <Grid.Triggers>
        <EventTrigger RoutedEvent="Loaded">
            <EventTrigger.Actions>
                <BeginStoryboard>
                    <Storyboard>
                        <DoubleAnimation Storyboard.TargetName="Line1" Storyboard.TargetProperty="X2" To="100" Duration="0:0:5"/>
                        <DoubleAnimation Storyboard.TargetName="Line1" Storyboard.TargetProperty="Y2" To="100" Duration="0:0:5"/>
                        <DoubleAnimation Storyboard.TargetName="Line2" Storyboard.TargetProperty="X2" To="200" Duration="0:0:5" BeginTime="0:0:5"/>
                        <DoubleAnimation Storyboard.TargetName="Line2" Storyboard.TargetProperty="Y2" To="0" Duration="0:0:5" BeginTime="0:0:5"/>
                    </Storyboard>
                </BeginStoryboard>
            </EventTrigger.Actions>
        </EventTrigger>
    </Grid.Triggers>
        <Line X1="10" Y1="10" X2="10" Y2="10" Stroke="Black" Name="Line1"/>
    <Line X1="100" Y1="100" X2="100" Y2="100" Stroke="Black" Name="Line2"/>
</Grid>


当然,如果您不能在XAML中提前声明这些故事板,那么很有可能动态构建这些故事板。

您可以尝试以下方法:

<Grid>
    <Grid.Triggers>
        <EventTrigger RoutedEvent="MouseDown">
            <EventTrigger.Actions>
                <BeginStoryboard>
                    <Storyboard TargetName="MyLine">
                        <DoubleAnimation Storyboard.TargetProperty="X2" To="100" Duration="0:0:5"/>
                        <DoubleAnimation Storyboard.TargetProperty="Y2" To="100" Duration="0:0:5"/>
                    </Storyboard>
                </BeginStoryboard>
            </EventTrigger.Actions>
        </EventTrigger>
    </Grid.Triggers>
        <Line X1="10" Y1="10" X2="20" Y2="20" Stroke="Black" Name="MyLine"/>
</Grid>
<Grid>
    <Grid.Triggers>
        <EventTrigger RoutedEvent="Loaded">
            <EventTrigger.Actions>
                <BeginStoryboard>
                    <Storyboard>
                        <DoubleAnimation Storyboard.TargetName="Line1" Storyboard.TargetProperty="X2" To="100" Duration="0:0:5"/>
                        <DoubleAnimation Storyboard.TargetName="Line1" Storyboard.TargetProperty="Y2" To="100" Duration="0:0:5"/>
                        <DoubleAnimation Storyboard.TargetName="Line2" Storyboard.TargetProperty="X2" To="200" Duration="0:0:5" BeginTime="0:0:5"/>
                        <DoubleAnimation Storyboard.TargetName="Line2" Storyboard.TargetProperty="Y2" To="0" Duration="0:0:5" BeginTime="0:0:5"/>
                    </Storyboard>
                </BeginStoryboard>
            </EventTrigger.Actions>
        </EventTrigger>
    </Grid.Triggers>
        <Line X1="10" Y1="10" X2="10" Y2="10" Stroke="Black" Name="Line1"/>
    <Line X1="100" Y1="100" X2="100" Y2="100" Stroke="Black" Name="Line2"/>
</Grid>

当你点击这条线时,你会看到它在增长。你可以将这个故事板的开头附加到任何你想要的事件或代码上,我只是为了演示而使用了mousedown

如果要绘制多条线,可以执行以下操作:

<Grid>
    <Grid.Triggers>
        <EventTrigger RoutedEvent="MouseDown">
            <EventTrigger.Actions>
                <BeginStoryboard>
                    <Storyboard TargetName="MyLine">
                        <DoubleAnimation Storyboard.TargetProperty="X2" To="100" Duration="0:0:5"/>
                        <DoubleAnimation Storyboard.TargetProperty="Y2" To="100" Duration="0:0:5"/>
                    </Storyboard>
                </BeginStoryboard>
            </EventTrigger.Actions>
        </EventTrigger>
    </Grid.Triggers>
        <Line X1="10" Y1="10" X2="20" Y2="20" Stroke="Black" Name="MyLine"/>
</Grid>
<Grid>
    <Grid.Triggers>
        <EventTrigger RoutedEvent="Loaded">
            <EventTrigger.Actions>
                <BeginStoryboard>
                    <Storyboard>
                        <DoubleAnimation Storyboard.TargetName="Line1" Storyboard.TargetProperty="X2" To="100" Duration="0:0:5"/>
                        <DoubleAnimation Storyboard.TargetName="Line1" Storyboard.TargetProperty="Y2" To="100" Duration="0:0:5"/>
                        <DoubleAnimation Storyboard.TargetName="Line2" Storyboard.TargetProperty="X2" To="200" Duration="0:0:5" BeginTime="0:0:5"/>
                        <DoubleAnimation Storyboard.TargetName="Line2" Storyboard.TargetProperty="Y2" To="0" Duration="0:0:5" BeginTime="0:0:5"/>
                    </Storyboard>
                </BeginStoryboard>
            </EventTrigger.Actions>
        </EventTrigger>
    </Grid.Triggers>
        <Line X1="10" Y1="10" X2="10" Y2="10" Stroke="Black" Name="Line1"/>
    <Line X1="100" Y1="100" X2="100" Y2="100" Stroke="Black" Name="Line2"/>
</Grid>


当然,如果您不能在XAML中提前声明这些故事板,那么很有可能动态构建这些故事板。

我们是在谈论straigt线条还是也需要曲线?对于直线,请看这些直线的轴线是平行的还是任意角度的?在第一种情况下,您可能不需要为每个时间增量绘制一小段线。如果他们有任意的倾向,事情会变得更加复杂。查看此链接。它可能会帮助你。。。[以编程方式绘制和移动线条][1][1]:我尝试过故事板,但不知道如何从code@RahulRanjan我不想移动线条,我想让它们慢慢画,我的意思是看到它们在画。我们说的是直线还是曲线?对于直线,请看这些直线的轴线是平行的还是任意角度的?在第一种情况下,您可能不需要为每个时间增量绘制一小段线。如果他们有任意的倾向,事情会变得更加复杂。查看此链接。它可能会帮助你。。。[以编程方式绘制和移动线条][1][1]:我尝试过故事板,但不知道如何从code@RahulRanjan我不想移动线条,我想让它们慢慢地画,我的意思是看到它们被画出来非常感谢你,但我想从代码开始,我在这个链接上找到了我的答案非常感谢,但是我想从代码开始,我在这个链接上找到了我的答案