RadomRadom RadomRadom - 18 days ago 6
C# Question

Trying to autosize grid on tab control to fill the right side, but has a border around it

I am trying to dock the grid to fill in the whole right side of the form, but it is not docking regardless of me using stretch.

You should have put an image description here...

Code I am using:

<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="7*"/>
<ColumnDefinition Width="40*"/>
</Grid.ColumnDefinitions>
<TabControl x:Name="tabControl" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" TabStripPlacement="Left" Background="#FF374E5A" BorderBrush="#FF374E5A" Foreground="#FF374E5A" SelectionChanged="tabControl_SelectionChanged" Grid.ColumnSpan="2">
<TabItem Header="TabItem" Foreground="#FF374E5A" BorderBrush="#FF374E5A" Background="#FF374E5A" Style="{DynamicResource TabItemStyle1}">
<Grid Background="#FFE5E5E5"/>
</TabItem>
<TabItem Header="TabItem" BorderBrush="#FF374E5A" Foreground="#FF374E5A" Background="#FF374E5A" Height="24" VerticalAlignment="Top" Style="{DynamicResource TabItemStyle2}">
<Grid Background="#FFE5E5E5" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Margin="-2,0,0,0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="12*"/>
<ColumnDefinition Width="53*"/>
</Grid.ColumnDefinitions>
</Grid>
</TabItem>
</TabControl>

</Grid>


How can I fix this so the left side is the tabs(color) and the right side is the gray grid with no blue around it?

Answer

TabControl has a default padding value.You Should Set it "0" Like This;

Padding="0"

<Grid>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="7*"/>
        <ColumnDefinition Width="40*"/>
    </Grid.ColumnDefinitions>
    <TabControl x:Name="tabControl" Padding="0" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" TabStripPlacement="Left" Background="#FF374E5A" BorderBrush="#FF374E5A" Foreground="#FF374E5A" SelectionChanged="tabControl_SelectionChanged" Grid.ColumnSpan="2">
        <TabItem Header="TabItem" Foreground="#FF374E5A" BorderBrush="#FF374E5A" Background="#FF374E5A" Style="{DynamicResource TabItemStyle1}">
            <Grid Background="#FFE5E5E5"/>
        </TabItem>
        <TabItem Header="TabItem" BorderBrush="#FF374E5A" Foreground="#FF374E5A" Background="#FF374E5A" Height="24" VerticalAlignment="Top" Style="{DynamicResource TabItemStyle2}">
            <Grid Background="#FFE5E5E5" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Margin="-2,0,0,0">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="12*"/>
                    <ColumnDefinition Width="53*"/>
                </Grid.ColumnDefinitions>
            </Grid>
        </TabItem>
    </TabControl>

</Grid>