October 29, 2006
08:27 PM

Sheva (well known on the MSDN WPF Forum) recently blogged his TransitionControl. In the post he dismisses my earlier attempt as "[a] bit cumbersome". While I would humbly accept the criticism, in this case I think it's cumbersome for good reason.

I assume Sheva is referring to the fact that I use the three properties: Source, DisplayA and DisplayB; whereas his implementation uses only two: Content and StaleContent. Because of this, I actually need to implement two transitions, one from A to B and one from B to A - while Sheva needs only one.

I did this because I want to avoid rebuilding the Visual Tree and the cost of any associated conversions. It's also important to maintain the active state of any animations and changes made by the user. In the samples we're just dealing with images, but in reality I'm using transitions on element trees which are much more complex, interactive, and expensive to build.

A side note here is that I have noticed (but still do not fully understand) that the use of DataTemplates has the "unfortunate benefit" that when the underlying data changes, if the DataTemplate to be applied to the new data is the same as the existing one, the Visual Tree is not rebuilt. The unfortunate part is that changes which are not based on the underlying data are maintained - so scrollbars for example will keep their previous values.

Another point which I neglected to mention in the original post is that the old (stale) value absolutely must be hidden or removed from the visual tree when the transition is complete. If the old display is just offscreen or obstructed by the new value we can still access it via the tab key or other means of UI Automation.

Finally, there are still a few things I'd like to do with transitions. I want to delay the transition until data-binding is complete, and I'd like to dispose the old value after the transition is finished. As yet I haven't come up with a good way to do either of these.

© Douglas Stockwell 2007
Creative Commons License Unless otherwise specified all "source code" examples are available for use under the Creative Commons Attribution-Noncommercial 3.0 License. Please contact me if you would like more flexible licensing terms.
Messenger Presence