以下是我在 Windows 窗体应用程序中的代码的一部分,我如何将其转换为 WPF,考虑到this.Controls
不可用:
public Form1()
{
InitializeComponent();
foreach (TextBox tb in this.Controls.OfType<TextBox>())
{
tb.Enter += textBox_Enter;
}
}
void textBox_Enter(object sender, EventArgs e)
{
focusedTextbox = (TextBox)sender;
}
private TextBox focusedTextbox = null;
private void button1_Click (object sender, EventArgs e)
{
if (focusedTextbox != null)
{
focusedTextbox.Text += "1";
}
}