tags:

views:

405

answers:

2

I know this works fine:

<TextBox IsEnabled="{Binding ElementName=myRadioButton, Path=IsChecked}" />

...but what I really want to do is negate the result of the binding expression similar to below (psuedocode). Is this possible?

<TextBox IsEnabled="!{Binding ElementName=myRadioButton, Path=IsChecked}" />
+2  A: 

Unfortunately, you cannot directly perform operators, such as negation, on the Binding expression... I would recommend using a ValueConverter to invert the boolean.

IanR
+6  A: 

You can do this using an IValueConverter:

public class NegatingConverter : IValueConverter
{
  public object Convert(object value, ...)
  {
    return !((bool)value);
  }
}

and use one of these as the Converter of your Binding.

itowlson
Unfortunately if your already using a value converter in your binding then you have to resort to some type of piping/chaining technique in order to negate the value returned by that value converter.
jpierson