WPF全局样式无法覆盖

Yat*_*rix 6 wpf coding-style textblock

这个全局样式在App.xaml中声明:

<Style TargetType="TextBlock">
     <Setter Property="FontFamily" Value="Times New Roman"/>
     <Setter Property="FontSize" Value="20"/>
</Style>   
Run Code Online (Sandbox Code Playgroud)

在一个窗口中,我试图在本地覆盖这个:

<Style TargetType="TextBlock" BasedOn="{StaticResource {x:Type TextBlock}}">
     <Setter Property="FontSize" Value="60" />
</Style>
Run Code Online (Sandbox Code Playgroud)

还有这个:

<Style TargetType="TextBlock">
     <Setter Property="FontSize" Value="60" />
</Style>
Run Code Online (Sandbox Code Playgroud)

但没有任何作用.我仍然坚持使用App.xaml中设置的样式.有谁知道什么可能干扰这个?如果我从App.xaml中删除该全局,我可以在本地设置我想要的任何内容.如果我改变全局中的值,它会全局反映出来,所以我认为没有任何一个全球性的地方与之相冲突.我搜索TargetType="TextBlock"并没有得到任何东西.

有任何想法吗?

Sve*_*enG 3

尝试了你的代码,它非常适合我。您的窗口样式放置在哪里?我将其复制到 Window.Resources 中,它显示字体大小为 60 的字体。如果这不起作用,请在新的空项目中尝试您的代码。

  <Window.Resources>
    <Style TargetType="TextBlock" BasedOn="{StaticResource {x:Type TextBlock}}">
      <Setter Property="FontSize" Value="60" />
    </Style>
  </Window.Resources>
Run Code Online (Sandbox Code Playgroud)