articles

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

Dynamic Bind TextBox Data to Label Control in WPF

Dynamic Bind TextBox Data to Label Control in WPF

maruthi pallamlli 36937 09-Jun-2011

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 Bind TextBox Data to Label Control in WPF

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

 You should read also this Article - Frame control in WPF


Updated 04-Mar-2020

Leave Comment

Comments

Liked By