简体   繁体   English

WPF中的自定义tabitem

[英]Custom tabitem in WPF

In WPF i want to create an custom TabItem which contains other controls.在 WPF 中,我想创建一个包含其他控件的自定义 TabItem。
After creating the TabItem, i want to add it to an TabControl.创建 TabItem 后,我想将其添加到 TabControl。
The content of the TabItem will be created dynamically. TabItem 的内容将被动态创建。

The TabItem only will be vissible after clicking on a button, and will close after entering the neccesary information. TabItem 仅在单击按钮后可见,并在输入必要信息后关闭。 After closing the tab, there will be no blank space in the TabControl.关闭选项卡后,TabControl 中将没有空格。

I tried with a custum control, an user control and a class which inherits from an TabItem.我尝试了自定义控件、用户控件和继承自 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.您希望将 TabItem 内容设置为 UserControl,而不是从 TabItem 继承。 Also you can bind the TabControl.ItemsSource to a collection of UserControls that would make it dynamic like you want I believe.您也可以将 TabControl.ItemsSource 绑定到 UserControls 的集合,这将使它像我相信的那样动态。

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.之后,我使用customcontrol 来填充tabitem。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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