我試圖在運行時將控件添加到另一個控件。這是我到目前爲止有:在運行時將控件添加到子控件
必須在.NET 3.5
public void addItem(Type addType, Type parentType, string name,string parentName, string fpath)
{
try
{
if (asdf != null)
{
}
else
{
StackPanel stkPnl = (StackPanel)_loadXaml.Content;
foreach (UIElement child in stkPnl.Children)
{
if ((child.GetType() == parentType))
{
Control theChild = (Control)child;
string theChildsName = theChild.Name;
if (theChildsName == parentName)
{
//I want to create and add the control under "theChild"
break;
}
}
}
}
}
catch (Exception e)
{
MessageBox.Show(e.ToString());
}
}
將AddType來完成:是的控件的類型
ParentType的:是希望對象的父類型要添加
名稱:是將添加
parentName對象的名稱:是,創建的對象將是下
我有父的名字牛逼ried .Children.Add不是「theChild」
的選項.content不是「theChild」的選項
是否有任何方法在運行時將控件添加到其父項?
AddVisualChild不是一個選項 – David