Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable button in WPF?

I have a Button and a TextBox in my WPF app. How can I make the Button not enabled until the user enters some text in the TextBox?

like image 908
sanjeev40084 Avatar asked May 25 '10 16:05

sanjeev40084


1 Answers

This should do it:

<StackPanel>     <TextBox x:Name="TheTextBox" />     <Button Content="Click Me">         <Button.Style>             <Style TargetType="Button">                 <Setter Property="IsEnabled" Value="True" />                 <Style.Triggers>                     <DataTrigger Binding="{Binding Text, ElementName=TheTextBox}" Value="">                         <Setter Property="IsEnabled" Value="False" />                     </DataTrigger>                 </Style.Triggers>             </Style>         </Button.Style>     </Button> </StackPanel> 
like image 131
Steve Greatrex Avatar answered Sep 19 '22 01:09

Steve Greatrex