为什么我的 DoubleAnimation 不工作?

Why isn't my DoubleAnimation working?

我正在尝试为我的应用制作自定义汉堡菜单。我已经设置了所有布局,但由于某种原因,我的 DoubleAnimation 没有按预期工作。我正在尝试在 Windows 10 上完成类似于 Cortana 的汉堡菜单的操作。我正在我的代码中创建我的 StoryboardDoubleAnimation(即使我的动画我仍然有同样的问题在 XAML 中创建)。这是我拥有的:

menuButton.Click += (s, e) => {
    if (menuIsOpen) {
        Animate(
            menuPanel,
            "Width",
            ActualWidth, //Page.ActualWidth
            50,
            0.1,
            new Duration(new TimeSpan(TimeSpan.TicksPerSecond)));
    }
    else {
        Animate(
            menuPanel,
            "Width",
            50,
            ActualWidth, //Page.ActualWidth
            0.1,
            new Duration(new TimeSpan(TimeSpan.TicksPerSecond)));
    }
    menuIsOpen = !menuIsOpen;
};

这是 Animate() 的签名:

private void Animate(DependencyObject item, string property, double from, double to, double? by, Duration duration) {
    var storyboard = new Storyboard();
    var animation = new DoubleAnimation();
    animation.From = from;
    animation.To = to;
    animation.Duration = duration;
    animation.EasingFunction = new SineEase() { EasingMode = EasingMode.EaseInOut };
    animation.By = by;
    Storyboard.SetTarget(animation, item);
    Storyboard.SetTargetProperty(animation, property);
    storyboard.Children.Add(animation);
    storyboard.Begin();
}

我用了一点 Debug.WriteLine() 来查看 Storyboard 是否真的是 运行,确实如此。 menuPanel 的宽度根本没有改变。我在我的其他一些项目中使用了类似的方法,并且在那里工作得很好。

EDIT: I thought I'd add a little bit more detail.
My app is targeting Windows 10 and I'm able to change the width of menuPanel freely if I don't use Storyboards and DoubleAnimations.

我找到了 this answer on a similar question,现在我的动画效果很好。

I figured it out myself. All I had to do was to Enable Dependent Animation (EnableDependentAnimation) on the DoubleAnimation as this animation affects the layout. And then it worked perfectly.