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

  • SEARCH
  • Home
  • 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

Ask A Question

Stats

  • Questions 372k
  • Answers 372k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The former is preferrable because if index(es) exist on any… May 14, 2026 at 7:27 pm
  • Editorial Team
    Editorial Team added an answer Learn about indexes, and use them properly. Generally speaking*, follow… May 14, 2026 at 7:27 pm
  • Editorial Team
    Editorial Team added an answer Would something like this work for you? class Container attr_accessor… May 14, 2026 at 7:27 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.