2012-06-07 25 views
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"); 

    } 
    } 
} 
+0

看一看這裏: http://stackoverflow.com/questions/4968367/WPF-C-尖銳編程-添加和 - 運動突出部 – mola

回答

0

一個良好的睡眠後,這裏就是答案:

Shell MainFrm = (Shell)App.Current.MainWindow; 
MainFrm.WorkSpaceControl.AddDataTab("Something"); 
相關問題