Tiago
Tiago

Reputation: 3131

Conditional TabItem styling

How can I set the first TabItem inside a TabControl with a custom style:

<Style TargetType="{x:Type TabControl}">
    <Style.Resources>
        <Style TargetType="{x:Type TabItem}">
        ...

What I'm trying to archive is to get the first TabItem with a left margin, and the others with margin = 0.

To illustrate what I'm trying to do:

How the tab control looks now: enter image description here

How it should look (space before the first TabItem): enter image description here

A different approach with the same results is also useful.

Upvotes: 0

Views: 93

Answers (1)

DonGru
DonGru

Reputation: 13710

What you could do to achieve this is simply add an invisible, empty TabItem at first position:

 <TabItem Visibility="Hidden"/>

Hidden will cause that the tab control is not shown, but space is anyway reserved for it, so it turns out to look like something like that: enter image description here

The space can be simply enlarged by choosing a Headerfor the TabItem with the appropriate amount of characters

Alternatively you can simply add some margin to the first TabItem itself

 <TabItem Header="TabItem1" Margin="5,0,0,0">

but that might result in that the Name of TabItem1 is cut off at the right side

Upvotes: 1

Related Questions