如何在动态WPF选项卡控件的选项卡中添加关闭按钮 [英] How to add Close Button in tab of Dynamic WPF Tab control
问题描述
我有一个WPF选项卡控件.
I have a WPF Tab Control..
我正在该TabControl中动态添加标签
i am adding tabs in that TabControl dynamically
现在我想在选项卡控件的每个选项卡中提供一个关闭按钮.
Now i want to give a Close Button in every Tab of Tab Control..
所以请告诉我,我希望在该Tab控件中添加关闭"按钮.
So please tell me hopw to add Close button in that Tab Control..
添加标签的代码
private void AddTab(ITabbedMDI mdiChild)
{
if (_mdiChildren.ContainsKey(mdiChild.UniqueTabName))
{
//user control is already opened in tab.
//So set focus to the tab item where the control hosted
foreach (object item in tcMdi.Items)
{
TabItem ti = (TabItem)item;
if (ti.Name == mdiChild.UniqueTabName)
{
ucChildLoc = (UserControl)mdiChild;
ti.Focus();
//tcMdi.Width = this.ucChildLoc.Width;
//tcMdi.Height = this.ucChildLoc.Height;
break;
}
}
}
}
关闭"标签的代码
private void CloseTab(ITabbedMDI tab, EventArgs e)
{
TabItem ti = null;
foreach(TabItem item in tcMdi.Items)
{
if (tab.UniqueTabName == ((ITabbedMDI)item.Content).UniqueTabName)
{
ti = item;
break;
}
}
if (ti != null)
{
_mdiChildren.Remove(((ITabbedMDI)ti.Content).UniqueTabName);
tcMdi.Items.Remove(ti);
}
}
我正在使用本文的TabControl
I am using TabControl of this article
http://www.codeproject.com/Articles/32362/WPF的选项卡式MDI
先谢谢了.
推荐答案
TabControl不提供关闭TabItem的功能.
TabControl does not provide the ability to close TabItems.
您可以添加一个"x"按钮,并将可见性设置为已折叠/隐藏"作为黑客.
You could add a 'x' button and set the visibility to Collapsed / Hidden as a hack.
或者您可以查看Infragistics的XamTabControl或其他任何支持关闭Tab的供应商产品.
OR You could look at XamTabControl by Infragistics or any other vendor product which does support closing of Tabs.
这篇关于如何在动态WPF选项卡控件的选项卡中添加关闭按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!