This should work for WPF and Silverlight. This is a SUPER simple example. I find it hard to locate really good clean examples in WPF / Silverlight. People tend to do a lot of Control Templating and Style-izing which clouds the code. I am starting a ‘Clean and Simple’ set of blog entries to show SIMPLE and CLEAN examples.
In this code (there is no code behind other than that which is generated by Visual Studio) all we do is bind the Value of the slider to the Content of the label.
<Window x:Class="WpfToolbox.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="153" Width="300">
<Grid>
<StackPanel Height="115" VerticalAlignment="Top">
<Label Content="{Binding ElementName=slider1, Path=Value}" />
<Slider Height="22" Name="slider1" VerticalAlignment="Top" Minimum="0" Maximum="99" />
<Label Content="{Binding ElementName=slider2, Path=Value}" />
<Slider Height="22" Name="slider2" VerticalAlignment="Top" Minimum="99" Maximum="199" />
</StackPanel>
</Grid>
</Window>
So in the XAML above you will see that the labels are not even named. All I did was use a binding expression to bind the ElementName to the Name of the slider control. The Path is simply the property name who’s value is to be bound. So the slider1.Value is bound to the Content of the first label.
50cf3a92-0d4f-4c6a-b2d5-95ce34eb9290|0|.0