<Button IsEnabled="{Binding (Not IsDisabled)}" />
Is there a way to do it with pure xaml, or I will have to do it via code? PS. I asked the question knowing that I can create a boolean converter like this:
<ValueConversion(GetType(Boolean), GetType(Boolean))>
Public Class BooleanFlagSwitchConverter : Implements IValueConverter
Public Function Convert(value As Object, targetType As Type,
parameter As Object, culture As CultureInfo) As Object
Implements IValueConverter.Convert
Return Not value
End Function
Public Function ConvertBack(value As Object, targetType As Type,
parameter As Object, ByVal culture As CultureInfo) As Object
Implements IValueConverter.ConvertBack
Return Not value
End Function
End Class
[ValueConversion(typeof(bool), typeof(bool))]
public class BooleanFlagSwitchConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter,
CultureInfo culture)
{
return !(bool)value;
}
public object ConvertBack(object value, Type targetType, object parameter,
CultureInfo culture)
{
return !(bool)value;
}
}
It doesn't exist. Look at the properties on the Binding class. There's nothing, other than a converter that will do what you want.
I would recommend using https://quickconverter.codeplex.com/
Inverting a boolean is then as simple as:
<Button IsEnabled="{qc:Binding '!$P', P={Binding IsDisabled)}" />
That speeds up the time normally needed to write converters.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With