简体   繁体   中英

Custom tabitem in WPF

In WPF i want to create an custom TabItem which contains other controls.
After creating the TabItem, i want to add it to an TabControl.
The content of the TabItem will be created dynamically.

The TabItem only will be vissible after clicking on a button, and will close after entering the neccesary information. After closing the tab, there will be no blank space in the TabControl.

I tried with a custum control, an user control and a class which inherits from an TabItem. But none of them does what i want.

Which is the best solution in this case?

You want to set the TabItem content to the UserControl not inherit from TabItem. Also you can bind the TabControl.ItemsSource to a collection of UserControls that would make it dynamic like you want I believe.

I solved my problem.

Instead of crating an usercontrol for the tab, i created an usercontrol with the contents of the tab. In my case, that's a grid.

After that, i use the customcontrol to fill the tabitem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM