Tuesday, January 8, 2013

WPF Simple Data Binding Example


Binding property value from one control to property of another:

In the example below, we will bind value of Text property of first TextBox named textBox1 to the Text property of the last TextBox. 


<Window x:Class="BindingExample.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <TextBox Height="23" HorizontalAlignment="Left" Margin="182,81,0,0" Name="textBox1" VerticalAlignment="Top" Width="239" />
        <TextBlock Height="23" HorizontalAlignment="Left" Margin="88,81,0,0" Name="textBlock1" Text="Enter Something" VerticalAlignment="Top" />
        <TextBox Height="141" HorizontalAlignment="Left" Margin="88,110,0,0" Name="textBox2" VerticalAlignment="Top" Width="333"
              Text="{Binding ElementName=textBox1, Path=Text}"   />
    </Grid>
</Window>



No comments:

Post a Comment