"boolean to visibility converter - inverted?" Code Answer


as far as i know, you have to write your own implementation for this. here's what i use:

public class booleantovisibilityconverter : ivalueconverter
    public object convert(object value, type targettype, object parameter, cultureinfo culture)
        bool boolvalue = (bool)value;
        boolvalue = (parameter != null) ? !boolvalue : boolvalue;
        return boolvalue ? visibility.visible : visibility.collapsed;

    public object convertback(object value, type targettype, object parameter, cultureinfo culture)
        throw new notimplementedexception();

and i generally set converterparameter='negate' so it's clear in code what the parameter is doing. not specifying a converterparameter makes the converter behave like the built-in booleantovisibilityconverter. if you want your usage to work, you can, of course, parse the converterparameter using bool.tryparse() and react to it.

By mdexp on July 1 2022

Answers related to “boolean to visibility converter - inverted?”

Only authorized users can answer the Search term. Please sign in first, or register a free account.