Inversing bool in XAML

I have seen a lot of these kinds of bindings in the Xamarin Forms community:

What I’m referring to is the IsNotPhotoVisible and IsPhotoVisible. It’s actually two different parameters in the view-model but the one is just a copy of the other but the inverse. Wouldn’t it be easier if there was a way to invert a property in the XAML-binding without having to create all these “NOT” properties? Well.. There is!

It’s called IValueConverter. I created this class named InverseConverter.cs:

Now we can simply call the converter from within the XAML like this:

Leave a Reply

Your email address will not be published. Required fields are marked *