WPF TextBox trigger to clear Text

Posted by PaN1C_Showt1Me on Stack Overflow See other posts from Stack Overflow or by PaN1C_Showt1Me
Published on 2010-05-03T07:29:54Z Indexed on 2010/05/03 7:48 UTC
Read the original article Hit count: 668

Filed under:
|
|
|
|

Hi ! I have many TextBox controls and I'm trying to write a style that clears the Text property when the Control is disabled. I don't want to have Event Handlers in code behind.

I wrote this:

<Style TargetType="{x:Type TextBox}">                            
 <Style.Triggers>
  <Trigger Property="IsEnabled" Value="False">                                    
   <Setter Property="Text" Value="{x:Null}" />
  </Trigger>                                
 </Style.Triggers>
</Style>

The problem is that if the TextBox is defined like:

<TextBox Text={Binding Whatever} />

then the trigger does not work (probably because it's bound) How to overcome this problem?

© Stack Overflow or respective owner

Related posts about wpf

Related posts about textbox