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}"
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.
I’m now free to use bindings for the To From properties.