How do I set TabControls TabItem header FontSize

后端 未结 1 454
执笔经年
执笔经年 2021-01-27 05:17

I have a TabControl with a style that changes the FontSize of the Header of the TabItem. When I data bind the ItemsSource only the headers are affected by the FontSize. But when

1条回答
  •  孤独总比滥情好
    2021-01-27 05:50

    Your problem is a result of Property Value Inheritance.

    When you define the TabItems in xaml something like this:

     
         
             
         
         
     
    

    Both TextBoxes, the header, and the content are in the logical tree of the TabItem that means that any Inheritable property set on TabItem will be propagated down the tree to these TextBoxes.

    The Foreground and FontSize are Inheritable.

    If you have something like:

      TEST_CONTENT2
    

    you don't have any Elements in TabItem's logical tree, the elements for the Header and the content will be auto generated, and the properties will not be inherited. But this type of declaring TabItem's is not very useful, you usually need some advanced XAML as the items content so I think the best way to solve this is by changing all those text properties in TabItem's HeaderTemplate, you can bind to TabItem's properties using the RelativeSource.

    0 讨论(0)
提交回复
热议问题