DataTrigger to make WPF Button inactive until TextBox has value

Posted by JohnB on Stack Overflow See other posts from Stack Overflow or by JohnB
Published on 2011-01-11T20:35:41Z Indexed on 2011/01/11 20:53 UTC
Read the original article Hit count: 877

Filed under:
|
|

I want the Button control's property to be IsEnabled="False" until a value is entered into a TextBox in the Window.

Code so far:

<Button
  Content="Click Me"
  Name="ClickMe"
  VerticalAlignment="Top"
  Click="ClickMe_Click">
  <Button.Style>
    <Style>
      <Style.Triggers>
        <DataTrigger
          Binding="{Binding ElementName=textBox, Path=Length}"
          <!-- or even: Binding="{Binding Path=textBox.Length}" -->
          Value="0">
          <Setter
            Property="Button.IsEnabled"
            Value="false" />
          </DataTrigger>
      </Style.Triggers>
    </Style>
  </Button.Style>
</Button>

Also, is it possible to have this Button control's IsEnabled property be based on 3 different TextBox controls all having values?

© Stack Overflow or respective owner

Related posts about wpf

Related posts about wpf-binding