Binding Exmaple In WPF-Slider Control.
DataBinding is the main feature of WPF. This article gives you a small introduction of how to use Binding in wpf. This article shows how to bind Slider Control to Label FontSize And Label Content property to Textbox Text property.
Data binding is the process that establishes a connection between the application UI and business logic. It is the main feature of WPF.
Here I am going to show you How to bind a Slider control to Label fontsize and how to bind label content property to Textbox text property.
Step I
First Open Visual Studio and Create a WPF project.
Step II
Now take a Textbox , a Label and a Slider Control. As shown in Attatched Project.
Step III
Bind Label Content To Textbox Text property. Like this:
<TextBox Height="23" HorizontalAlignment="Left" Margin="98,12,0,0" Name="tex_text"
VerticalAlignment="Top" Width="120" Text="Abhishek"/>
<Label Content="{Binding ElementName=tex_text, Path=Text}" Foreground="Red"
Height="55" HorizontalAlignment="Left" Margin="144,98,0,0" Name="lbt_text" VerticalAlignment="Top" Width="206" />
Step IV
Bind The Label FontSize to Slider Value Property. as:
<Label Content="{Binding ElementName=tex_text, Path=Text}" FontSize="{Binding ElementName=slider1, Path=Value}"
Foreground="Red" Height="55" HorizontalAlignment="Left" Margin="144,98,0,0"
Name="lbt_text" VerticalAlignment="Top" Width="206" />
<Slider Height="23" HorizontalAlignment="Left" Margin="322,220,0,0" Name="slider1"
Minimum="12" Maximum="24" VerticalAlignment="Top" Width="154" />
Now build the project and Run the project by pressing F5 key. So you can see that binding is done in this project. So by this way you can use binding in your projects.