1

I would like to enable a button when either of the 2 check boxes are checked. When neither of the check boxes are checked, the button should be inactive(IsEnabled = false)

It is possible to bind like this.

IsEnabled="{Binding ElementName=CheckBox Path=IsChecked}"

But it works only for a single checkbox. I want to bind both the check boxes IsChecked properties to the IsEnabled property of button in XAML itself. (I know how to do using property changed in code)

I tried using Multi triggers.

            <Button.IsEnabled>
                <MultiBinding>
                    <MultiBinding.Bindings>                                                  <Binding ElementName="BlankmeasurementCheckBox" Path="IsChecked"/>
                     <Binding ElementName="MeasurementCheckBox" Path="IsChecked"/>
                  </MultiBinding.Bindings>
             </MultiBinding>
          </Button.IsEnabled>

But it doesn't seem to help. Could you please help me out? Thanks in advance.

ViVi
  • 4,339
  • 8
  • 29
  • 52

1 Answers1

3

You can make use of MultiDataTrigger here.

Here is the sample code:

 <StackPanel HorizontalAlignment="Center" VerticalAlignment="Center">
        <CheckBox Name="cbSampleYes" Content="Yes" />
        <CheckBox Name="cbSampleSure" Content="I'm sure" />
        <Button HorizontalAlignment="Center" Margin="0,20,0,0">
            <Button.Style>
                <Style TargetType="Button">
                    <Setter Property="Content" Value="Verified" />                    
                    <Style.Triggers>
                        <MultiDataTrigger>
                            <MultiDataTrigger.Conditions>
                                <Condition Binding="{Binding ElementName=cbSampleYes, Path=IsChecked}" Value="False" />
                                <Condition Binding="{Binding ElementName=cbSampleSure, Path=IsChecked}" Value="False" />
                            </MultiDataTrigger.Conditions>
                            <Setter Property="Content" Value="Unverified" />
                            <Setter Property="IsEnabled" Value="False" />
                        </MultiDataTrigger>
                    </Style.Triggers>
                </Style>
            </Button.Style>
        </Button>
    </StackPanel>
Gopichandar
  • 2,742
  • 2
  • 24
  • 54
  • Thank you. The sample code works fine. But I am still facing issues with the style.. Before the style was defined in the button ie within the tag.. Now I changed it to inside the style(ie within the – ViVi Mar 08 '16 at 10:20
  • @VishakhBabu I hope this answers for your question. Pls create a separate question for others that are not related this thread. Also, feel free to accept the answer if it resolves your question. Thanks! – Gopichandar Mar 08 '16 at 10:25