我正在DataBinding
中执行简单的WPF
申请。在这个TextBox
中我输入的任何名为txtName的内容都应该在Label
上得到。为此,我在WPF
中使用了绑定。
但它没有受到约束。
我的XAML:
<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
新手。请指导我。
答案 0 :(得分:7)
非常确定XAML区分大小写。当您的绑定路径为text
时,您的绑定路径为Text
。
答案 1 :(得分:1)
TextBox具有属性Text,而不是文本。小错误:))
<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>
答案 2 :(得分:1)
路径= <强> * T 强> *分机
这是一个错字问题。
答案 3 :(得分: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" />