Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 251211
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T21:34:32+00:00 2026-05-11T21:34:32+00:00

I have a global style that sets all my TextBox styles, but in some

  • 0

I have a global style that sets all my TextBox styles, but in some cases I want to revert just the Foreground color to the original non-custom-style color. I tried using {TemplateBinding Foreground} inside the specific TextBoxes that I wanted to revert. It didn’t end up being valid XAML and I’m not sure that’s the right way anyhow.

Any ideas? Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T21:34:32+00:00Added an answer on May 11, 2026 at 9:34 pm

    There’s a few ways this could be done. If you look at the Precedence List on the MSDN
    then you can see that the Forground set in ways 1-8 will override the Foreground from a default style. The easiest way being just to set the local value in the TextBox.

    <TextBox Foreground="Red" />
    

    Another thing that you can do is use the 'BasedOn' property of styles to override the other versions. This does require giving a key value to your default style, but that can then be used to also apply the default like in this example:

        <Style TargetType="{x:Type TextBox}"
               x:Key="myTextBoxStyle">
            <Setter Property="Foreground"
                    Value="Red" />
            <Setter Property="FontWeight"
                    Value="Bold" />
        </Style>
        <!-- Style applies to all TextBoxes -->
        <Style TargetType="{x:Type TextBox}"
               BasedOn="{StaticResource myTextBoxStyle}" />
    
    
    <TextBox Text="Hello">
        <TextBox.Style>
            <Style BasedOn="{StaticResource myTextBoxStyle}" TargetType="{x:Type TextBox}">
                <Setter Property="Foreground"
                        Value="Blue" />
            </Style>
        </TextBox.Style>
    </TextBox>
    

    Edit:
    In the case that the default style is applying a value and you want to revert it to the base value there are a few ways I can think of, off hand, to get this behavior. You can’t, that I know of, bind back to the default theme value in a generic manner.

    We can however do some other things. If we need the style to not apply some properties, we can set the style to {x:Null}, thus stopping the default style from applying. Or we can give the element it’s own style that does not inherit from the base style and then re-apply only the setters that we need:

            <TextBox Text="Hello" Style="{x:Null}" />
            <TextBox Text="Hello">
                <TextBox.Style>
                    <Style TargetType="{x:Type TextBox}">
                        <Setter Property="FontWeight"
                                Value="Bold" />
                    </Style>
                </TextBox.Style>
            </TextBox>
    

    We could modify the default style so that the Foreground will only be set on certain conditions, such as the Tag being a certain value.

        <Style TargetType="{x:Type TextBox}"
               x:Key="myTextBoxStyle">
            <Setter Property="FontWeight"
                    Value="Bold" />
            <Style.Triggers>
                <Trigger Property="Tag"
                         Value="ApplyForeground">
                    <Setter Property="Foreground"
                            Value="Red" />
                </Trigger>
            </Style.Triggers>
        </Style>
    
       <TextBox Text="Hello" />
        <TextBox Text="Hello" Tag="ApplyForeground" />
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to define a global style for all TextBlock and TextBox that exist
I am attempting to style some html that I do not have control over.
I have this jQuery and I'm changing styles in it but I've heard that
I declared a style that I want to apply to ALL the buttons in
If i have global variable in A.dll, that depends on global variable in B.dll
I have a global header and footer that has a Database connection and a
I have a global pointer variable char* pointer = new char[500]; /* some operations...
I have a global variable that is an instance of my custom class. How
I have a global app that prevents the mouse from moving into areas of
I have a global variables that I am using as a default variable. Depending

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.