Search code examples
c#wpftabstooltip

C# WPF how to set tooltip size in a tabcontrol


I have a tabcontrol in which each tabITem is rendered a very big font symbol (see image below)

pic1 big font size for tab header

now the tooltip is set to a very big size according to the very big size of the aforementioned tabItem char.

enter image description here

What I'd like is to keep the tabItem symbol very big but being able to resize the tooltip font.

PLUS I can't understand why the tabheader tooltip is randomly set on all children. I want it on the tabheader itself and not floating everywhere!

enter image description here

--EDIT--- As requested here is a relevant part of my xaml. I only include tab2 which is shorter but there are several tabItems and all behave the same way.

 <!-- +++++++++++++ TAB2 ++++++++++++ -->
  <TabItem Name="tabItem2" HorizontalAlignment="Center" Height="80" IsSelected="false" FontSize="{StaticResource TAB_FONTSIZE}">
    <TabItem.Header>
      <StackPanel>
        <TextBlock Text="&#xF0F7;"/>  <-------------unicode symbol very big!
        <TextBlock Name="tbTab2" Visibility="Hidden" FontSize="{StaticResource BUTTON_FONTSIZE}" />
      </StackPanel>
    </TabItem.Header>
    <TabItem.Background>
      <ImageBrush/>
    </TabItem.Background>
  </TabItem>

while tooltip is set in code-behind

tabItem2.ToolTip = Langs.Word(Langs.eWords.Pallet);

and it gets the HUGE size of the aforementioned unicode char.

Thanx for any help


Solution

  • The problem here is that you set both font size and tooltip directly on the TabItem, and those are then "inherited" by the item's header and content (the font size is also "inherited" by their tooltips). So in order to accomplish what you're asking you need to be more precise when setting those properties, i.e. set them on appropriate controls and not on the TabItem itself. In your case the following should work as expected.

    You want to use the large font only for the unicode character, so set the FontSize property only on the control displaying that character:

    <TextBlock Text="&#xF0F7;" FontSize="{StaticResource TAB_FONTSIZE}" />
    

    You want the tooltip to be displayed only for the header, therefore you should set it on the header. You can do that either in XAML:

    <TabItem.Header>
        <StackPanel ToolTip="My tooltip text">
        ...
        </StackPanel>
    </TabItem.Header>
    

    or in code-behind:

    var stackPanel = (StackPanel)tabItem2.Header;
    stackPanel.ToolTip = "My tooltip text";