XAML 如何在Mahapps.MetroWindow中更改窗口标题的字体粗细

vc6uscn9  于 2022-12-31  发布在  其他
关注(0)|答案(2)|浏览(211)

我不能在MetroWindow标题中更改字体粗细。我该怎么做呢?我可以在MetroWindow属性中设置字体粗细,但是它会影响我的XAML代码中的所有控件...

px9o7tmv

px9o7tmv1#

您可以设置MetroWindowTitleTemplate属性。

<Controls:MetroWindow.TitleTemplate>
    <DataTemplate>
        <TextBlock Text="{TemplateBinding Content}"
                   TextTrimming="CharacterEllipsis"
                   VerticalAlignment="Center"
                   Margin="8 -1 8 0"
                   FontWeight="Light"
                   FontSize="{DynamicResource WindowTitleFontSize}"
                   FontFamily="{DynamicResource HeaderFontFamily}" />
    </DataTemplate>
</Controls:MetroWindow.TitleTemplate>

或用大写字母表示标题:

<Controls:MetroWindow.TitleTemplate>
    <DataTemplate>
        <TextBlock Text="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Content, Converter={Converters:ToUpperConverter}}"
                   TextTrimming="CharacterEllipsis"
                   VerticalAlignment="Center"
                   Margin="8 -1 8 0"
                   FontWeight="Light"
                   FontSize="{DynamicResource WindowTitleFontSize}"
                   FontFamily="{DynamicResource HeaderFontFamily}" />
    </DataTemplate>
</Controls:MetroWindow.TitleTemplate>
bq9c1y66

bq9c1y662#

为了更新@punker76的答案,在2.x版中,资源被重命名,因此示例如下

<mah:MetroWindow.TitleTemplate>
   <DataTemplate>
      <TextBlock Text="{TemplateBinding Content}"
                 TextTrimming="CharacterEllipsis"
                 VerticalAlignment="Center"
                 Margin="8 -1 8 0"
                 FontWeight="Normal"
                 FontSize="{DynamicResource MahApps.Font.Size.Window.Title}"
                 FontFamily="{DynamicResource MahApps.Fonts.Family.Window.Title}" />
   </DataTemplate>
</mah:MetroWindow.TitleTemplate>

相关问题