如何在Mahapps.MetroWindow中更改Window Title的FontWeigth

Tim*_*ioz 7 wpf xaml mahapps.metro

我不能在MetroWindow标题中更改字体重量.我怎样才能做到这一点?我可以在MetroWindow属性中设置FontWeihgt,但它会影响我的XAML代码中的所有控件...

pun*_*r76 11

你可以设置的TitleTemplate属性MetroWindow.

<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>
Run Code Online (Sandbox Code Playgroud)

或者标题为大写:

<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>
Run Code Online (Sandbox Code Playgroud)