rss or subscribe by email | follow us on Facebook | contact us

Continuing the wishlist for WPF

February 22, 2008 19:52

I often get these ideas while I'm waking up. This one is called "Dynamic Animateable Value Lookup".

This value lookup is partially like DataBinding. Right now, we can write Property="{Binding Path=XYZ, Element=ABC, Mode=Default}" and the property will take its value from Path (the property) of the element (Control). However, this is not animateable without animating the original property.

Let me give you an example:

	<StackPanel HorizontalAlignment="Stretch">           <Rectangle /></StackPanel>

Now, the StackPanel uses "Stretch" for HorizontalAlignment and therefore does not expose a direct physical double value in XAML. If I wanted to animate my rectangle's Width from 100% (which would be equal to the Width of the StackPanel) to 0px, it would pretty much impossible (as far as I know) in XAML. I'd have to go to code-behind and write the animation in VB or C#.

Here's how a lookup can help...

On Time 00:00.00 / Frame 0

<Rectangle Width="{ValueLookup Path=Width, Element=StackPanel}"/>

I could then, in Blend, go to the Time 00:00.7 (Frame 7) create a keyframe, and then enter a manual value, like 0 or 10 in the Rectangle's Width property. What the runtime would do is on reaching frame 0 it would do a lookup for the current width of the StackPanel control and pass on that value to the Rectangle's Width as a ByVal variable rather a ByRef variable (not an accurate description, but you know what I mean) and then that value would be a physical double and could be animated in accordance with the other keyframe.

Such "once only" lookups can be very valuable. Now, developers might choose to do this in code rather than having a new feature like this. And while yes it is easy to do this in code behind, you have to remember the separation of XAML and procedural code is mandatory for separating design and code - especially when working with a designer. If the Designer had to go write in procedural code, then it would be a mess to manage - especially if you intend to have your own code in there.

EDIT: Please see the comment on this blog post by Paul Shmakov, where explains how my Rectangle issue can be solved with the current release of WPF! Thanks, Paul. Wow, looks like the WPF team DID think of almost everything.


Powered by the awesome BlogEngine.NET | Sign in