故事板动画中的错误?

故事板动画中的错误?

问题描述:

昨天我没有得到答案,但也许我对问题的理解不够深入,无法提出正确的问题.

Yesterday I failed to get an answer, but perhaps I did not understand the problem deep enough to formulate correct question.

这个故事是关于为 ListBox 高度设置动画的.以下是后续截图:

The story is about animating ListBox height. Here are subsequent screenshots:

a) "Medium" 是一个文本块

a) "Medium" is a TextBlock

b) "Medium" TextBlock 被 ListBox 替换.用户选择一个项目.这将启动 ListBox.Height 的动画.动画完成后,ListBox 被替换为原来的 TextBlock.(忽略数据的差异.当我不得不处理渲染帧时,图像的收集是一个痛苦的过程.其中一张图像是为不同的记录拍摄的.)

b) "Medium" TextBlock gets replaced by a ListBox. The user selects an item. That initiates animation of the ListBox.Height. After the animation completes, the ListBox is replaced by original TextBlock. (Disregard the differences in data. Collection of the images was a painfull process, when I had to work with rendered frames. One of the images was shot for different record.)

此序列偶尔会闪烁.我想知道发生了什么,过了一会儿我得到了这个截图:

This sequence works with occasional flickering. I wanted to know what's going on and after a while I got this screenshot:

你看到的是 Storyboard.Completed 事件被拦截后的第一帧.据我了解,这是 Storyboard 的最终结果.

What you see is the first frame after Storyboard.Completed event was intercepted. As far I understand this is the final result from the Storyboard.

注意事项:

  • 此时我检查了可视化树,没有发现任何可疑的东西.

  • I checked the visual tree at this instant and did not find anything suspiceous.

这只是发生的影响之一.另一个常见的情况是调整大小的带有蓝色阴影的 1 行 ListBox;在这种情况下,列表框上方的所有元素都会消失.第三种可能是整个屏幕上的对角红线.

This is just one of the effects that happen. Another frequent case is a resized 1-line ListBox with blue hatching; in this case all elements above the listbox disappear. 3rd possibility is a diagonal red line over the whole screen.

这是定义故事板的代码:

Here is the code defining the Storyboard:

    private Storyboard GetDropDownAnimation(double from, double to)
    {
        double secs = this.IsExpanded ? 0.2 : 0.4;
        CubicEase ease = new CubicEase() { EasingMode = EasingMode.EaseInOut };
        DoubleAnimation animation = new DoubleAnimation()
        {
            Duration = new Duration(TimeSpan.FromSeconds(secs)),
            From = from,
            To = to,
            FillBehavior = FillBehavior.HoldEnd,
            EasingFunction = ease
        };
        Debug.WriteLine("Animation Height {0} -> {1}", from, to);

        Storyboard.SetTarget(animation, this);
        Storyboard.SetTargetProperty(animation, new PropertyPath("Height"));

        Storyboard sb = new Storyboard();
        sb.Children.Add(animation);
        return sb;
    }

我可以解释完成的其他技巧(很长一段时间我确信问题出在那里),但看起来问题只与动画本身有关.

I could explain other tricks done (for a long time I was convinced that the problem is there), but it looks like the problem concerns only the animation itself.

有人能解释一下这是怎么回事吗?

Anybody able to explain what's going on?

在继续这样做之前先看看这些吧让你的生活更轻松:)

也就是说,看看动画的起始值(来自),看看它是否正确.

That said, have a look at the starting value of the animation (from) and see if it is correct.

如果一切都失败了,你可以从一个完全透明的列表框开始.

If all else fails you could start with a fully transparent listbox.