3

Hi I need to specify a a static with to the headers of a tab control. The names are generating dynamically so I could get something with 150 characters. . . . I know i could take the string and cut it with the first 10 characters or something like that, but I don't want the easy way :P

P.D

This answer did not work for my problem, actually it did nothing.

Community
  • 1
  • 1
Yoiku
  • 882
  • 2
  • 13
  • 25

3 Answers3

2
<TabControl>
    <TabItem>
        <TabItem.Header>
            <TextBlock Width="100" Text="slad asdljlajksdflajsdf;ljlj;asdlljsaldkjlasdfjkl"/>
        </TabItem.Header>
    </TabItem>
    <TabItem>
        <TabItem.Header>
            <TextBlock Width="75" Text="slad asdljlajksdflajsdf;ljlj;asdlljsaldkjlasdfjkl"/>
        </TabItem.Header>
    </TabItem>
</TabControl>
paparazzo
  • 44,497
  • 23
  • 105
  • 176
1

Setting TextBlock.MaxWidth worked just fine for me. I used it inside the ItemTemplate , e.g.

<TabControl.ItemTemplate>
    <DataTemplate DataType="viewModels:ITabViewModel">
        <TextBlock Text="{Binding DisplayName}" ToolTip="{Binding ToolTip}"
            TextTrimming="CharacterEllipsis" MaxWidth="150" />
    </DataTemplate>
</TabControl.ItemTemplate>
mkoertgen
  • 898
  • 6
  • 14
  • a width of 130 to 180 pixels seems to be a good fit for tabs. Chrome uses ~130 pixels for its tabs, Visual Studio about 180 pixels for Code File Tabs. – mkoertgen Jun 26 '14 at 14:38
0

Another possible solution:

    <TabControl>
        <TabControl.Resources>
            <Style TargetType="{x:Type TabItem}">
                <Setter Property="HeaderTemplate">
                    <Setter.Value>
                        <DataTemplate>
                            <TextBlock Text="{Binding}" MaxWidth="200" />
                        </DataTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
        </TabControl.Resources>
    </TabControl>
pistipanko
  • 745
  • 5
  • 9