0

There is a checkbox that is already binded to boolean field "IsOutsourcing"

<CheckBox x:Name="chkIsOutsourcing" IsChecked="{Binding IsOutsourcing, Mode=TwoWay}" />

And I need to check it when checked another checkbox.

<CheckBox x:Name="chkIsOption1" IsChecked="{Binding IsOption1, Mode=TwoWay}" />

How ot can be done with XAML?

Can we use here multiple elements to bind?

IsChecked="{Binding IsOutsourcing chkIsOption1, Mode=TwoWay}"

Thanks!

0

1 Answer 1

1

This can be done using MultiBinding with MultiValueConverter.

<CheckBox x:Name="chkIsOutsourcing">
    <CheckBox.IsChecked>
        <MultiBinding Converter="{StaticResource BooleanConverter}">
            <Binding Path="IsOutSourcing" />
            <Binding Path="IsChecked"
                        ElementName="chkIsOption1" />
        </MultiBinding>
    </CheckBox.IsChecked>
</CheckBox>

The Converter,

public class BooleanConverter : IMultiValueConverter
{
    public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        bool value1 = (bool)values[0];
        bool value2 = (bool)values[1];

        return value1 || value2;
    }

    public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
    {
        throw new NotImplementedException();
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.