Home > DeveloperSection > Articles > Dynamic Bind TextBox Data to Label Control in WPF

Dynamic Bind TextBox Data to Label Control in WPF


WPF WPF 
Ratings:
0 Comment(s)
 19490  View(s)
Rate this:

Dynamic Bind TextBox Data to Label Control in WPF


This is the simple demonstration how to show the text data to label at run time (when input value in text it show also in label control).

In this WPF application, we take one textbox (for input value) and one label (for output value).

This is the simple code in xaml

<Window x:Class="WpfApplication2.Window1"

    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

    Title="Window1" Height="350" Width="519">

    <Grid Height="318" Width="469">

        <StackPanel Margin="10,48,91,128" Name="stackPanel1" >

            <Label Content="Databind Textbox to label "/>           

             <Label Content="Enter Value: "/>

            <TextBox Height="30" x:Name="txtinput" Background="AliceBlue" Width="189" AllowDrop="True"  />

            <Label Content="Display TextBox Value: "/>

            <Label Height="31" Name="label1" Background="AliceBlue" Width="189" Content="{Binding Text,ElementName=txtinput,UpdateSourceTrigger=PropertyChanged}"></Label>

        </StackPanel>

 

    </Grid>

</Window>

 

Note:  highlight portion show the binding text data to content properties of label control.

Output:
Run the program and input the value in textbox it show in label control as here

Dynamic Binding in WPF

 

So , this is the simple demonstration how to bind the textbox data to label control at runtime.

 


Don't want to miss updates? Please click the below button!

Follow MindStick