Search code examples
c#silverlightexpression-blendcontroltemplate

Changing foreground color of a TextBox control


Maybe this question is kind of silly but I have no clue how to solve the following (maybe trivial) problem:

I just want to change the foreground color of a TextBox control in Silverlight 4 so that in "Normal" state it is, say, black and in "Disabled" state it should be red.

So far i did the following: I am editing the controls ControlTemplate to manipulate the visual states of the TextBox with the Visual State Manager in Blend 4 but because the text in the textBox is realized as its contentControl I can't find any foreground property to change the color or it to link to a particular visual state respectively.

Again, I simply want to set different foreground colors for different visual states of the TextBox.

Can anybody help me ? Thank you in advance !


Solution

  • You can do a couple things, You can delete the contentpresenter and replace it with a textblock, then with the TextBlock selected go to your Common Properties -> Text and click the little square next to it and choose Template Binding -> Content Which just adds a template binding for content to the control.

    Or a quick an easy way is just wrap it in a usercontrol and apply your changes to it instead like

    <UserControl>
    <ContentPresenter....
    </UserControl>
    

    Then just choose the user control object and voila you can set foreground etc.