0
我被困在一個非常基本的東西。從另一個用戶控件添加TabItem
在shell窗口中有兩個用戶控件。第一個基本上有一個色帶控制。第二個控件基本上有一個標籤控件。
如何在功能區上單擊按鈕時添加新選項卡項目?包括Shell在內的所有視圖都共享相同的命名空間。
在Ribbon.xaml
<UserControl x:Name="RibbonControl" ... >
在WorkSpace.xaml
<UserControl x:Name="WorkSpaceControl" ... >
在Shell.xaml
<RibbonWindow x:Name="ShellWindow" ... >
...
<Views:RibbonRegion x:Name="RibbonControl" />
<Views:WorkspaceRegion x:Name="WorkSpaceControl" />
...
</RibbonWindow>
在Ribbon.xaml.cs
namespace Application.Views
{
public partial class RibbonControl: UserControl
{
private void Button_Click(object sender, RoutedEventArgs e)
{
//This throws the error that name is not available in current context.
WorkSpaceControl.AddDataTab("Hede");
//This doesn't throw error. But I think because the tab control
//has already initialized, it doesn't add the tab neither.
TabRegion su = new TabRegion();
su.AddDataTab("Hede");
}
}
}
看一看這裏: http://stackoverflow.com/questions/4968367/WPF-C-尖銳編程-添加和 - 運動突出部 – mola