Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XAML 'NOT' operator?

<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;
    }
}
like image 923
Shimmy Weitzhandler Avatar asked Aug 23 '09 02:08

Shimmy Weitzhandler


Video Answer


2 Answers

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.

like image 91
Scott Weinstein Avatar answered Nov 16 '22 00:11

Scott Weinstein


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.

like image 42
Noxxys Avatar answered Nov 16 '22 01:11

Noxxys