如何在我的标签控件中添加一个关闭按钮? 这是我的应用程序在构建和运行后的样子。
如果我选择菜单1.1,在菜单2.2之后它将显示如下。
这是我的usercontrol看起来像。我有两个用户控件,一个用于菜单1.1(左),其他用于菜单1.2(右)。
我的问题是: 1.可以为每个标签添加关闭按钮吗? 2.如果是的话,我该怎么做?
我已经遵循了此link,但仍无法做到。如果您添加小标题或长标题,该链接将使用相同的UI。但现在我为每个标签设置了不同的UI。我该如何处理关闭按钮?谢谢。
这是我的xaml。
<ribbon:Ribbon x:Name="Ribbon">
<ribbon:Ribbon.ApplicationMenu>
<ribbon:RibbonApplicationMenu SmallImageSource="Images\SmallIcon.png">
<ribbon:RibbonApplicationSplitMenuItem Header="Menu 1"
ImageSource="Images\LargeIcon.png" Name="RibbonSplit">
<ribbon:RibbonApplicationMenuItem Header="Menu 1.1"
x:Name="RibbonMenu1"
ImageSource="Images\LargeIcon.png" Click="RibbonMenu1_Click"/>
</ribbon:RibbonApplicationSplitMenuItem>
<ribbon:RibbonApplicationSplitMenuItem Header="Menu 2" ImageSource="Images\LargeIcon.png">
<ribbon:RibbonApplicationMenuItem Header="Menu 2.1"
x:Name="RibbonMenu2"
ImageSource="Images\LargeIcon.png" Click="RibbonMenu2_Click"/>
</ribbon:RibbonApplicationSplitMenuItem>
</ribbon:RibbonApplicationMenu>
</ribbon:Ribbon.ApplicationMenu>
</ribbon:Ribbon>
<TabControl Grid.Row="1" Height= "394" Name="TabMenu" VerticalAlignment="Top">
</TabControl>
这是我添加标签的代码,
tab2 tb1 = new tab1(); //menu1.1
AddTab(tb1);
这是我的AddTab方法,
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 TabMenu.Items)
{
TabItem ti = (TabItem)item;
if (ti.Name == mdiChild.UniqueTabName)
{
ti.Focus();
break;
}
}
}
else
{
//the control is not open in the tab item
TabMenu.Visibility = Visibility.Visible;
TabMenu.Width = this.ActualWidth;
TabMenu.Height = this.ActualHeight;
//((ITabbedMDI)mdiChild).CloseInitiated += new delClosed(CloseTab);
//create a new tab item
TabItem ti = new TabItem();
//set the tab item's name to mdi child's unique name
ti.Name = ((ITabbedMDI)mdiChild).UniqueTabName;
//set the tab item's title to mdi child's title
ti.Header = ((ITabbedMDI)mdiChild).Title;
//set the content property of the tab item to mdi child
ti.Content = mdiChild;
ti.HorizontalContentAlignment = HorizontalAlignment.Stretch;
ti.VerticalContentAlignment = VerticalAlignment.Top;
//add the tab item to tab control
TabMenu.Items.Add(ti);
//set this tab as selected
TabMenu.SelectedItem = ti;
//add the mdi child's unique name in the open children's name list
_mdiChildren.Add(((ITabbedMDI)mdiChild).UniqueTabName, ((ITabbedMDI)mdiChild).Title);
}
//* */
}