views:

342

answers:

1

Hello, I have idea to implement my wpf windows like TabPages in tab control. It is possible to do that dinamically in c# code. In Example i have Menu in main window. Some Menu items calls search type windows. Is it possible to do such a thing in C# code (SomeMenuItem_Click): this code adds new tab in tabControl of main window. If there are no search windows called -there is no tab's shown, if there are many search windows called - there are many tab's. So how i must write code like that And whats the technique with the windows..?I suppose that my search type windows must be implemented like some UserControl's. I think its no a good idea to implement that like simple wpf windows. I have tryed to do that by using Marlon grech "Blend like UIs using DOCKY", find at: http://marlongrech.wordpress.com/2008/01/29/create-blend-like-uis-using-docky/ but I failed, dont find the way how to add controlls in code dinamically, not in xaml. Any examples and suggestions would be helpfull. Thanks.

+1  A: 

Is it possible to do such a thing in C# code (SomeMenuItem_Click): this code adds new tab in tabControl of main window.

Yes. The basic pattern is:

TabItem newItem = new TabItem();
tabControl.Items.Add(newItem);

You'll obviously need to set the relevant properties of your tab item (such as the Header and Style) but that should get you started.

You'll then need to create any controls you want to show and add them to the tab item itself (or more correctly - a container within the tab item).

ChrisF
How to add some userControl in this code? In other words- how to fill in c# content of this tabItem? I guess its possible only to add some userControl, but no wpf window..?
Vytas999