これは、動作させるための単なるテストアプリケーションです
私のメインページは、テキストボックスを作成するためのコードを保持するビューモデルにバインドします
ここに私のxamlがあります
<StackPanel x:Name="StackSG" Grid.Row="1" Grid.Column="0"/>
<StackPanel x:Name="StackSGName" Grid.Row="1" Grid.Column="1"/>
次に、実際にテキスト ボックスを生成するためのボタンがあります。スタックパネルを定義してテキストボックスを作成する方法は次のとおりです。
private StackPanel stackSG;
public StackPanel StackSG
{
get { return stackSG; }
set { stackSG = value; OnNotifyPropertyChanged("StackSG"); }
}
private StackPanel stackSGName;
public StackPanel StackSGName
{
get { return stackSGName; }
set { stackSGName = value; OnNotifyPropertyChanged("StackSGName"); }
}
そして、ここでテキストボックスを追加してみます
private void Generate(object obj)
{
StackSG = new StackPanel();
StackSGName = new StackPanel();
int st = 10;
for (int i = 0; i < st; i++)
{
TextBox txtSG = new TextBox();
txtSG.Name = string.Format("{0}{1}", "Te", i.ToString());
txtSG.Height = 25;
txtSG.Text = string.Format("{0}{1}", "Te", i.ToString());
txtSG.IsReadOnly = true;
StackSG.Children.Add(txtSG);
//Add SG name textboxes
TextBox txtSGName = new TextBox();
txtSGName.Name = string.Format("{0}{1}", "Test", i.ToString());
txtSGName.Height = 25;
txtSGName.Text = string.Format("{0}{1}", "Test", i.ToString());
txtSGName.IsReadOnly = true;
StackSGName.Children.Add(txtSGName);
}
}
エラーなしで実行されますが、テキスト ボックスに広告が表示されません。