WPF获取/复制TabItem的内容

问题描述:

Heya,



我有一个使用TabHead / TabItem元素的WPF应用程序。我想在运行时创建新元素,内容与第一个元素相同(通常是包含更多元素的网格)。



Basicaly我希望函数看起来类似这样的事情:



Heya,

I have a WPF application that is using the TabHead/TabItem elements. I want to create new elements at runtime, with the same content as the first element (usually a grid with more elements).

Basicaly I would want the function to look something like this:

public TabItem TabItemAdd(TabControl CHead, TabItem Example, String Header="New Tab" )
{
TabItem item = new TabItem();
item.Content = Example.Content;  // <-- This line doesn't work and is the problem
item.Header = Header;
CHead.Items.Add(item);

return item;
}





现在我知道这不起作用,因为TabItem示例的元素已经全部是CHead的孩子了,但我不确定如何解开它们或让它工作



提前谢谢



Now I know that this doesn''t work because the elements of the TabItem Example are allready childrean of CHead, but I''m not exactly sure how to unbind them or get it to work

Thanks in advance

您可以获取标签项的克隆。然后尝试添加。它将是工作
you can get a clone for tab item . then try to add. it will be work