Click here to Skip to main content
15,880,299 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi guys,

I have a tab item and a user control. I want to add the user control to tab item at runtime?
Any one can help me in doing that?
Updated 20-Nov-10 3:13am

Just instantiate it and add it to the Children collection of the parent container. Assuming you have a grid in the TabItem called "LayoutRoot":

MyControl ctrl = new MyControl();
Share this answer
Tarun.K.S 20-Nov-10 12:53pm    
Good answer!
You can add user control at run time by using given code
UserControl1 obj = new UserControl1(); // UserControl1 is a created User control.
this.tbgrid1.Children.Add(obj); // here tbgrid1 is the name of Grid of TabItem.

Share this answer
Tarun.K.S 20-Nov-10 13:00pm    
Good answer!
#realJSOP 20-Nov-10 19:13pm    
And how is this answer different from mine, which was also posted an hour earlier than yours?
RaviRanjanKr 20-Nov-10 21:03pm    
Hey John Simmons its my fault,
I apologize I didn't focus on your answer while writing my answer. so sorry once again.
Tarun.K.S 21-Nov-10 4:22am    
It often happens!

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

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900