如何将用户在文本框中输入的文本移动到 C# 中的文本块中?
How do I move a text input by user in a textbox, into a textblock in C#?
menuText 是文本块,commentTextbox 是文本框。当文本输入到文本框时,我已经清除了文本框。单击 commentButton 时,如何使文本框中的文本输入显示在文本块中?
private void commentButton_Click(object sender, RoutedEventArgs e)
{
if (string.IsNullOrWhiteSpace(commentTextbox.Text))
{
}
else
{
commentTextbox.Text = string.Empty;
menuText.Text += commentTextbox.Text;
}
}
您首先要清除文本框,因此,由于 commentTextbox.Text
是一个空字符串,您的最后一行实际上是在执行 menuText.Text += string.Empty;
您应该颠倒这些调用的顺序,例如:
private void commentButton_Click(object sender, RoutedEventArgs e)
{
if (String.IsNullOrWhiteSpace(commentTextbox.Text) == false)
{
menuText.Text += commentTextbox.Text;
commentTextbox.Text = string.Empty;
}
}
menuText 是文本块,commentTextbox 是文本框。当文本输入到文本框时,我已经清除了文本框。单击 commentButton 时,如何使文本框中的文本输入显示在文本块中?
private void commentButton_Click(object sender, RoutedEventArgs e)
{
if (string.IsNullOrWhiteSpace(commentTextbox.Text))
{
}
else
{
commentTextbox.Text = string.Empty;
menuText.Text += commentTextbox.Text;
}
}
您首先要清除文本框,因此,由于 commentTextbox.Text
是一个空字符串,您的最后一行实际上是在执行 menuText.Text += string.Empty;
您应该颠倒这些调用的顺序,例如:
private void commentButton_Click(object sender, RoutedEventArgs e)
{
if (String.IsNullOrWhiteSpace(commentTextbox.Text) == false)
{
menuText.Text += commentTextbox.Text;
commentTextbox.Text = string.Empty;
}
}