Wpf 设置ContentControl的缩放动画

Wpf 设置ContentControl的缩放动画,wpf,animation,Wpf,Animation,我正在尝试设置ContentControl的缩放X和Y属性的动画。这是我的代码: //主窗口构造函数: ScaleTransform scale = new ScaleTransform(0, 0); ModalControl.LayoutTransform = scale; ModalControl.UpdateLayout(); //动画代码 Dispatcher.Invoke(()=> { va

我正在尝试设置ContentControl的缩放X和Y属性的动画。这是我的代码:

//主窗口构造函数:

        ScaleTransform scale = new ScaleTransform(0, 0);
        ModalControl.LayoutTransform = scale;
        ModalControl.UpdateLayout();
//动画代码

        Dispatcher.Invoke(()=> {
            var anim = new DoubleAnimation {
                From = 0,
                To = 1,
                Duration = TimeSpan.FromMilliseconds(250)
            };

            var scaleXAnim = new DoubleAnimation {
                From = 0,
                To = 1,
                Duration = TimeSpan.FromMilliseconds(250)
            };

            ModalControl.BeginAnimation(OpacityProperty, anim); // this works
            ModalControl.BeginAnimation(ScaleTransform.ScaleXProperty, scaleXAnim); // this doesn't
            ModalControl.BeginAnimation(ScaleTransform.ScaleYProperty, scaleXAnim);

            Console.WriteLine("Animation called");

        });
XAML



我不知道我错过了什么。当动画不透明度时,它会按预期工作,但缩放更麻烦。知道还需要做什么吗?

该控件没有ScaleX和ScaleY属性

必须在控件的LayoutTransform中设置ScaleTransform对象属性的动画:

ModalControl.LayoutTransform.BeginAnimation(
    ScaleTransform.ScaleXProperty, scaleXAnim);

ModalControl.LayoutTransform.BeginAnimation(
    ScaleTransform.ScaleYProperty, scaleXAnim);

该控件没有ScaleX和ScaleY属性

必须在控件的LayoutTransform中设置ScaleTransform对象属性的动画:

ModalControl.LayoutTransform.BeginAnimation(
    ScaleTransform.ScaleXProperty, scaleXAnim);

ModalControl.LayoutTransform.BeginAnimation(
    ScaleTransform.ScaleYProperty, scaleXAnim);

不清楚为什么要在Dispatcher操作中启动动画。看起来毫无意义,至少在问题的上下文中是这样。不清楚为什么要在调度程序操作中启动动画。似乎毫无意义,至少在这个问题上是这样。