foreach文を操作することはできません 「System.Windows.Controls.GroupBoxので、タイプ の変数に「System.Windows.Controls.GroupBox」を操作することはできませんGetEnumeratorメソッド ''の公開 の定義が含まれていない'foreach文は、型の変数に「System.Windows.Controls.GroupBox」
mycode:
foreach (var txt in this.groupBox1.Children)
{
if (txt is TextBox)
{
(txt as TextBox).Text = string.Empty;
}
}
しかし、なぜグリッドの正しいコードはありますか?
groupBoxの正しいコードは何ですか?
///////////////// 編集
正しいコード:
foreach (var txt in this.MyGridInGroupBox.Children)
{
if (txt is TextBox)
{
(txt as TextBox).Text = string.Empty;
}
}
動作しません:のために(私は= 0をint型;私はVisualTreeHelper.GetChildrenCount(groupBox1を)<;私は++) { VARをtxt = VisualTreeHelper.GetChild(groupBox1、i); if(txtがTextBoxの場合) { (TextBoxとしてのtxt).Text = string.Empty; } } – mrJack
@mrJack「うまくいかない」とは? –
あなたのコードを更新した後は美しいです。 – mrJack