0

我正在开发一个自定义的类似网格的面板,其中一个元素可以缩放。首先,所有元素都具有相同的大小。如果一个应该被缩放,它会得到两倍于以前的大小,其余元素均匀地填充剩余空间(因此,除了与缩放元素在同一行或列中的元素之外,所有元素的高度和宽度都会变小,在同一行获得更小的宽度和缩放的高度等)。

一切正常,直到我为缩放添加动画。

我正在计算测量过程中每个元素的大小,起初我用计算出的大小来测量每个元素。元素本身的大小为 NaN,直到它们被缩放。我通过将它们设置为最终大小来缩放它们,然后开始从旧到新的双重动画。

但是,当我添加动画时,仅在第一个动画步骤中调用了测量和排列。当我尝试使用 availableSize 或无限大小来测量元素时,动画效果很好,但是元素在它们变小的维度上没有正确调整大小。

有谁知道如何解决其中任何一种行为?

问候托拜厄斯

编辑:动画代码:

        Size normalSize = GetNormalElementSize(new Size(ActualWidth, ActualHeight));

        DoubleAnimation widthAnimation = new DoubleAnimation
        {
            From = normalSize.Width,
            To = normalSize.Width * 2,
            Duration = TimeSpan.FromMilliseconds(750),
            EasingFunction = new QuadraticEase { EasingMode = EasingMode.EaseInOut }
        };

        DoubleAnimation heightAnimation = new DoubleAnimation
        {
            From = normalSize.Height,
            To = normalSize.Height * 2,
            Duration = TimeSpan.FromMilliseconds(750),
            EasingFunction = new QuadraticEase { EasingMode = EasingMode.EaseInOut }
        };

        ZoomedElement.Height = normalSize.Height;
        ZoomedElement.Width = normalSize.Width;

        Storyboard.SetTargetProperty(widthAnimation, new PropertyPath(FrameworkElement.WidthProperty));
        Storyboard.SetTarget(widthAnimation, ZoomedElement);
        Storyboard.SetTargetProperty(heightAnimation, new PropertyPath(FrameworkElement.HeightProperty));
        Storyboard.SetTarget(heightAnimation, ZoomedElement);

        Storyboard zoomStoryboard = new Storyboard();
        zoomStoryboard.Children.Add(heightAnimation);
        zoomStoryboard.Children.Add(widthAnimation);
        zoomStoryboard.CurrentTimeInvalidated += zoomStoryboard_CurrentTimeInvalidated;
        zoomStoryboard.Begin();
4

1 回答 1

0

我猜您正在使用 RenderTransformation,请尝试使用 LayoutTransformation。

于 2014-01-02T08:01:14.783 回答