Alex Hope O'Connor
Alex Hope O'Connor

Reputation: 9684

WPF TabControl remove header padding?

I am trying to make it so that I can perform a command when the user clicks on a TabItem header in my TabControl.

Here is my code:

      <TabControl TabStripPlacement="Left" BorderThickness="1,0,0,0">
        <TabItem Selector.IsSelected="{Binding IsGeneric, Mode=OneWay}">
            <TabItem.Header>
                <Button Content="Generic" Margin="0" Command="{Binding GenericSelected}"></Button>
            </TabItem.Header>
            <V:WasteEstimationGenericView DataContext="{Binding}"></V:WasteEstimationGenericView>
        </TabItem>
        <TabItem Selector.IsSelected="{Binding IsSTP, Mode=OneWay}">
            <TabItem.Header>
                <Button Content="STP" Margin="0" Command="{Binding STPSelected}"></Button>
            </TabItem.Header>
            <V:WasteEstimationSTPView DataContext="{Binding STPViewModel}"></V:WasteEstimationSTPView>
        </TabItem>
    </TabControl>

However I end up this something that looks like this: TabControl Headers

Can someone please tell me how to make my TabControl headers consume all the available space in the TabItem Header? I originally wanted to do this using a label but it had a problem where if the user clicked towards the edge of the header it would not execute the command, I would still prefer this to using buttons, but the buttons allow the users to target where they click.

Upvotes: 0

Views: 3880

Answers (2)

Mark Hall
Mark Hall

Reputation: 54532

You will need to Modify the TabItem ControlTemplate, more specifically the ContentPresenter, setting the VerticalAlignment and HorizontalAlignment to Stretch and setting the Margin to what you are wanting, it is defaulted to 12,2,12,2.

Upvotes: 2

failedprogramming
failedprogramming

Reputation: 2522

Try this:

<TabControl TabStripPlacement="Left" BorderThickness="1,0,0,0" HorizontalContentAlignment="Stretch">

Upvotes: 0

Related Questions