我目前在标签中有一些文本,我正在尝试将其转移到文本框中。我已经尝试过这种方法,但似乎没有做任何事情。有什么建议么? WPF Label to TextBox
XAML
<Label x:Name="TotalNumberInputted" HorizontalAlignment="Left" Height="23" Margin="122,282,0,0" Content="" VerticalAlignment="Top" Width="35" Background="{x:Null}" />
<TextBox Height="23" Margin="187,282,554,0" Name=" TotalNumberTextBox" VerticalAlignment="Top" TextChanged="TotalNumberTextBox_TextChanged"/>
CS
string LocalLabel = "";
string LocalTextBox = "";
public string Label
{
get { return LocalLabel; }
set
{
LocalLabel = value;
TotalNumberInputted.Content = value;
}
}
public string TextBox
{
get { return LocalTextBox; }
set
{
LocalTextBox = value;
NewQuantity.Text = value;
}
}
答案 0 :(得分:0)
使用绑定(Tutorial,MSDN Data Binding Overview)
<StackPanel>
<Label x:Name="TotalNumberLabel" Content="some content" />
<TextBox Text="{Binding ElementName=TotalNumberLabel, Path=Content}" />
</StackPanel>
现在,当设置标签的内容时,文本框将自动更新。