Reputation: 552
I am creating a shell. XAML
which houses only a TabControl
. I am trying to create new tabs on a button click event. With the code that I have written till now I am able to create new tabs on a button click event but the content of the Tab (a region) is only shown on the FIRST Tab and the new tabs that are created are empty. I.e. I am not able to show the same content (the region) in the newly created tabs...
Shell.XAML
<TabControl Name="MyTabs"
Prism:RegionManager.RegionName="{x:Static inf:RegionConstants.MainRegion}">
</TabControl>
UserControl
that I wish to add to tabs:
MainControls.XAML
<UserControl>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid x:Name="LeftGrid" Grid.Row="0" Grid.Column="0" Prism:RegionManager.RegionName="{x:Static inf:RegionConstants.InputRegion}">
<GridSplitter>
<Grid x:Name="RightGrid" Grid.Row="0" Grid.Column="0" Prism:RegionManager.RegionName="{x:Static inf:RegionConstants.OutputRegion}">
</Grid>
</UserControl>
Function to Add Tab
private void New_Tab(object sender, RoutedEventArgs e)
{
TabItem tab = new TabItem();
tab.Header = "New Tab";
tab.Content = new MainControls();
MyTabs.Items.Add(tab);
}
Module for Registering MainRegion
class CollaboratedModule :IModule
{
private IUnityContainer container = default(IUnityContainer);
private IRegionManager regionManager = default(IRegionManager);
public CollaboratedModule(IUnityContainer container, IRegionManager regionManager)
{
this.container = container;
this.regionManager = regionManager;
}
public void Initialize()
{
if (this.container != default(IUnityContainer) &&
this.regionManager != default(IRegionManager))
{
var IntergratedView = this.container.Resolve<MainControls>();
this.regionManager.AddToRegion(RegionConstants.MainRegion, IntergratedView);
this.regionManager.Regions[RegionConstants.MainRegion].Activate(IntergratedView);
}
}
}
Similarly i have created a Module for registering InputRegion
and the OutputRegion
. Can anyone let me know where is the issue in this code and how can I resolve it?
Upvotes: 1
Views: 5120
Reputation: 1
just try this way
regionManager.RegisterViewWithRegion(RegionConstants.MainRegion, () => IntergratedView);
Upvotes: 0