Data binding
When building graphical user interfaces, you will often want to bind a property of one control to another or to some data.
Binding to elements
In the MainWindow.xaml
file, add the following markup after the Button
element inside the horizontally orientated StackPanel
:
<Slider Value="50" Maximum="100" Minimum="0" Width="200" Name="slider"/> <TextBlock Text="{Binding ElementName=slider, Path=Value}" VerticalAlignment="Center" Margin="10"/>
Rerun the app. Click, hold, and drag the slider, and notice that the text block shown to the right of the slider always shows the current value of the slider:
Under the horizontally orientated stack panel, but inside the outer stack panel, add the following markup to define some instructions to the user, a slider for values between 0
and 360
degrees, and a red square with a rotation transformation:
<TextBlock>Use the...