I have two keys declared in my resources:

<x:Double x:Key="LargerSize">20</x:Double> <x:Double x:Key="BigSize">24</x:Double> 

which are used here:

 <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> 

When programmed in this way:

 App.Current.Resources["LargerSize"] = 16d; App.Current.Resources["BigSize"] = 18d; 

the application crashes with the exception System.Exception: "Разрушительный сбой (Exception from HRESULT: 0x8000FFFF (E_UNEXPECTED))"

    1 answer 1

    I solved the problem. Added FontSettings class with static fields:

     public class FontSettings { public static double TitleSize { get; } public static double CaptionSize { get; } static FontSettings() { FontSizeType fontSize = (FontSizeType)AppSettings.SelectedFontSize; switch (fontSize) { case FontSizeType.Small: TitleSize = 16d; CaptionSize = 18d; break; case FontSizeType.Medium: TitleSize = 18d; CaptionSize = 20d; break; case FontSizeType.Large: TitleSize = 20d; CaptionSize = 24d; break; } } } 

    Static fields are bound to styles in the Resource Dictionary:

     <local:FontSettings x:Key="FontSettings"/> <Style x:Key="baseTitleStyle" TargetType="TextBlock"> <Setter Property="FontFamily" Value="/Assets/Fonts/Poppins-Regular.ttf#Poppins"/> <Setter Property="FontSize" Value="{Binding Source={StaticResource FontSettings}, Path=TitleSize}" /> </Style> <Style x:Key="CaptionStyle" TargetType="TextBlock" BasedOn="{StaticResource baseTitleStyle}"> <Setter Property="FontWeight" Value="Bold"/> <Setter Property="FontSize" Value="{Binding Source={StaticResource FontSettings}, Path=CaptionSize}" /> </Style>