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

Related Questions

I'm implementing a Google Suggest like autocomplete feature for tag searching using jQuery's autocomplete.
Have/Want List Matching Algorithm I am implementing an item trading system on a high-traffic
In implementing faceted search, if the number of options is 7 or less, I
I'm implementing a DFA as close as I can to the formal definition as
I plan about implementing a dynamic linking into my smalltalk dialect. The problem is
I'm currently implementing a radix tree/patricia trie (whatever you want to call it). I
I'm implementing a system following version 2.0 of the WCAG guidelines. I have tabular
I am implementing a search field where the user can type in a string
While implementing a tree structure over a SQL 2005 server database, the query response

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.