I am stuck in a very basic thing.
There are two user controls on a shell window. First one basically have a ribbon control. Second control basically has a tab control.
How can I add a new tab item when a button clicked on the ribbon? All the views including Shell share the same namespace.
In Ribbon.xaml
<UserControl x:Name="RibbonControl" ... >
In WorkSpace.xaml
<UserControl x:Name="WorkSpaceControl" ... >
In Shell.xaml
<RibbonWindow x:Name="ShellWindow" ... >
...
<Views:RibbonRegion x:Name="RibbonControl" />
<Views:WorkspaceRegion x:Name="WorkSpaceControl" />
...
</RibbonWindow>
In 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");
}
}
}
After a good sleep, here is the answer: