Earlier this year, I wrote about Silverlight 3’s new element data binding feature, which enables XAML elements to be bound together declaratively. I also bemoaned the fact that the target of an element-to-element data binding had to be a Framework-element derivative. Good news! Silverlight 4 fixes this by extending element data binding to DependencyObject derivatives.
My Silverlight 3 element data binding sample was built from the following XAML:
<Grid x_Name=”LayoutRoot” Background=”White”>
<Border>
<Border.Projection>
<PlaneProjection x_Name=”Projector” />
</Border.Projection>
<user:PenguinUserControl />
</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>
The result was a penguin that could be rotated about the X, Y, and Z axes using Sliders:
When I wrote this demo, I wanted to attach the {Binding} expressions to the PlaneProjection, not the Slider controls. But Silverlight 3 didn’t allow this because PlaneProjection isn’t a FrameworkElement. My recourse was to apply the bindings to the Sliders themselves and to use 2-way bindings to sync the Sliders’ Value properties with the PlaneProjection’s RotationX, RotationY, and RotationZ properties.
Such shenanigans are no longer necessary in Silverlight 4, which supports the following syntax:
<Grid x_Name=”LayoutRoot” Background=”White”>
<user:PenguinUserControl>
<user:PenguinUserControl.Projection>
<PlaneProjection
RotationX=”{Binding Value, ElementName=SliderX}”
RotationY=”{Binding Value, ElementName=SliderY}”
RotationZ=”{Binding Value, ElementName=SliderZ}” />
</user:PenguinUserControl.Projection>
</user:PenguinUserControl>
<StackPanel Orientation=”Vertical” VerticalAlignment=”Top”>
<Slider x_Name=”SliderX” Minimum=”0″ Maximum=”360″ Width=”400″
VerticalAlignment=”Top” Margin=”0,20,0,0″ />
<Slider x_Name=”SliderY” Minimum=”0″ Maximum=”360″ Width=”400″
VerticalAlignment=”Top” Margin=”0,20,0,0″ />
<Slider x_Name=”SliderZ” Minimum=”0″ Maximum=”360″ Width=”400″
VerticalAlignment=”Top” Margin=”0,20,0,0″ />
<
p class=”MsoNormal”> </StackPanel>
</Grid>
Also note that you can now apply a PlaneProjection directly to a user control. Silverlight 3 didn’t support this, which explains why in the Silverlight 3 version of this demo, I enclosed the user control in a Border and applied the PlaneProjection to the Border. This is yet another new feature of Silverlight 4 that further narrows the gap between Silverlight and WPF.
Microsoft Azure and Amazon Web Services (AWS) are two of the most popular cloud platforms.…
Cloud management is difficult to do manually, especially if you work with multiple cloud…
Azure’s scalable infrastructure is often cited as one of the primary reasons why it's the…
https://www.youtube.com/watch?v=wDzCN0d8SeA Watch our "Unlocking the Power of AI in your Software Development Life Cycle (SDLC)"…
FinOps is a strategic approach to managing cloud costs. It combines financial management best practices…
Using Kubernetes with Azure combines the power of Kubernetes container orchestration and the cloud capabilities…
View Comments
PingBack from http://isilverlight.cn/jeff-prosises-blog-silverlight-4s-improved-element-data-binding/
This post was mentioned on Twitter by ittyurl: New at IttyUrl: http://ittyurl.net/ebkl.ashx jeff prosise's blog : silverlight 4's improved element data binding
Hi Jeff,
Thanks for this write up.
How can I get to do this in Code Behind !? Setting this precise binding ?
Thank you.
Hi,
I am using Blend 4 & Silverlight 4, I have modified , to I am able to drag the slider but I am unable to bind the data or passing data to the callout through xaml.cs Can you help me on this.