1

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

4

1 回答 1

1

你可以尝试这样的事情:

<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 中提前声明这些情节提要,则很有可能即时构建这些情节提要。

于 2012-11-02T17:11:17.423 回答