3
votes

I'm pretty new to WPF / XAML. I have the following TabControl definition with a single TabItem definition:

<TabControl Grid.Row="1">
   <TabItem Header="CdTe Thickness">
      <Grid x:Name="CdTeThicknessGrid">
         <Grid.RowDefinitions>
            <RowDefinition Height=".4*" /> <!-- 40% -->
            <RowDefinition Height=".6*" /> <!-- 60% -->
         </Grid.RowDefinitions>
      </Grid>
   </TabItem>
   <TabItem Header="CdTe Roughness"></TabItem>
</TabControl>

Im my app, my TabControl will have at least a dozen TabItems like this. Each TabItem is going to have a grid with the same exact row definitions (as shown in the XAML). I really don't want to repeat this a dozen times (for each TabItem). I'm vaguely familiar with the concept of templates. Can I put these row definitions in a template of some sort and reuse them for each TabItem?

1

1 Answers

4
votes

You can do this using the same SharedSizeGroup for the same row across all tab items

<TabControl Grid.IsSharedSizeScope="True" Grid.Row="1">
   <TabItem Header="CdTe Thickness">
      <Grid x:Name="CdTeThicknessGrid">
         <Grid.RowDefinitions>
            <RowDefinition Height=".4*" SharedSizeGroup="FirstRow" />
            <RowDefinition Height=".6*" SharedSizeGroup="SecondRow" />
         </Grid.RowDefinitions>
      </Grid>
   </TabItem>
   <TabItem Header="CdTe Roughness"></TabItem>
</TabControl>

Useful links: