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 151387
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T09:26:30+00:00 2026-05-11T09:26:30+00:00

I try to animate a DependencyProperty from a value to a target value (in

  • 0

I try to animate a DependencyProperty from a value to a target value (in code) and when the animation finishes (or is canceled) set the final value to the property. The final value would be either the To value if the animation finishes or the current computed value (by the animation) when the animation is canceled.

By default the Animation doesn’t have this behavior and an Animation doesn’t change the actual value even if it has completed.

A failed attempt

A while ago I wrote this helper method to achieve the mentioned behavior:

static void AnimateWithAutoRemoveAnimationAndSetFinalValue(IAnimatable element,     DependencyProperty property,     AnimationTimeline animation) {     var obj = element as DependencyObject;     if (obj == null)         throw new ArgumentException('element must be of type DependencyObject');     EventHandler handler = null;     handler = (sender, e) =>     {         var finalValue = obj.GetValue(property);         //remove the animation         element.BeginAnimation(property, null);         //reset the final value         obj.SetValue(property, finalValue);          animation.Completed -= handler;      };      animation.Completed += handler;      element.BeginAnimation(property, animation); } 

Unfortunately the Completed event doesn’t seem to fire if the Animation is removed by someone calling BeginAnimation(property,null) and therefore I cannot set the final value correctly when an Animation is canceled. What is worse I cannot remove the event handler either…

Does someone know how to do this in a clean way?

  • 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. 2026-05-11T09:26:30+00:00Added an answer on May 11, 2026 at 9:26 am

    It looks like you are trying to set value back to the initial value prior to the animation starts just after the animation finishes. This actually happens automatically if you stop the animation (or when the animation timeline finishes). Animations, in WPF, can be though of as an value overlay on top of the current value of the property. Stopping or removing an animation will remove the overlay and the prior value will now start showing through again. The original value is not lost, it is being temporarily obscured.

    Setting the property explicitly back to its prior value is, in general, bad practice because it can incur a memory overhead if the value was not originally set locally on the object. Also, this can introduce subtle problems later. For example, if the old value was derived from a style, the property will no longer change if the style changes.

    If you still feel you must extract the current value and later restore it, use ReadLocalValue() instead of GetValue(). This will return DepenencyProperty.UnsetValue if the value is not set locally. You can then conditionally call ClearValue() or SetValue() depending on whether the property initially had a local value.

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

Sidebar

Ask A Question

Stats

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

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

    • 7 Answers
  • Editorial Team

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

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Are you running on OS 3.0? I saw the same… May 12, 2026 at 1:19 am
  • Editorial Team
    Editorial Team added an answer It looks like you need to register Apache::Session::Memcached with Apache::Session::Wrapper,… May 12, 2026 at 1:19 am
  • Editorial Team
    Editorial Team added an answer Use DATENAME or DATEPART: SELECT DATENAME(dw,GETDATE()) -- Friday SELECT DATEPART(dw,GETDATE())… May 12, 2026 at 1:19 am

Related Questions

I was looking for a way to animate the scrolling of a ScrollViewer and
I might be missing something really obvious. I'm trying to write a custom Panel
When I try to change a CroppedBitmap's SourceRect property at runtime, nothing happens. There's
I'd like to do a line-graph on a web-page using Javascript. I want it

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.