How about this one:
Create a converter for booleans:
class BooleanValueInverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (!(parameter is IValueConverter))
{
if (value is bool)
return !(bool)value;
else
return DependencyProperty.UnsetValue;
}
else
{
IValueConverter converter = (IValueConverter)parameter;
if (value is bool)
{
bool input = !(bool)value;
return converter.Convert(input, targetType, null, culture);
}
else
{
return DependencyProperty.UnsetValue;
}
}
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
in the xaml import the namespace where the inverter class is implemented:
xmlns:util="clr-namespace:MyApp.Utilities"
In the resource section add reference the inverter class:
<util:BooleanValueInverter x:Key="Inverter" />
And then just simply use it like this:
<TextBox Text="{Binding Path=TextProperty}" IsEnabled="{Binding SomeBoolPropertyToInvert, Converter={StaticResource Inverter}}"/>