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''' –