Set the tab item text as bold in WPF tab control

风流意气都作罢 提交于 2019-12-02 07:48:11

问题


When I set my tab item font weight to bold, all the controls within that tab become bold. How do I set just the text header of the tab item without affecting the controls?


回答1:


This is what I did to get it to work. Thanks, SeeSharp, for the hint.

            <TabControl.Resources>
            <Style TargetType="{x:Type TabItem}">
                <Setter Property="HeaderTemplate">
                    <Setter.Value>
                            <DataTemplate>
                                <TextBlock FontWeight="Bold" Text="{Binding}"/>
                            </DataTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
            </TabControl.Resources>



回答2:


Use ItemTemplate to set template for tab header. Example:

<TabControl ItemsSource="{Binding Items}">
            <TabControl.ItemTemplate>
                <DataTemplate>
                    <TextBlock FontWeight="UltraBold" Text="{Binding Caption}"/>
                </DataTemplate>
            </TabControl.ItemTemplate>


来源:https://stackoverflow.com/questions/4677840/set-the-tab-item-text-as-bold-in-wpf-tab-control

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!