将标签内容移动到文本框中

时间:2018-12-30 15:11:51

标签: wpf xaml

我目前在标签中有一些文本,我正在尝试将其转移到文本框中。我已经尝试过这种方法,但似乎没有做任何事情。有什么建议么? 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;
        }
    }

1 个答案:

答案 0 :(得分:0)

使用绑定(TutorialMSDN Data Binding Overview

<StackPanel>
  <Label x:Name="TotalNumberLabel" Content="some content" />

  <TextBox Text="{Binding ElementName=TotalNumberLabel, Path=Content}" />
</StackPanel>

现在,当设置标签的内容时,文本框将自动更新。