【发布时间】:2014-01-19 11:34:03
【问题描述】:
我正在开发一个自定义的类似网格的面板,其中一个元素可以缩放。 首先,所有元素都具有相同的大小。如果一个应该缩放,它会得到两倍于以前的大小,其余元素均匀地填充剩余空间(因此,除了与缩放元素在同一行或列中的元素之外,所有元素的高度和宽度都会变小,在同一行得到更小的宽度和缩放的高度等)。
在我为缩放添加动画之前一切正常。
我正在计算测量过程中每个元素的大小,起初我用计算出的大小来测量每个元素。元素本身的大小为 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();
【问题讨论】:
-
把那个添加动画的代码放上去,对你有帮助。
-
我在上面添加了我正在使用的代码
标签: wpf layout wpf-controls measureoverride arrangeoverride