1

The software I am working is for a printing company. I have a total of 5 different Views/VMs that I could possibly display in a single TabItem inside of the TabControl. I am creating a list of them on the TabControlViewModel I have created. So for example List - FormsViewModel, PlasticsViewModel, LabelsViewModel; This list should produce 3 Dynamic Tabs containing their respective View. On top of this I was hoping to be able to actually develop it so that I have a different view from this list as the first tab, then the last tab would also have a different view from the list. Basically 2 tabs that would surround the list of dynamic tabs. Here is the code I have been messing around with so far.

 <UserControl.Resources>
    <ResourceDictionary>
        <DataTemplate DataType="{x:Type jobDetails:JobProductionAddOnViewModel}">
            <jobDetails:JobProductionAddOnView />
        </DataTemplate>
        <DataTemplate DataType="{x:Type forms:FormsDetailViewModel}">
            <forms:FormsDetailView />
        </DataTemplate>
        <DataTemplate DataType="{x:Type labels:LabelsDetailViewModel}">
            <labels:LabelsDetailView />
        </DataTemplate>
        <DataTemplate DataType="{x:Type plastics:PlasticsDetailViewModel}">
            <plastics:PlasticsDetailView />
        </DataTemplate>
        <DataTemplate DataType="{x:Type specialtyCoatings:SpecialtyCoatingsDetailViewModel}">
            <specialtyCoatings:SpecialtyCoatingsDetailView />
        </DataTemplate>
        <DataTemplate DataType="{x:Type digitalLabels:DigitalLabelDetailViewModel}">
            <digitalLabels:DigitalLabelDetailView />
        </DataTemplate>
    </ResourceDictionary>
</UserControl.Resources>
<Grid>
    <TabControl ItemsSource="{Binding AdditionalDetailsViewModelList}"
                controls:TabControlHelper.IsUnderlined="True" 
                controls:TabControlHelper.Transition="Left"
                TabStripPlacement="Left"
                SelectedIndex="{Binding SelectedIndex}"
                ItemContainerStyle="{StaticResource ProductionTabItem}">
        <TabItem>
            <TabItem.Header>
                <Label Content="Primary"
                       Width="100"
                       HorizontalContentAlignment="Center"/>
            </TabItem.Header>
            <AdornerDecorator>
                <ContentControl Content="{Binding PrimaryDetailsViewModel}" />
            </AdornerDecorator>
        </TabItem>
        <!--I have tried adding an ItemsControl here, didn't work-->
        <!--I have also tried adding ItemsSource and binding it to the dynamic list-->
        <!--But can't figure out how to change the view based on the type of viewmodel like-->
        <!--you would with an itemscontrol-->
        <TabItem>
            <TabItem.Header>
                <Label Content="+"
                       Width="100"
                       HorizontalContentAlignment="Center"/>
            </TabItem.Header>
            <AdornerDecorator>
                <ContentControl Content="{Binding JobProductionAddOnViewModel}" />
            </AdornerDecorator>
        </TabItem>
    </TabControl>
</Grid>

1 Answers1

1

This was the solution I came to. And I got most of my idea from this post here. The ViewModel property is an interface that my ViewModels inherit called IBaseViewModel.

 <UserControl.Resources>
    <ResourceDictionary>
        <DataTemplate DataType="{x:Type jobDetails:JobProductionAddOnViewModel}">
            <jobDetails:JobProductionAddOnView />
        </DataTemplate>
        <DataTemplate DataType="{x:Type forms:FormsDetailViewModel}">
            <forms:FormsDetailView />
        </DataTemplate>
        <DataTemplate DataType="{x:Type labels:LabelsDetailViewModel}">
            <labels:LabelsDetailView />
        </DataTemplate>
        <DataTemplate DataType="{x:Type plastics:PlasticsDetailViewModel}">
            <plastics:PlasticsDetailView />
        </DataTemplate>
        <DataTemplate DataType="{x:Type specialtyCoatings:SpecialtyCoatingsDetailViewModel}">
            <specialtyCoatings:SpecialtyCoatingsDetailView />
        </DataTemplate>
        <DataTemplate DataType="{x:Type digitalLabels:DigitalLabelDetailViewModel}">
            <digitalLabels:DigitalLabelDetailView />
        </DataTemplate>
    </ResourceDictionary>
</UserControl.Resources>
<Grid>
    <TabControl ItemsSource="{Binding TabItems}"
                controls:TabControlHelper.IsUnderlined="True" 
                controls:TabControlHelper.Transition="Left"
                TabStripPlacement="Left"
                SelectedIndex="{Binding SelectedIndex}"
                ItemContainerStyle="{StaticResource ProductionTabItem}">
        <TabControl.ItemTemplate>
            <DataTemplate>
                <TextBlock Text="{Binding Header}"
                           Width="150"/>
            </DataTemplate>
        </TabControl.ItemTemplate>
        <TabControl.ContentTemplate>
            <DataTemplate>
                <ContentControl Content="{Binding ViewModel}" />
            </DataTemplate>
        </TabControl.ContentTemplate>
    </TabControl>
</Grid>