首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何将wpf中的动画缩放到窗口的大小

如何将wpf中的动画缩放到窗口的大小
EN

Stack Overflow用户
提问于 2017-04-05 19:16:06
回答 1查看 328关注 0票数 0

我想要一个动画,适应窗口的大小。

我使用code example复制了点动画中的代码,并对其进行了一些修改。我添加了一条新的路径,这样我就可以看到圆圈所沿着的路径。我还为圆圈做了一条更简单的路径。

我可以将Stretch="Fill"添加到显示圆路径的路径中。现在,路径的大小随窗口大小而变化。如何对动画的路径执行此操作,并使其遵循与所示路径相同的路径?

代码语言:javascript
运行
复制
<Window x:Class="TestPointAlongPath.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:PresentationOptions="http://schemas.microsoft.com/winfx/2006/xaml/presentation/options" 
        mc:Ignorable="PresentationOptions"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <Path Data="M1,200 L275,1 L345,200" Margin="15,15,15,15" 
                        Stroke="#BF708090" StrokeThickness="3" />

        <Path Fill="Blue" Margin="15,15,15,15" >
            <Path.Data>

                <!-- The EllipseGemetry specifies the shape and position of the Ellipse. The
            Center property is animated, causing the Ellipse to animate across the screen-->
                <EllipseGeometry x:Name="MyAnimatedEllipseGeometry"
                Center="10,100" RadiusX="15" RadiusY="15"/>
            </Path.Data>
            <Path.Triggers>
                <EventTrigger RoutedEvent="Path.Loaded">
                    <BeginStoryboard Name="MyBeginStoryboard">
                        <Storyboard>

                            <!-- Animates the ellipse along the path. -->
                            <PointAnimationUsingPath
                    Storyboard.TargetName="MyAnimatedEllipseGeometry"
                    Storyboard.TargetProperty="Center"
                    Duration="0:0:7.5" 
                    RepeatBehavior="Forever" >
                                <PointAnimationUsingPath.PathGeometry>
                                    <PathGeometry 
                        Figures="M1,200 L275,1 L345,200"
                        PresentationOptions:Freeze="True">
                                        <PathGeometry.Transform>
                                            <ScaleTransform ScaleX="{Binding ActualWidth, RelativeSource={RelativeSource AncestorType=Grid}}"
                                                            ScaleY="{Binding ActualHeight, RelativeSource={RelativeSource AncestorType=Grid}}"/>
                                        </PathGeometry.Transform>
                                    </PathGeometry>
                                </PointAnimationUsingPath.PathGeometry>
                            </PointAnimationUsingPath>
                        </Storyboard>
                    </BeginStoryboard>
                </EventTrigger>
            </Path.Triggers>
        </Path>
    </Grid>
</Window>
EN

回答 1

Stack Overflow用户

发布于 2017-04-06 01:28:15

您托管了Canvas下的路径。Canvas需要精确的位置。请改用栅格。所有的路径都将位于另一条路径之上。然后,您可以使用它们的Stretch属性来计算它们的拉伸。此外,您也不需要Page元素。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43229601

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档