TabControl.ItemTemplate: set TabItem.Header.Text to a MultiBinding with StringFormat

Viewed 29335

How do I set the TabItem.Header to bindings taken from few fields, each binding shown in a different size, all in the place of the original header text; without overriding the default style and behavior of the header - I only need the text.

I tried to set its template but then it creates a rectangle that contains the inner controls, and this rectangle is not responsive for user clicks, and also have the control-style, I want this controls to be invisible, only its text should be visible.

I've tried the following:

<TabControl ItemsSource="{Binding}">
    <TabControl.ItemTemplate>
         <DataTemplate>
             <TabItem>
                 <TabItem.Header>
                     <MultiBinding StringFormat="{}{0}-{1}">
                         <Binding Path="Title"/>
                         <Binding Path="Category.Title"/>
                     </MultiBinding>
                 </TabItem.Header>
                 <TabItem.Content>
                     <TextBlock>
                         Here is what is gonna be in the TabItem - not header
                     </TextBlock>
                 </TabItem.Content>
             </TabItem>
         </DataTemplate>
    </TabControl.ItemTemplate>
</TabControl>

But it doesn't show anything.

I've also tried to set the HeaderTemplate to a DataTemplate but what happens is, the DataTemplate overrides the TabItem style and when I click the text it doesn't go to the clicked tab, besides, the unselected tabs look very funny, I see the rectangle of the text floating, while I want it to be transparent.

So, to summarize up my question, I want to set TabItem.Header.Text to a MultiBinding with StringFormat.

1 Answers
Related