One of the improvements you can look forward to in Silverlight 3 is element data binding, also known as element-to-element data binding. Silverlight 2’s {Binding} expression allowed you to specify the name of the property you were binding to, but not the element that owned the property. This typically meant you had to write a line of code to complete the binding. In Silverlight 3, {Binding} expressions can identify elements as well as properties.

Here’s an example:

<Grid x:Name=”LayoutRoot” Background=”White”>

    <Border>

        <Border.Projection>

            <PlaneProjection x:Name=”Projector” />

        </Border.Projection>

        <user:Penguin />

    </Border>

    <StackPanel Orientation=”Vertical” VerticalAlignment=”Top”>

        <Slider Minimum=”0″ Maximum=”360″

            Value=”{Binding RotationX, ElementName=Projector, Mode=TwoWay}”

            Width=”400″ VerticalAlignment=”Top” Margin=”0,20,0,0″ />

        <Slider Minimum=”0″ Maximum=”360″

            Value=”{Binding RotationY, ElementName=Projector, Mode=TwoWay}”

            Width=”400″ VerticalAlignment=”Top” Margin=”0,20,0,0″ />

        <Slider Minimum=”0″ Maximum=”360″

            Value=”{Binding RotationZ, ElementName=Projector, Mode=TwoWay}”

            Width=”400″ VerticalAlignment=”Top” Margin=”0,20,0,0″ />

    </StackPanel>

</Grid>

This XAML declares a user control that draws a penguin, and then wires up a trio of sliders to the RotationX, RotationY, and RotationZ properties of a PlaneProjection. The result? You can rotate the penguin about the X, Y, and Z axes by moving the sliders. And there’s no code required.

Element Data Binding 

Pretty cool. But element data binding has a couple of limitations/nuances of which you should be aware. First, I applied the PlaneProjection to a Border containing the penguin user control because element data binding didn’t work when I applied it directly to the user control. I’m assuming this is simply a beta bug and that in the final release, I can get rid of the Border.

Second, and more importantly, the target of an element data binding must be a FrameworkElement derivative. I would have preferred to write my XAML like this:

<Grid x:Name=”LayoutRoot” Background=”White”>

    <Border>

        <Border.Projection>

            <PlaneProjection

                RotationX=”{Binding Value, ElementName=SliderX}”

                RotationY=”{Binding Value, ElementName=SliderY}”

                RotationZ=”{Binding Value, ElementName=SliderZ}”

            />

        </Border.Projection>

        <user:Penguin />

    </Border>

    <StackPanel Orientation=”Vertical” VerticalAlignment=”Top”>

        <Slider x:Name=”SliderX” Minimum=”0″ Maximum=”360″ Value=”0″

            Width=”400″ VerticalAlignment=”Top” Margin=”0,20,0,0″ />

        <Slider x:Name=”SliderY” Minimum=”0″ Maximum=”360″ Value=”0″

            Width=”400″ VerticalAlignment=”Top” Margin=”0,20,0,0″ />

        <Slider x:Name=”SliderZ” Minimum=”0″ Maximum=”360″ Value=”0″

            Width=”400″ VerticalAlignment=”Top” Margin=”0,20,0,0″ />

    </StackPanel>

</Grid>

But that produces a XAML parsing error since PlaneProjection isn’t a FrameworkElement. It is unclear at the moment whether the requirement that an element data binding target a FrameworkElement will change before Silverlight 3 ships. The good news is that lots of elements do derive from FrameworkElement. It is perfectly legal, for example, to bind a Slider representing a volume control to the Volume property of a MediaElement since MediaElement derives from FrameworkElement (and Volume is a dependency property).

Incidentally, I’m always interested to hear about companies who adopt Silverlight and put it to work in creative ways. But when John Robbins told me that Playboy magazine is now using Silverlight Deep Zoom, I wasn’t sure what to think. I wondered why John had suddenly developed an interest in Silverlight. 🙂

I’ve had a blast this week blogging about Silverlight 3, and I have many more tips and samples to share. However, I’m leaving for Microsoft India in a few hours, so I won’t be blogging much for the next week or so. I plan to resume my series on Silverlight 3 the week after next and hope to be posting new entries right up to Devscovery.

Finally, as I wrote the sentence “element data binding has a couple of limitations/nuances of which you should be aware,” I was reminded of a quotation from Winston Churchill:

Churchill 

Which is why I sometimes do allow myself to end sentences with prepositions!