3

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?

sll
  • 61,540
  • 22
  • 104
  • 156
Hosea146
  • 7,412
  • 21
  • 60
  • 81

1 Answers1

4

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:

sll
  • 61,540
  • 22
  • 104
  • 156