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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T14:50:40+00:00 2026-06-05T14:50:40+00:00

How can I animate the width of an element from 0 to its actual

  • 0

How can I animate the width of an element from 0 to its actual width in WPF?

I tried this:

<ControlTemplate.Triggers>
    <EventTrigger RoutedEvent="Loaded">
        <BeginStoryboard>
            <Storyboard>
                <DoubleAnimation Duration="0:0:0.3" To="{Binding ElementName=MyElement, Path=ActualWidth}" From="0" Storyboard.TargetProperty="Width" Storyboard.TargetName="MyElement" />
            </Storyboard>
        </BeginStoryboard>
    </EventTrigger>
</ControlTemplate.Triggers>

If I change the binding to a hard coded value, like 100, then the width is properly animated, except that I want to bind to the actual width of the element.

If it matters, MyElement is a border, and I’m animating a tab item.

For the record, this does not work either:

To="{Binding RelativeSource={RelativeSource AncestorType={x:Type Border}}, Path=ActualWidth}"
  • 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-05T14:50:43+00:00Added an answer on June 5, 2026 at 2:50 pm

    I’m sure this is wrong for SO many reasons and please feel free to tell me how many WPF laws I’ve violated but.. I solved the same problem by creating my own BindableDoubleAnimation.

    public class BindableDoubleAnimation : DoubleAnimationBase
    {
        DoubleAnimation internalAnimation;
    
        public DoubleAnimation InternalAnimation { get { return internalAnimation; } }
    
        public double To
        {
            get { return (double)GetValue(ToProperty); }
            set { SetValue(ToProperty, value); }
        }
    
        /// <summary>
        /// Dependency backing property for the <see cref="To"/> property.
        /// </summary>
        public static readonly DependencyProperty ToProperty =
            DependencyProperty.Register("To", typeof(double), typeof(BindableDoubleAnimation), new UIPropertyMetadata(0d, new PropertyChangedCallback((s, e) =>
                {
                    BindableDoubleAnimation sender = (BindableDoubleAnimation)s;
                    sender.internalAnimation.To = (double)e.NewValue;
                })));
    
    
        public double From
        {
            get { return (double)GetValue(FromProperty); }
            set { SetValue(FromProperty, value); }
        }
    
        /// <summary>
        /// Dependency backing property for the <see cref="From"/> property.
        /// </summary>
        public static readonly DependencyProperty FromProperty =
            DependencyProperty.Register("From", typeof(double), typeof(BindableDoubleAnimation), new UIPropertyMetadata(0d, new PropertyChangedCallback((s, e) =>
            {
                BindableDoubleAnimation sender = (BindableDoubleAnimation)s;
                sender.internalAnimation.From = (double)e.NewValue;
            })));
    
    
        public BindableDoubleAnimation()
        {
            internalAnimation = new DoubleAnimation();
        }
    
        protected override double GetCurrentValueCore(double defaultOriginValue, double defaultDestinationValue, AnimationClock animationClock)
        {
            return internalAnimation.GetCurrentValue(defaultOriginValue, defaultDestinationValue, animationClock);
        }
    
        protected override Freezable CreateInstanceCore()
        {
            return internalAnimation.Clone();;
        }
    }
    

    I’m now free to use bindings for the To From properties.

    <local:BindableDoubleAnimation Storyboard.TargetProperty="Width" From="0" To="{Binding ActualWidth, RelativeSource={RelativeSource AncestorType=Window}}"/>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

From the documentation I've found this example: We can animate any element, such as
Possible Duplicate: Can you animate a height change on a UITableViewCell when selected? This
I found this Is it possible to move the text from an element to
How do you animate a div element to the middle of the screen from
is there a way to animate one element's height(let's say div) from bottom to
I want create an application with animate button? how can i do? after click
With jquery i can't get links working AND animate the anchors' background both. It
i am having problems with animation. Can't realize how to animate things in flex?
I was just wondering how I can animate the jQuery form ui's div update
If i have my animations defined in xml then i can animate between activities

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.