0
這僅僅是一個測試應用程序,使其能工作Silverlight的 - 如何在代碼中添加文本框到堆棧面板後面
我的炫魅結合我的視圖模型保存代碼來創建文本框
這裏是我的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);
}
}
它運行沒有錯誤,但沒有廣告我的文本框中。
你檢查的寬度和高度你父母的網格的行和列?另外,你是否將一個靜態高度放到了堆棧面板上以確保文本框可以出現? – Oliver