Home / Programming / Blog article: Silverlight 3 Element To Element Binding

| RSS

Silverlight 3 Element To Element Binding

July 12th, 2009 | No Comments | Posted in Programming

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.

Leave a Reply 1730 views, 1 so far today |
Tags: ,

Leave a Reply





Switch to our mobile site