如何为这个选项卡项的标题和内容设置不同的字体?

时间:2022-03-22 22:42:25

How can I set different fonts for tabitem header and content of this tabitem??

如何为这个选项卡项的标题和内容设置不同的字体?

1 个解决方案

#1


1  

Like anything in WPF, there are many ways. Without knowing exactly what you are trying to do, here is one "for instance" (I wouldn't suggest using this combination of fonts:) )

就像WPF中的任何东西一样,有很多方法。在不知道自己想要做什么的情况下,这里有一个“例如”(我不建议使用这种字体组合:)

    <TabControl>
        <TabControl.Resources>
            <Style TargetType="{x:Type TextBlock}">
                <Setter Property="FontFamily" Value="Comic Sans MS" />
                <Setter Property="FontSize" Value="20" />
            </Style>

            <Style x:Key="headerStyle" TargetType="{x:Type TextBlock}">
                <Setter Property="Control.FontFamily" Value="Papyrus" />
                <Setter Property="Control.FontSize" Value="12" />
            </Style>
        </TabControl.Resources>
        <TabItem>
            <TabItem.Header>
                <TextBlock Text="Header" Style="{StaticResource headerStyle}" />
            </TabItem.Header>
            <TextBlock Text="Here is the content" />
        </TabItem>
    </TabControl>

#1


1  

Like anything in WPF, there are many ways. Without knowing exactly what you are trying to do, here is one "for instance" (I wouldn't suggest using this combination of fonts:) )

就像WPF中的任何东西一样,有很多方法。在不知道自己想要做什么的情况下,这里有一个“例如”(我不建议使用这种字体组合:)

    <TabControl>
        <TabControl.Resources>
            <Style TargetType="{x:Type TextBlock}">
                <Setter Property="FontFamily" Value="Comic Sans MS" />
                <Setter Property="FontSize" Value="20" />
            </Style>

            <Style x:Key="headerStyle" TargetType="{x:Type TextBlock}">
                <Setter Property="Control.FontFamily" Value="Papyrus" />
                <Setter Property="Control.FontSize" Value="12" />
            </Style>
        </TabControl.Resources>
        <TabItem>
            <TabItem.Header>
                <TextBlock Text="Header" Style="{StaticResource headerStyle}" />
            </TabItem.Header>
            <TextBlock Text="Here is the content" />
        </TabItem>
    </TabControl>