gpt4 book ai didi

WPF 全局样式不能被覆盖

转载 作者:行者123 更新时间:2023-12-04 15:36:21 25 4
gpt4 key购买 nike

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

<Style TargetType="TextBlock">
<Setter Property="FontFamily" Value="Times New Roman"/>
<Setter Property="FontSize" Value="20"/>
</Style>

在一个窗口中,我试图像这样在本地覆盖它:
<Style TargetType="TextBlock" BasedOn="{StaticResource {x:Type TextBlock}}">
<Setter Property="FontSize" Value="60" />
</Style>

和这个:
<Style TargetType="TextBlock">
<Setter Property="FontSize" Value="60" />
</Style>

但没有任何效果。我仍然坚持在 App.xaml 中设置的样式。有谁知道什么会干扰这个?如果我从 App.xaml 中删除该全局变量,则可以在本地设置我想要的任何内容。如果我更改全局中的一个值,它会在全局中反射(reflect)出来,所以我认为在任何地方都不存在与它冲突的另一个全局。我搜索了 TargetType="TextBlock"却一无所获。

有任何想法吗?

最佳答案

试过你的代码,它对我来说很完美。你的 window 风格放在哪里?
我将它复制到 Window.Resources 中,它显示字体大小为 60。
如果这不起作用,请在新的空项目中尝试您的代码。

  <Window.Resources>
<Style TargetType="TextBlock" BasedOn="{StaticResource {x:Type TextBlock}}">
<Setter Property="FontSize" Value="60" />
</Style>
</Window.Resources>

关于WPF 全局样式不能被覆盖,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8476857/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com