从网格中心扩展动画

发布于 2025-02-12 14:58:43 字数 1240 浏览 0 评论 0原文

我正在制作一个应用程序,当它打开时它会扩展。 但是它正在从网格的侧面扩展,但我希望它从中心扩展。 这是XAML代码

    <Window.Resources>
        <Storyboard x:Key="ExpandingAnimation">
            <DoubleAnimationUsingKeyFrames Storyboard.TargetName="ExpandingGrid" Storyboard.TargetProperty="(FrameworkElement.Height)">
                <EasingDoubleKeyFrame KeyTime="00:00:00" Value="0"></EasingDoubleKeyFrame>
                <EasingDoubleKeyFrame KeyTime="00:00:01" Value="0"></EasingDoubleKeyFrame>
                <EasingDoubleKeyFrame KeyTime="00:00:03" Value="222"></EasingDoubleKeyFrame>
            </DoubleAnimationUsingKeyFrames>
        </Storyboard>
    </Window.Resources>

<Grid x:Name="ExpandingGrid"> </Grid>

这是c#代码

        public MainWindow()
        {
            InitializeComponent();
            Storyboard ExpandingAnime = (Storyboard)TryFindResource("ExpandingAnimation");
            ExpandingAnime.Begin();
        }

这是一个外观的示例。

I am making an app where when it opens it expands.
But it is expanding from the side of the grid but I want it to expand from the center.
Here is the xaml code

    <Window.Resources>
        <Storyboard x:Key="ExpandingAnimation">
            <DoubleAnimationUsingKeyFrames Storyboard.TargetName="ExpandingGrid" Storyboard.TargetProperty="(FrameworkElement.Height)">
                <EasingDoubleKeyFrame KeyTime="00:00:00" Value="0"></EasingDoubleKeyFrame>
                <EasingDoubleKeyFrame KeyTime="00:00:01" Value="0"></EasingDoubleKeyFrame>
                <EasingDoubleKeyFrame KeyTime="00:00:03" Value="222"></EasingDoubleKeyFrame>
            </DoubleAnimationUsingKeyFrames>
        </Storyboard>
    </Window.Resources>

<Grid x:Name="ExpandingGrid"> </Grid>

And this is the c# code

        public MainWindow()
        {
            InitializeComponent();
            Storyboard ExpandingAnime = (Storyboard)TryFindResource("ExpandingAnimation");
            ExpandingAnime.Begin();
        }

Here is an example of how it looks like.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

城歌 2025-02-19 14:58:43

您可以使用scaletransform并为其scalexscale> scaley属性进行动画:

<Storyboard x:Key="ExpandingAnimation">
    <Storyboard>
        <DoubleAnimation
            Storyboard.TargetName="MyScaleTransform"
            Storyboard.TargetProperty="(ScaleTransform.ScaleX)"
            From="0" To ="1" Duration="0:0:3"/>
        <DoubleAnimation
            Storyboard.TargetName="MyScaleTransform"
            Storyboard.TargetProperty="(ScaleTransform.ScaleY)"
            From="0" To ="1" Duration="0:0:3"/>
    </Storyboard>
</Storyboard>
...
<Grid x:Name="ExpandingGrid"
              RenderTransformOrigin="0.5,0.5"
              Height="222">
    <Grid.RenderTransform>
        <ScaleTransform x:Name="MyScaleTransform" ScaleX="0" ScaleY ="0" />
    </Grid.RenderTransform>
</Grid>

You could use a ScaleTransform and animate its ScaleX and ScaleY properties:

<Storyboard x:Key="ExpandingAnimation">
    <Storyboard>
        <DoubleAnimation
            Storyboard.TargetName="MyScaleTransform"
            Storyboard.TargetProperty="(ScaleTransform.ScaleX)"
            From="0" To ="1" Duration="0:0:3"/>
        <DoubleAnimation
            Storyboard.TargetName="MyScaleTransform"
            Storyboard.TargetProperty="(ScaleTransform.ScaleY)"
            From="0" To ="1" Duration="0:0:3"/>
    </Storyboard>
</Storyboard>
...
<Grid x:Name="ExpandingGrid"
              RenderTransformOrigin="0.5,0.5"
              Height="222">
    <Grid.RenderTransform>
        <ScaleTransform x:Name="MyScaleTransform" ScaleX="0" ScaleY ="0" />
    </Grid.RenderTransform>
</Grid>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文