Search code examples
c#wpfprismtabcontrolregion

How prevent RegisterViewWithRegion adds new TabItems in PRISM?


OK

In my PRISM app I have 3 modules that each one have 3~6 views. in each module when Initialize method runs, after each RegisterViewWithRegion for each one of views, new TabItem appears in Shell's TabControl. But i want to just add one TabItem at startup and each time user execute a Command and Navigation occurs, new TabItem appears. Also user should be able to add or remove TabItems. What should i do? Implement a new RegionAdapter or what?

Here is my Shell TabControl:

<TabControl TabStripPlacement="Left" Grid.Column="2" Margin="6" VerticalAlignment="Stretch" HorizontalAlignment="Stretch"
            VerticalContentAlignment="Stretch" HorizontalContentAlignment="Stretch"
            prism:RegionManager.RegionName="{x:Static infrastructure:RegionNames.MainRagionName}">
    <TabItem />
</TabControl>

and This is RegisterViewWithRegion:

var codingMainTreeView = _container.Resolve<Views.CodingMainTreeView>();
_regionManager.RegisterViewWithRegion(RegionNames.MainRagionName, () => codingMainTreeView);

var vouchersMainView = _container.Resolve<Views.VouchersMainView>();
_regionManager.RegisterViewWithRegion(RegionNames.MainRagionName, () => vouchersMainView);

Solution

  • Answer from Damian Cherubini Here.