Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 637915
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T20:40:32+00:00 2026-05-13T20:40:32+00:00

I am implementing a marching ants style animation by applying a StrokeDashOffset animation to

  • 0

I am implementing a “marching ants” style animation by applying a StrokeDashOffset animation to a Rectangle control. I would like the animation to play when the rectangle is visible but not take up extra CPU cycles when it’s hidden. Is WPF smart enough to automatically pause the animation when the affected control is hidden?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T20:40:33+00:00Added an answer on May 13, 2026 at 8:40 pm

    No. WPF is smart enough to not do so :). The reason behind this is that the animation system cannot make assumptions about what the animated property does (it could be any dependency property, not necessary related to control appearance, in which case you want the animation to work regardless of visibility).

    You can test this as follows:

    XAML:

    <Window x:Class="WpfApplication1.TestBrowser"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            xmlns:local="clr-namespace:WpfApplication1"
            Title="Animation Test"
            Height="300"
            Width="300">
        <StackPanel>
                <Button Content="Toggle label" 
                                Click="ToggleLableClick"/>
                <local:MyLabel x:Name="lbl" Content="Hello" />
        </StackPanel>
    </Window>
    

    C#:

    using System;
    using System.Diagnostics;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Media.Animation;
    
    namespace WpfApplication1
    {
      public partial class TestBrowser : Window
      {
        public TestBrowser()
        {
          InitializeComponent();
            var da = new DoubleAnimation(0, 10, new Duration(TimeSpan.FromSeconds(10)))
                        {
                            AutoReverse = true,
                            RepeatBehavior = RepeatBehavior.Forever
                        };
            lbl.BeginAnimation(MyLabel.DoublePropertyProperty, da);
        }
    
        private void ToggleLableClick(object sender, RoutedEventArgs e)
        {
            lbl.Visibility = lbl.IsVisible ? Visibility.Collapsed : Visibility.Visible;
        }
      }
    
        public class MyLabel : Label
        {
            public double DoubleProperty
            {
                get { return (double)GetValue(DoublePropertyProperty); }
                set { SetValue(DoublePropertyProperty, value); }
            }
    
            public static readonly DependencyProperty DoublePropertyProperty =
                    DependencyProperty.Register("DoubleProperty", typeof(double), typeof(MyLabel), 
                    new FrameworkPropertyMetadata(0.0,
                        FrameworkPropertyMetadataOptions.AffectsMeasure | FrameworkPropertyMetadataOptions.AffectsArrange, OnDoublePropertyChanged));
    
            private static void OnDoublePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
            {
                Trace.WriteLine(e.NewValue);
            }
    
            protected override Size MeasureOverride(Size constraint)
            {
                Trace.WriteLine("Measure");
                return base.MeasureOverride(constraint);
            }
    
            protected override Size ArrangeOverride(Size arrangeBounds)
            {
                Trace.WriteLine("Arrange");
                return base.ArrangeOverride(arrangeBounds);
            }
        }
    }
    

    You’ll see proof of WPF’s brilliance in the debug output: it shows DoubleProperty changes whether the control is visible or not, but visibility matters when it comes to Measure/Arrange. Handlers are not called when the control is collapsed, even though I marked DoubleProperty as a property that affects measure and arrange…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When implementing a class with multiple properties (like in the toy example below), what
I'm implementing a linux shell for my weekend assignment and I am having some
Implementing ArrayAccess Interface in PHP , We can access Object Properties as Array Keys
Im implementing sphinx search engine into my site, thru SpinxSE, its all seems to
when implementing/using methods that return or work with instances of objects, what is the
I'm looking for idea's how to convert a 30+gb, 2000+ colored TIFF image series
I have a program that uses (and must continue to use) an old sorting
hi i am new to android what i did is creating a list with
I have the following problem: Given a Guice type literal TypeLiteral<T> template and a
I suppose this question is language-agnostic, tho I'm asking it in regards to building

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.