menuText is the textblock and commentTextbox is the textbox. I have cleared the textbox when text is inputted into the textbox. How do I make the text input in the textbox to appear in the textblock when the commentButton is clicked?
private void commentButton_Click(object sender, RoutedEventArgs e)
{
if (string.IsNullOrWhiteSpace(commentTextbox.Text))
{
}
else
{
commentTextbox.Text = string.Empty;
menuText.Text += commentTextbox.Text;
}
}
You are clearing the text box first, so, since commentTextbox.Text
is an empty string, your last line is effectively doing menuText.Text += string.Empty;
You should invert the order of those calls, like that:
private void commentButton_Click(object sender, RoutedEventArgs e)
{
if (String.IsNullOrWhiteSpace(commentTextbox.Text) == false)
{
menuText.Text += commentTextbox.Text;
commentTextbox.Text = string.Empty;
}
}