How to boolean && two visibility converters

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();
    }
}

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)