System.Windows.Media.Animation.DoubleAnimation generates a lot of PropertyChangedCallbacks of DependecyProperty

64 Views Asked by At

Hi together i am Korbinian and i investigate currently a CPU cosumption problem regarding WPF and animated UI elements. We animate a UI element via System.Windows.Media.Animation.DoubleAnimation methode BeginAnimation. I am quite new to WPF especially animation.

Timeline.DesiredFrameRateProperty.OverrideMetadata(typeof(Timeline),
                new FrameworkPropertyMetadata { DefaultValue = 8 });

            flashAnimation = new DoubleAnimation(1, 0.3, TimeSpan.FromMilliseconds(330), FillBehavior.Stop)
            {
                RepeatBehavior = RepeatBehavior.Forever,
                AutoReverse = true

            };

            this.BeginAnimation(FlashOpacityProperty, flashAnimation);

hint: I already tried in the snippet above to reduce the DesiredFrameRate to 8 in order to reduce the CPU consumption.

As far as i can see during debugging, the FlashOpacityProperty's Callback (PropertyChangedCallback) is called around 8 times per second. This amount of callbacks is somehow independent from what is defined in the constructor of the DoubleAnimation. My Goal is to reduce the amount of callbacks. For my use case its not important to have a fluent and nice looking animation. It should mainly support for highlighting.

Is is possible to reduce the amount of callbacks? Or is this a fix kind of animation from .Net?

Thank you very much in advance

1

There are 1 best solutions below

0
korbif On BEST ANSWER

The problem was, that the DependencyProperty was changed in an endless loop (~8 times per second).

Independent from that, the DoubleAnimation was not using the updated value from the DependencyProperty.

At the end, i removed the DependencyProperty and handled the animation in the certain Behavior implementation.