0
以下是我在Windows窗体应用程序,我怎样才能将其转换为WPF,考虑this.Controls
代码部分不可用:转换Windows窗体到WPF
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";
}
}
什么是WFA ...... –
Windows窗体应用程序 –
可能没有'在WPF'Window' Controls'属性,但您可以枚举对象?用一个'VisualTreeHelper'或一个'LogicalTreeHelper'。用[这个答案中的代码](http://stackoverflow.com/a/978352/559103),你可以用'foreach(FindVisualChildren(myWindow))中的TextBox tb枚举所有可见的'TextBox''' –