-1

I want to open a Text box on this button click (create it in runtime, when user clicks the button), and store a string.

private void button5_Click(object sender, RoutedEventArgs e)
{
    TextBox dynamicTextBox = new TextBox();
    dynamicTextBox.Text = "Type Partnumber";
} 
2

3 Answers 3

1

Add your TextBox to Grid children and set column and row numbers.

private void button1_Click(object sender, RoutedEventArgs e)
        {
            TextBox dynamicTextBox = new TextBox();
            dynamicTextBox.Text = "Type Partnumber";
            Grid.SetRow(dynamicTextBox, 1);
            Grid.SetColumn(dynamicTextBox, 0);
            this.MainGrid.Children.Add(dynamicTextBox);
        }
Sign up to request clarification or add additional context in comments.

Comments

0

Try like this

private void button5_Click(object sender, EventArgs e)
        {
            TextBox dynamicTextBox = new TextBox();
            // your code
            this.Controls.Add(dynamicTextBox);
        }

Comments

0

Say, you have a Grid in your XAML part and name it as "grid" and access that grid to add this newly created TextBox

private void button5_Click(object sender, RoutedEventArgs e)
{
  TextBox dynamicTextBox = new TextBox();
  dynamicTextBox.Text = "Type Partnumber";
  grid.Children.Add(dynamicTextBox);
} 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.