I would like to use a DoubleAnimation
to animate a double-DependencyProperty
on MouseOver depending on it's current value. For the sake of simplicity lets say i want to animate a ListBoxItem to move slightly to the right while i hover my mouse over it and move back when the mouse is removed.
I started out by defining <DoubleAnimation By="5">
and <DoubleAnimation By="-5">
in the EnterActions
and ExitActions
of my MouseOver-Trigger. This works fine if i hover the mouse over the object long enough, but if i interrupt the first animation by moving the mouse, the second animation will run longer than the first one. Thus after all animations are done, the objects position is slightly off.
I can use FillBehaviour="Stop"
in the Storyboard to fix the state of my object after all animations are done. However this makes the object snap back into place, which obviously looks quite irritating.
What i would like to do is to specify the To
-Property in the second DoubleAnimation
to be the original value of my Property. This was calculated initially by a Converter
, so I tried to bind that Property to the already existing Converter
. This throws an error due to threading issues (while i was surprised at first, google explained the reason quite well). I even found a post covering this (WPF animation: binding to the "To" attribute of storyboard animation) and might be able to modify this to fit my situation. However this feels like a "hacky" solution.
The question: I feel like i am not thinking straightforward enough anymore. All I want to do is to "move" an object on mouseover and "move" it back afterwards. Is there an easy way to do this?