Silverlight 3 among its other features includes element to element binding. This was always available in WPF but somehow missing in Silverlight 1 and 2. And now Silverlight 3 has bridged that gap. Element to element binding can reduce code when used properly. In this post I will show you how to use this feature.

Example

In this very basic example I will use two controls, a TextBlock and a Slider. When the slider is moved, the value in TextBlock changes accordingly.

<StackPanel x:Name="LayoutRoot">
  <TextBlock
    Width="100"
    Foreground="Blue"
    HorizontalAlignment="Center"
    Text="{Binding Value, ElementName=slider1}" />
  <Slider
    x:Name="slider1"
    Minimum="0"
    Maximum="100"
    Width="200" />
</StackPanel>

 

Here is a screenshot of the output produced by XAML above.

Element Binding 

Element binding can come in very handy in certain scenarios. An example can be making all fields read-only based on a status flag. Rather than writing C# code, this can be done easily and cleanly with element binding.

Tagged with:
 

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>