Olga
Olga

Reputation: 1455

tab of TabControl at the bottom in WPF

I use WPF (C #).

I want to tab TabControls were located at the bottom. For this I use the property: TabStripPlacement="Bottom".

However, the this property does not work because of my style:

<Grid>
 <Grid.Resources>
   <Style TargetType="{x:Type TabControl}">
     <Setter Property="Template">
       <Setter.Value>
         <ControlTemplate TargetType="{x:Type TabControl}">
           <Grid KeyboardNavigation.TabNavigation="Local">
             <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
             </Grid.RowDefinitions>

             <TabPanel IsItemsHost="True" />
             <ContentPresenter Grid.Row="1" ContentSource="SelectedContent"/>
           </Grid>
          </ControlTemplate>
        </Setter.Value>
      </Setter>
   </Style>
 </Grid.Resources>

 <TabControl TabStripPlacement="Bottom" >
     <TabItem Header="tab1">fff</TabItem>
     <TabItem Header="tab2"></TabItem>
     <TabItem Header="tab3"></TabItem>
 </TabControl>

</Grid>

Please tell me, How can I fix that tabs TabControls located at the bottom?

Upvotes: 1

Views: 4785

Answers (2)

Nitin Purohit
Nitin Purohit

Reputation: 18580

Update your control template as:

     <Grid>
        <Grid.Resources>
            <Style TargetType="{x:Type TabControl}">
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="{x:Type TabControl}">
                            <Grid KeyboardNavigation.TabNavigation="Local">
                                <Grid.RowDefinitions>
                                    <RowDefinition />
                                    <RowDefinition Height="Auto"/>
                                </Grid.RowDefinitions>
                                <ContentPresenter ContentSource="SelectedContent"/>
                                <TabPanel  Grid.Row="1" IsItemsHost="True" />

                            </Grid>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
        </Grid.Resources>

        <TabControl TabStripPlacement="Bottom" >
            <TabItem Header="tab1">fff</TabItem>
            <TabItem Header="tab2"></TabItem>
            <TabItem Header="tab3"></TabItem>
        </TabControl>

    </Grid>

Upvotes: 3

user128300
user128300

Reputation:

Move Grid.Row="1" to the <TabPanel...> element:

<TabPanel Grid.Row="1" IsItemsHost="True" />
<ContentPresenter ContentSource="SelectedContent"/>

Then, the tabs will be shown below the content.

Upvotes: 2

Related Questions