0

I have a button on a form which I want to be disabled as long as my DomainDataSource's DataContext.IsLoading is true; I want to bind the IsEnabled property of the button to a ! condition on DomainContext.IsLoading and unfortunately I do not know how to handle it as a conditional expression. I can get it working in the reverse of my intended fashion, but not the way I want it to be.

My question is, how do I make this:

<Button IsEnabled="{Binding ElementName=someDomainDataSource, Path=DomainContext.IsLoading}" />

effectively be a ! condition along the lines of (this of course does not work) this:

<Button IsEnabled="{Binding ElementName=someDomainDataSource, Path=!DomainContext.IsLoading}" />
Keith Adler
  • 20,880
  • 28
  • 119
  • 189

1 Answers1

3

You could use a ValueConverter for this, something like an BooleanInverter which on conversion, inverts the value. See MSDN

Your binding would then be

 <Button IsEnabled="{Binding ElementName=someDomainDataSource, Path=DomainContext.IsLoading, Converter={StaticResource BooleanInverter}}" />
Adam Price
  • 10,027
  • 1
  • 20
  • 16