我在资源中声明了两个键:
<x:Double x:Key="LargerSize">20</x:Double>
<x:Double x:Key="BigSize">24</x:Double>
在这里使用:
<Style x:Key="baseTitleStyle" TargetType="TextBlock">
<Setter Property="FontFamily" Value="/Assets/Fonts/Poppins-Regular.ttf#Poppins"/>
<Setter Property="FontSize" Value="{StaticResource LargerSize}" />
</Style>
<Style x:Key="CaptionStyle" TargetType="TextBlock" BasedOn="{StaticResource baseTitleStyle}">
<Setter Property="FontWeight" Value="Bold"/>
<Setter Property="FontSize" Value="{StaticResource BigSize}" />
</Style>
当以这种方式以编程方式更改时:
App.Current.Resources["LargerSize"] = 16d;
App.Current.Resources["BigSize"] = 18d;
应用程序因异常而崩溃System.Exception: "Разрушительный сбой (Exception from HRESULT: 0x8000FFFF (E_UNEXPECTED))"
解决了这个问题。添加了一个
FontSettings带有静态字段的类:与资源字典中的样式相关的静态字段: