Region in TabControl

Topics: Prism v4 - WPF 4
Nov 14, 2011 at 3:30 AM

If changed Template to TabControl is empty, example:

<ControlTemplate x:Key="mykey" TargetType="{x:Type l:BivTabControl}">
        <Grid></Grid>

</ControlTemplate>

 

and apply this ControlTemplate to style:

<Setter Property="Template" Value="{StaticResource mykey}"/>

 

Result, Content TabControl  is empty, but I set View to TabControl Region.

If I Changed ither Template, example:

<ControlTemplate x:Key="mykey" TargetType="{x:Type l:BivTabControl}">
        <Grid>

<ScrollViewer Visibility="Hidden" >
                <TabPanel x:Name="TabPanel" IsItemsHost="True" />
            </ScrollViewer>

        </Grid>

</ControlTemplate>

 

this work - Content is contains my View.

How do I make sure not to put fake elements?:

<ScrollViewer Visibility="Hidden" >
                <TabPanel x:Name="TabPanel" IsItemsHost="True" />
            </ScrollViewer>

Nov 14, 2011 at 5:39 PM

up!

Developer
Nov 14, 2011 at 7:10 PM

Hi,

Based on my understanding, the Template property of the TabControl control specifies how the TabControl will be shown. So, if the ControlTemplate that is set to the Template property is empty, it might be normal that the control does not work correctly. For example if you create a TabControl using the following code, the control is never shown:

<TabControl>

      <TabControl.Template>
             <ControlTemplate>
                   <Grid></Grid>
             </ControlTemplate>
      </TabControl.Template>
            
      <TabItem>I'm a item.</TabItem>

</TabControl>

To change the template of a TabControl you might find useful the following article on MSDN:

If instead you want to set a template for the items in the TabControl, you might useful the ContentTemplate and ItemTemplate properties.

As this is not strictly related to Prism, you might find better support about this in the WPF Forums:

I hope you find this useful,

Damian Cherubini
http://blogs.southworks.net/dcherubini

Nov 15, 2011 at 12:04 AM
Edited Nov 15, 2011 at 12:09 AM

I'm sorry, of course, I forgot to ContentPresenter, both when skin is assumed that there is ContentPresenter in both cases.

Empty Template:

 

<ControlTemplate x:Key="mykey" TargetType="{x:Type l:BivTabControl}">
        <Grid>
               <ContentPresenter 
				    Content="{Binding Path=SelectedContent, RelativeSource={RelativeSource TemplatedParent}}"
				    ContentSource="SelectedContent" />
        </Grid>
</ControlTemplate>

 

Good Template:

<ControlTemplate x:Key="mykey" TargetType="{x:Type l:BivTabControl}"> 
     <Grid>
            <ScrollViewer Visibility="Hidden" >
                <TabPanel x:Name="TabPanel" IsItemsHost="True" />
            </ScrollViewer>
            <ContentPresenter 
                Content="{Binding Path=SelectedContent, RelativeSource={RelativeSource TemplatedParent}}" 
                ContentSource="SelectedContent" /> 
     </Grid> 
</ControlTemplate>

If you apply the first ControlTemplate, and try to put in the control region TabControl representation, it does not appear when using the second ControlTemplate that view is displayed.
I can not understand what was happening, any ideas?
Developer
Nov 15, 2011 at 8:33 PM

Hi,

Based on my understanding, the TabControl requires, at least, a child element that shows the TabItem headers and a child element that shows the contents of the selected TabItem. The TabPanel that is included in the second template is an element required by the TabControl to work correctly.

So, in the first ControlTemplate, the TabControl doesn't work because it doesn't have a child element to show the headers.

As far as I know, when defining a ControlTemplate for a TabControl, the template should have, at least, the following elements in order for the TabControl to work correctly:

<ControlTemplate TargetType="{x:Type TabControl}">
      <Grid>
            <Grid.RowDefinitions>
                  <RowDefinition Height="Auto"/>
                  <RowDefinition Height="*"/>
            </Grid.RowDefinitions>
                        
            <TabPanel Grid.Row="0" IsItemsHost="True"/>
                        
            <ContentPresenter Grid.Row="1" x:Name="PART_SelectedContentHost"
                              ContentSource="SelectedContent" />
      </Grid>
</ControlTemplate>
You can find more information about how to define a ControlTemplate for a TabControl in the following link:

Also, we have checked that this problem still happens when using your ControlTemplates without Prism.

Based on the aforementioned, it seems that this problem is not related to Prism.

I hope you find this useful,

Damian Cherubini
http://blogs.southworks.net/dcherubini

Nov 20, 2011 at 6:14 AM

Thank you, apparently, you're right, TabPanel element is required for template TabControl.