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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T22:40:55+00:00 2026-06-16T22:40:55+00:00

I have class that is derived from FrameworkElement , and I want WPF to

  • 0

I have class that is derived from FrameworkElement, and I want WPF to update its Location property by using DoubleAnimation. I register the property as DependendencyProperty:

public class TimeCursor : FrameworkElement
{
    public static readonly DependencyProperty LocationProperty;

    public double Location
    {
        get { return (double)GetValue(LocationProperty); }
        set
        {
            SetValue(LocationProperty, value);
        }
    }

    static TimeCursor()
    {
        LocationProperty = DependencyProperty.Register("Location", typeof(double), typeof(TimeCursor));
    }
}

Following code sets up the storyboard.

TimeCursor timeCursor;
private void SetCursorAnimation()
{
    timeCursor = new TimeCursor();
    NameScope.SetNameScope(this, new NameScope());
    RegisterName("TimeCursor", timeCursor);

    storyboard.Children.Clear();

    DoubleAnimation animation = new DoubleAnimation(LeftOffset, LeftOffset + (VerticalLineCount - 1) * HorizontalGap + VerticalLineThickness, 
                new Duration(TimeSpan.FromMilliseconds(musicDuration)), FillBehavior.HoldEnd);

    Storyboard.SetTargetName(animation, "TimeCursor");
    Storyboard.SetTargetProperty(animation, new PropertyPath(TimeCursor.LocationProperty));

    storyboard.Children.Add(animation);
}

Then I call storyboard.Begin(this) from another method of the object which contains the above SetCursorAnimation() method and this object is derived from Canvas. However the Location property is never updated(set accessor of Location is never called) and no exception is thrown. What am I doing wrong?

  • 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-06-16T22:40:57+00:00Added an answer on June 16, 2026 at 10:40 pm

    When a dependency property is animated (or set in XAML, or set by a Style Setter, etc.), WPF does not call the CLR wrapper, but instead directly accesses the underlying DependencyObject and DependencyProperty objects. See the Implementing the “Wrapper” section in Checklist for Defining a Dependency Property and also Implications for Custom Dependency Properties.

    In order to get notified about property changes, you have to register a PropertyChangedCallback:

    public class TimeCursor : FrameworkElement
    {
        public static readonly DependencyProperty LocationProperty =
            DependencyProperty.Register(
                "Location", typeof(double), typeof(TimeCursor),
                new FrameworkPropertyMetadata(LocationPropertyChanged)); // register callback here
    
        public double Location
        {
            get { return (double)GetValue(LocationProperty); }
            set { SetValue(LocationProperty, value); }
        }
    
        private static void LocationPropertyChanged(
            DependencyObject obj, DependencyPropertyChangedEventArgs e)
        {
            var timeCursor = obj as TimeCursor;
    
            // handle Location property changes here
            ...
        }
    }
    

    And note also that animating a dependency property does not necessarily require a Storyboard. You could simply call the BeginAnimation method on your TimeCursor instance:

    var animation = new DoubleAnimation(LeftOffset,
        LeftOffset + (VerticalLineCount - 1) * HorizontalGap + VerticalLineThickness, 
        new Duration(TimeSpan.FromMilliseconds(musicDuration)),
        FillBehavior.HoldEnd);
    
    timeCursor.BeginAnimation(TimeCursor.LocationProperty, animation);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a basic class that derived subclasses inherit from, it carries the basic
I have a class Derived that inherits directly from two base classes, Base1 and
I have a class that derives from ImageView . In its onDraw method override
I'm creating an abstract class to derive from. I have a Value property that
I have a virtual class Element that forces its derived classes to have a
I have a class that is derived from ostream: class my_ostream: public std::ostream {
I have a base class Foo that has an Update() function, which I want
I have a class that has been derived from NSObject. How can copy be
I have a virtual class that has been derived from a non virtual class.
In .Net/C# I have a class that's derived from List. When I try to

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.