none
Default foreground, TextBlock RRS feed

  • Question

  • Should TextBlock's Foreground property not default to SystemColors.WindowTextBrush resource instead of Brushes.Black?
    It is very annoying to change TextBlocks afterwards, as it has to be done at each TextBlock.

    Applying a global style is not feasible, as it will change Foreground on every control. And the DependencyProperty doesn't appear to support bindings as default value.

    Any way to easily apply the correct Brush to the property?

    Best regards,
    Alexei Mihalchuk

    Wednesday, January 13, 2010 2:00 PM

Answers

  • If you add to Window.Resources the following:

        <Style TargetType="{x:Type TextBlock}">
          <Setter Property="Foreground" Value="{x:Static SystemColors.WindowTextBrush}" />
        </Style>
    
    all the TextBlock elements in your window will be updated. All the other controls will be unaffected.

    HTH
    --mc

    Thursday, January 14, 2010 2:46 AM

All replies

  • If you add to Window.Resources the following:

        <Style TargetType="{x:Type TextBlock}">
          <Setter Property="Foreground" Value="{x:Static SystemColors.WindowTextBrush}" />
        </Style>
    
    all the TextBlock elements in your window will be updated. All the other controls will be unaffected.

    HTH
    --mc

    Thursday, January 14, 2010 2:46 AM
  • It will work, but shouldn't it be set to WindowTextBrush by default?

    Furthermore, there is apparently a difference between setting a style in Application.Resources vs. Window.Resources. If your style is set at application level all TextBlocks, even those inside ContentPresenter (Buttons, ToolTips, ...), are changed. If you set it at Window level, only actual TextBlocks are affected. Weird behaviour.

    But thanks. Since you mentioned "Window", I learned the difference and going to apply my style at Window level.

    Best regards,
    Alexei Mihalchuk
    Thursday, January 14, 2010 9:59 AM