如何向我的选项卡控件添加关闭按钮?这就是我构建和运行后我的应用程序的样子。
如果我选择菜单 1.1,在菜单 2.2 之后它将显示如下。
这是我的用户控件的样子。我有两个用户控件,一个用于菜单 1.1(左),另一个用于菜单 1.2(右)。
我的问题是:1.是否可以为每个选项卡添加关闭按钮?2. 如果是,我该怎么做?
我已经关注了这个链接,但仍然无法做到。如果您添加小标题或长标题,该链接将使用相同的 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);
}
//* */
}