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 6595085
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T17:53:39+00:00 2026-05-25T17:53:39+00:00

First, let me say I’ve been working with WPF for about a week. I

  • 0

First, let me say I’ve been working with WPF for about a week. I want to style a TextBox so that when it is disable, it is cleared. This article explained how to do it, however I’m confused on how to set the generic style as a resource so that every TextBox can bind to a different property without repeating the style for each TextBox.

<Window.Resources>
        <Style TargetType="{x:Type TextBox}" x:Key="style1">
            <Setter Property="Text" Value="{What do I really put here?}" /> 
            <Style.Triggers>
                <Trigger Property="IsEnabled" Value="False">
                    <Setter Property="Text" Value="{x:Null}" /> 
                </Trigger>
            </Style.Triggers>
        </Style> 
    </Window.Resources>

….

<TextBox Style="{StaticResource style1}" Text="{Binding SomeProperty}"/>

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-25T17:53:39+00:00Added an answer on May 25, 2026 at 5:53 pm

    You won’t be able to use the Text property like that. Setting the Text property explicitly on any TextBox that has that style will override the Text setter in the trigger (like you noticed).

    If you only need the TextBox to be cleared and not the property it is binding to, then a workaround is to use an attached property (or Tag) for the text which you bind Text to in the Style.
    Example..

    <Style TargetType="{x:Type TextBox}" x:Key="style1">
        <Setter Property="Text" Value="{Binding RelativeSource={RelativeSource Self},
                                                Path=Tag}"/>
        <Style.Triggers>
            <Trigger Property="IsEnabled" Value="False">
                <Setter Property="Text" Value="{x:Null}" />
            </Trigger>
        </Style.Triggers>
    </Style>
    

    Then a TextBox can use this Style like

    <TextBox Style="{StaticResource style1}" Tag="{Binding SomeProperty}" />
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First let me say that I've been searching to find a solution for a
First let me say that this is not about production settings for django -
first of all let me say that I know about dynamic, no PIA, named
First let me say that I really feel directionless on this question. I am
First let me say that I did see this article: How to remove AspxAutoDetectCookieSupport
Let's say I have 3 point clouds: first that has 3 points {x1,y1,z1}, {x2,y2,z2},
Let's say I have a form that collects a first name and a last
First, let me say that I'm a complete beginner at Python. I've never learned
First let me say that I know it's better to use the subprocess module,
First of all let me say thank you to everyone that offered answers...I have

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.