0

I create the style in the xaml but in the code behind I recive a NULL value how exactly I supposed to do this code? Sorry for the question im new in this and I want to learn.

This is the xaml code:

 <Style x:Key="TextBoxProperties" x:Name="TextBoxProperties" TargetType="TextBlock">
        <Setter x:Name="textFontSize" Property="FontSize" Value="24"></Setter>
        <Setter x:Name="textTypography" Property="FontFamily" Value="Resources/Fonts/Bryant-BoldAlt_Italic__Santillana.ttf#Bryant"></Setter>
    </Style>  

This is the code behind:

 private void btnIncreaseFont_Click(object sender, RoutedEventArgs e)
    {
        if (currentFontSize < MAX_FONTSIZE)
        {
            if (btnDecreaseFont.IsEnabled == false)
                btnDecreaseFont.IsEnabled = true;
            currentFontSize += 2;
            TextBoxProperties.Setters.Add(textFontSize);
            TextBoxProperties.Setters.Add(textTypography);
            UpdateCurrentPage();
        }
        else
            btnIncreaseFont.IsEnabled = false;

    }
John
  • 173
  • 1
  • 1
  • 5

1 Answers1

2

If you want to change Global Font Size/Type at runtime, your best bet is set it at the parent container, e.g. Window, and child elements will inherit the value.

You can bind the global font size to a value in your DataContext(VM)

E.g. <Window FontSize="{Binding FontSize}" ...>

See: WPF - change global font size at runtime

Community
  • 1
  • 1
Michal Ciechan
  • 13,492
  • 11
  • 76
  • 118
  • I just want to change the style when I press the button(apply the condition of that style. – John Apr 02 '14 at 15:47