"how to boolean && two visibility converters" Code Answer

4

you could use a multibinding together with a short, hand made imultivalueconverter.

example:

<stackpanel>
    <stackpanel.resources>
        <local:multibooleantovisibilityconverter x:key="converter" />
    </stackpanel.resources>
    <checkbox x:name="box1" />
    <checkbox x:name="box2" />
    <textblock text="hidden text">
        <textblock.visibility>
            <multibinding converter="{staticresource converter}">
                <binding elementname="box1"
                            path="ischecked" />
                <binding elementname="box2"
                            path="ischecked" />
            </multibinding>
        </textblock.visibility>
    </textblock>                   
</stackpanel>

... and the converter ...

class multibooleantovisibilityconverter : imultivalueconverter
{
    public object convert(object[] values,
                            type targettype,
                            object parameter,
                            system.globalization.cultureinfo culture)
    {
        bool visible = true;
        foreach (object value in values)
            if (value is bool)
                visible = visible && (bool)value;

        if (visible)
            return system.windows.visibility.visible;
        else
            return system.windows.visibility.hidden;
    }

    public object[] convertback(object value,
                                type[] targettypes,
                                object parameter,
                                system.globalization.cultureinfo culture)
    {
        throw new notimplementedexception();
    }
}
By Quantico on January 2 2022

Answers related to “how to boolean && two visibility converters”

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