Click here to Skip to main content
11,637,415 members (58,453 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# WPF GUI .NET4
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;
}
 

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
Posted 23-Nov-11 9:39am
Y0UR248
Edited 23-Nov-11 12:00pm
v3
Comments
SteveAdey at 18-Jan-12 4:15am
   
Try using XamlReader to get the xaml out and then create that in the new TabItem.

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

you can get a clone for tab item . then try to add. it will be work
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 295
1 stibee 288
2 jyo.net 270
3 Sergey Alexandrovich Kryukov 224
4 himanshu agarwal 184
0 OriginalGriff 9,031
1 Sergey Alexandrovich Kryukov 8,643
2 Mika Wendelius 6,959
3 F-ES Sitecore 2,388
4 Suvendu Shekhar Giri 2,320


Advertise | Privacy | Mobile
Web03 | 2.8.150728.1 | Last Updated 10 Apr 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100