Вероятно, плохая идея определять явный стиль TextBlock
в App.xaml
, так как это повлияет на все TextBlock
элементы в вашем приложении.
В любом случае, вы все равно можете сделать так, чтобы кнопка заголовка выглядела как положено, если вы определяете пользовательский ControlTemplate
для TitleBarButton
, где вы заменяете ContentPresenter
на TextBlock
:
<Style x:Key="CustomStyle" TargetType="ui:TitleBarButton">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ui:TitleBarButton">
<Grid
x:Name="RootGrid"
Background="{TemplateBinding Background}"
SnapsToDevicePixels="True">
<TextBlock
x:Name="Content"
Text="{TemplateBinding Content}"
FontFamily="Segoe MDL2 Assets"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
Margin="{TemplateBinding Padding}" />
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsActive" Value="False">
<Setter Property="Background" TargetName="RootGrid" Value="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=InactiveBackground}" />
<Setter Property="TextElement.Foreground" TargetName="Content" Value="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=InactiveForeground}" />
</Trigger>
<Trigger Property="IsMouseOver" Value="true">
<Setter Property="Background" TargetName="RootGrid" Value="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=HoverBackground}" />
<Setter Property="TextElement.Foreground" TargetName="Content" Value="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=HoverForeground}" />
</Trigger>
<Trigger Property="IsPressed" Value="true">
<Setter Property="Background" TargetName="RootGrid" Value="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=PressedBackground}" />
<Setter Property="TextElement.Foreground" TargetName="Content" Value="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=PressedForeground}" />
</Trigger>
<Trigger Property="IsEnabled" Value="false">
<Setter Property="Background" TargetName="RootGrid" Value="{DynamicResource SystemControlDisabledTransparentBrush}" />
<Setter Property="TextElement.Foreground" TargetName="Content" Value="{DynamicResource SystemControlDisabledBaseMediumLowBrush}" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
Вам необходимо установить TitleBar.ButtonStyle
Прикрепленное свойство всех ваших windows к вашему пользовательскому стилю, как вы устанавливаете WindowHelper.UseModernWindowStyle
:
<Window ... ui:TitleBar.ButtonStyle="{StaticResource CustomStyle}" />