locked
Cant change Foreground Color RRS feed

  • Question

  • Hello,

    i build a

    <Style TargetType="{x:Type TextBlock}">
        <Setter Property="Foreground" Value="Red"></Setter>
    </Style>

    Style. No i cant change the Foreground of the Contextmenu or of the Tooltip. I tried also in <ContextMenu TextBlock.Foreground="Red". Have anyone a idea how i can change the foreground?
    • Moved by Mathias Schiffer Wednesday, April 29, 2009 7:44 AM English Language Post (From:Windows Presentation Foundation (WPF))
    • Edited by mfelive.de Wednesday, April 29, 2009 3:47 PM xaml code formating
    Wednesday, April 29, 2009 7:23 AM

Answers

  • There's many ways to solve your problem. 
    1. define your style in a context so that it only affects the controls you are trying to affect (i.e. not globally).
    2. Give your style a key and reference it when you want to use it.
    3. derive a new version of the control and set the values specifically for that control in code.
    4. restyle ContextMenu (not a good idea)
    5. set the background explicitly on each instance of TextBlock that you want to have it
    6. probably lots more...

    1,2 are the best choices.
    WNC
    • Marked as answer by Hua Chen Tuesday, May 5, 2009 8:52 AM
    Wednesday, April 29, 2009 10:40 PM

All replies

  • Hi,

    Can you please provide more details about what exactly you want to achieve.


    Thanks

    ParvezAnsari
    Wednesday, April 29, 2009 9:31 AM
  • Hello,

    i override the default Style of the TextBlock. Now all Textblocks got the Foreground color Red. I think that the Contextmenu uses in the Header also a TextBlock. Thats the reason, so i think, why i cant change the foreground.

    Have anyone a idea, how i can avoid, that the contextmenu uses the default TextBlock Style?
    Wednesday, April 29, 2009 3:55 PM
  • There's many ways to solve your problem. 
    1. define your style in a context so that it only affects the controls you are trying to affect (i.e. not globally).
    2. Give your style a key and reference it when you want to use it.
    3. derive a new version of the control and set the values specifically for that control in code.
    4. restyle ContextMenu (not a good idea)
    5. set the background explicitly on each instance of TextBlock that you want to have it
    6. probably lots more...

    1,2 are the best choices.
    WNC
    • Marked as answer by Hua Chen Tuesday, May 5, 2009 8:52 AM
    Wednesday, April 29, 2009 10:40 PM