2

我正在做一个简单的DataBinding应用程序WPF。在这个应用程序中,我在TextBox命名中输入的任何内容都txtName应该出现在Label. 为此,我使用了绑定WPF,但它没有被绑定。

<Grid>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="315*" />
        <ColumnDefinition Width="188*" />
    </Grid.ColumnDefinitions>

    <TextBox Height="23" HorizontalAlignment="Left"
             Margin="79,12,0,0" Name="txtName"
             VerticalAlignment="Top" Width="120" />
    <Label Height="28" HorizontalAlignment="Left"
             Margin="22,12,0,0" Name="label1"
             VerticalAlignment="Top" Width="42"
             Content="Name"/>
    <TextBox Height="23" HorizontalAlignment="Left"
             Margin="79,56,0,0" Name="txtSirName"
             VerticalAlignment="Top" Width="120" />
    <Label Content="SirName" Height="28"
           HorizontalAlignment="Left" Margin="12,56,0,0"
           Name="label2" VerticalAlignment="Top" Width="52" />
    
    <!-- Following is the label which I bound -->

    <Label Content="{Binding ElementName=txtName,Path=text}"
           Height="28" HorizontalAlignment="Left" Margin="47,112,0,0"
           Name="label3" VerticalAlignment="Top" Width="171" />
</Grid>

我是新手WPF。请指导我。

4

4 回答 4

8

很确定 XAML 区分大小写。您的绑定路径text应该是Text.

于 2013-06-05T06:33:00.120 回答
1

TextBox具有属性文本,而不是文本。小错误:)


 <Grid>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="315*"/>
        <ColumnDefinition Width="188*"/>
    </Grid.ColumnDefinitions>
    <TextBox Height="23" HorizontalAlignment="Left"
             Margin="79,12,0,0" Name="txtName"
             VerticalAlignment="Top" Width="120"/>
    <Label Height="28" HorizontalAlignment="Left"
           Margin="22,12,0,0" Name="label1" VerticalAlignment="Top"
           Width="42" Content="Name"/>
    <TextBox Height="23" HorizontalAlignment="Left"
             Margin="79,56,0,0" Name="txtSirName"
             VerticalAlignment="Top" Width="120" />
    <Label Content="SirName" Height="28" HorizontalAlignment="Left"
           Margin="12,56,0,0" Name="label2" VerticalAlignment="Top"
           Width="52" />
    <Label Content="{Binding ElementName=txtName,Path=Text}"
           Height="28" HorizontalAlignment="Left" Margin="47,112,0,0"
           Name="label3" VerticalAlignment="Top" Width="171" />
</Grid>
于 2013-06-05T06:30:51.120 回答
1

路径= *T *ext

这是一个错字问题。

于 2013-06-05T06:59:17.993 回答
0

尝试这个

<Label Content="{Binding Source={x:Reference txtName}, Path=text}" Height="28" HorizontalAlignment="Left" Margin="47,112,0,0" Name="label3" VerticalAlignment="Top" Width="171" />
于 2013-06-05T06:36:47.937 回答