TextBlock - Prevent theme from changing Foreground brush RRS feed

  • General discussion

  • I have some TextBlock controls on a dark background and whenever the phone theme is changed to light the foreground color changes to dark. It does this despite the fact that I implicitly set the Foreground property to White.

    Is there a simple way of prevent the phone's selected theme from modifying the brushes of a control?

    Tuesday, January 18, 2011 5:02 AM

All replies

  • Check to make sure that the XAML actually has it set to white. When in the Visual Studio Designer, the properties will show "White" as the default value (and setting it to "White" in the properties will often (perhaps always) remove the Foreground tag from the TextBlock (or other control) rather than set it to white in the XAML. I don't know how Blend behaves, but it's possible it does the same (the idea being to prevent people from shooting themselves in the foot as far as themes go). So look closely at the XAML and make sure there's actually a


    property in the TextBlock. Chances are that it's not there and the properties window is just showing you "white" because that's the default, no-style-set-in-XAML value that they chose for Foreground.
    Tuesday, January 18, 2011 6:10 AM
  • Hi,

    Also worth having a look at retemplating the control in Blend if you're still having issues here.

    - rclick the control
    - edit template
    - edit a copy
    - change formating of consistuent components for specifics visual states as needed
    Tuesday, January 18, 2011 10:19 AM
  • If you had used Foreground="White" in a TextBlock, it should have stayed white regardless of the theme. Post your TextBlock xaml here.

    If you want, you can apply a fixed value (unaffected by theme) across the entire app by defining PhoneForegroundColor and PhoneForegroundBrush in App.xaml.

    Use this for white:
            <Color x:Key="PhoneForegroundColor">#FFFFFFFF</Color> 
            <SolidColorBrush x:Key="PhoneForegroundBrush" Color="{StaticResource PhoneForegroundColor}"/> 

    Wednesday, January 19, 2011 12:20 AM
  • Thanks for everyone's replies. I discovered the root of the problem - I was programatically setting the foreground color for these controls and using a system theme-enabled brush. Changing my code to use a static application resource fixed the issue.

    Monday, January 24, 2011 4:01 AM