简体   繁体   中英

Why doesn't TextBox bind to Label in my XAML code?

New to wpf applications. I tried to implement this code but the label is always blank no matter what I enter in the textbox:

<Window x:Class="Mufu.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Muf(u)" Height="350" Width="525">
<Grid>
    <TextBox Height="23" HorizontalAlignment="Left" Margin="100,200,0,0" Name="textBox3" VerticalAlignment="Top" Width="124" />
    <Label Content="{Binding ElementName=textbox3, Path=Text}"  Height="48" HorizontalAlignment="Center" Margin="0,30,0,0" Name="label4" VerticalAlignment="Top" Width="445" FontSize="26" />
</Grid>

That is because textbox3 and textBox3 are different names. Just change the case and it will work

<Stackpanel>
    <TextBox Height="23" HorizontalAlignment="Left" Margin="100,200,0,0" Name="textBox3" VerticalAlignment="Top" Width="124" />
    <Label Content="{Binding ElementName=textbox3, Path=Text}"  Height="48" HorizontalAlignment="Center" Margin="0,30,0,0" Name="label4" VerticalAlignment="Top" Width="445" FontSize="26" />
</Stackpanel>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM