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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T16:11:55+00:00 2026-06-04T16:11:55+00:00

The purpose of the code below is that a thumb follows a horizontal mouse

  • 0

The purpose of the code below is that a thumb follows a horizontal mouse movement. The code is called upon a mouse event, so the target value of the animation gets updated continuously.

In the code, offset is the current mouse horizontal position. The problem is, that the animation of the thumb doesn’t fully animate to the specified offset, but always seems to be stopping at a value smaller or higher (depending if the mouse is dragged left or right).

The SeekAlignedToLastTick() influences the behavior of the animation, although I couldn’t figure out what this function does by reading the documentation.

How can I animate the thumb, so that it follows smoothly the drag event?

    private Storyboard _thumbStoryboard;
    private DoubleAnimation _thumbAnimation = new DoubleAnimation();;
    private CompositeTransform _thumbTransform = new CompositeTransform();

    private void UpdateUserInterface(double offset)
    {
        var thumbItem = Thumb as FrameworkElement;

        if (_thumbStoryboard == null)
        {
                Storyboard.SetTarget(_thumbAnimation, _thumbTransform);

                _thumbStoryboard = new Storyboard();
                _thumbStoryboard.Children.Add(_thumbAnimation);

                thumbItem.RenderTransform = _thumbTransform;
                _thumbStoryboard.Duration = new Duration(TimeSpan.FromMilliseconds(100));
                _thumbAnimation.EasingFunction = new ExponentialEase();
        }

        double from =  _thumbTransform.TranslateX;

        _thumbStoryboard.Stop();

        Storyboard.SetTargetProperty(_thumbAnimation,  new PropertyPath("TranslateX"));

        _thumbAnimation.From = from;
        _thumbAnimation.To = offset;

        _thumbStoryboard.Begin();
        _thumbStoryboard.SeekAlignedToLastTick(TimeSpan.Zero);            
    }
  • 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-04T16:11:56+00:00Added an answer on June 4, 2026 at 4:11 pm

    I’ve tried to solve your issue, So I’ve created a Silverlight application and added a Border element for testing.

    <Border x:Name="Thumb" VerticalAlignment="Top" HorizontalAlignment="Left" Width="50" height="25" Background="#ff0000" />
    

    There was no need to set the “From” Property, since the DoubleAnimation object could automatically continue from the current Value to the “To” Property.

    And you were setting the Duration to the Storyboard, which causes the DoubleAnimation to Cutoff its animation without reaching the “To” Value, You need to set the Duration Property to the DoubleAnimation itself instead.

    Also there was no need to call _thumbStoryboard.Stop(), because it will reset the current animation to the first TranslateX Value.

    Here is the updated “UpdateUserInterface” function code with comments:

            private void UpdateUserInterface(double offset) {
            var thumbItem = Thumb as FrameworkElement;
    
            if ( _thumbStoryboard == null ) {
    
                // UpdateLayout Method is update the ActualWidth Properity of the UI Elements
                this.UpdateLayout();
    
                // Applying the CompositeTransform on "thumbItem" UI Element
                thumbItem.RenderTransform = _thumbTransform;
    
                // Setting the Render Transform Origin to be the Center of X and Y
                thumbItem.RenderTransformOrigin = new Point(0.5d, 0.5d);
    
                // Setting the target of the DoubleAnimation to be the Thumb CompositeTransform
                Storyboard.SetTarget(_thumbAnimation, _thumbTransform);
    
                // Setting the Targeted Properity of the DoubleAnimation to be The "TranslateX" Properity
                Storyboard.SetTargetProperty(_thumbAnimation, new PropertyPath("TranslateX"));
    
                // Used QuinticEase instead of ExponentialEase
                // and Added EaseOut to make the animation be more smoother.
                _thumbAnimation.EasingFunction = new QuinticEase(){ EasingMode = EasingMode.EaseOut };
    
                // Initializing the Storyboard
                _thumbStoryboard = new Storyboard();
    
                // Specifing the Duration of the DoubleAnimation not the StoryBoard
                _thumbAnimation.Duration = new Duration(TimeSpan.FromMilliseconds(500));
    
                // Adding the DoubleAnimation to the Children of the Storyboard
                _thumbStoryboard.Children.Add(_thumbAnimation);
    
            }
    
            // Calculate the New Centered Position
            double newPos = offset - (thumbItem.ActualWidth / 2);
    
            // Set the New DoubleAnimation "To" Value, 
            // There is no need to set the "From" Value since it'll automatically continue from the current TranslateX Value
            _thumbAnimation.To = newPos;
    
            // Begin the animation.
            _thumbStoryboard.Begin();
        }
    

    Hope that helps you 🙂

    Regards,

    Monir Abu Hilal

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

Sidebar

Related Questions

Suppose i have the code snippet as follows : ( clarification purpose/not well formed
How could I modify the below code such that I could, for better readability
The code below is going to be called from a website so having a
We all know that wordpress have simple .htaccess code like below RewriteEngine on RewriteBase
Below is some code that is used to pass around a reference to a
Wikipedia says it's called a quine and someone gave the code below: char*s=char*s=%c%s%c;main(){printf(s,34,s,34);};main(){printf(s,34,s,34);} But,
I've got following (simplified for example purpose) code and it works: void log(const string
The purpose of this code is to pull upgrade.zip from a central server, extract
Quick question, What have I done wrong here. The purpose of this code is
What is the purpose of these java.lang.annotation imports in this code? Why are they

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.