WPF how do I create a textbox dynamically and find the textbox on a button click?

后端 未结 5 883
不思量自难忘°
不思量自难忘° 2021-02-04 04:19

I am creating a TextBox and a Button dynamically using the following code:

Button btnClickMe = new Button();
btnClickMe.Content = \"Cli         


        
5条回答
  •  醉话见心
    2021-02-04 04:19

    You can get your original click handler to work by registering the name of the text box:

    someStackPanel.RegisterName(txtNumber.Name, txtNumber);
    

    This will then allow you to call FindName on the StackPanel and find the TextBox.

提交回复
热议问题