1

IN my below code i have 2 check boxes chkQAReviewMandatory and chkIsAnsMandatory. My requirement is when i check the chkQAReviewMandatory checkbox then automatically i need to checkbox chkIsAnsMandatory is checked and disabled, If chkQAReviewMandatory is not checked then uncheck the chkIsAnsMandatory and also enable it.

      <StackPanel Grid.Row="1" Grid.Column="1" Orientation="Horizontal" Margin="5,15,5,0">
                        <CheckBox x:Name="chkQAReviewMandatory" Content="QA Review Mandatory" Grid.Row="1" Grid.Column="0" Margin="0,5,0,0" 
                                  IsChecked="{Binding IsQAReviewMandatory}"/>
                        <StackPanel Orientation="Horizontal" Margin="20,0,0,0">
                        <StackPanel.Style>
                            <Style TargetType="StackPanel">
                            <Setter Property="Visibility" Value="Hidden"/>
                            <Style.Triggers>
                                    <DataTrigger Binding="{Binding ElementName=chkQAReviewMandatory, Path=IsChecked}" Value="True">
                                    <Setter Property="Visibility" Value="Visible"/>
                                </DataTrigger>
                            </Style.Triggers>
                        </Style>
                        </StackPanel.Style>
                                <Label x:Name="lblMax" Content="QA Max Point" Height="20" VerticalAlignment="Center" Margin="0,5,5,0"></Label>
                                <local:NumericTextBox Width="50"
                                                             MaxLength="1"
                                                             Height="25"
                                                             VerticalAlignment="Top"
                                                             Text="{Binding MaximumQAPoints}" />
                    </StackPanel>
                    </StackPanel>

                     <CheckBox Content="Is Answer Mandatory" 
                          Grid.Row="2" 
                          HorizontalAlignment="Left" 
                          Margin="5,12,0,0" 
                          IsChecked="{Binding IsAnswerMandatory}" >
                        <CheckBox.Style>
                            <Style TargetType="CheckBox">
                                <Style.Triggers>
                                    <DataTrigger Binding="{Binding ElementName=chkQAReviewMandatory,Path=IsChecked}" Value="True">
                                        <Setter Property="IsChecked" Value="True"/>
                                        <Setter Property="IsEnabled" Value="False"/>
                                        <Setter Property="Foreground" Value="White"/>
                                    </DataTrigger>
                                    <DataTrigger Binding="{Binding ElementName=chkQAReviewMandatory,Path=IsChecked}" Value="False">
                                        <Setter Property="IsChecked" Value="False"/>
                                        <Setter Property="IsEnabled" Value="True"/>
                                        <Setter Property="Foreground" Value="White"/>
                                    </DataTrigger>
                                </Style.Triggers>
                            </Style>
                        </CheckBox.Style>
                    </CheckBox>
3
  • do you have a question? Commented Jun 24, 2015 at 17:11
  • the above one is a question Commented Jun 24, 2015 at 17:38
  • 1
    my question is when i checked the checkbox "chkQAReviewMandatory" then i want to disable the checkbox "chkIsAnsMandatory" with checked option Commented Jun 24, 2015 at 17:39

1 Answer 1

2

There are two ways:

  1. For one control, bind the IsEnabled and IsChecked properties to properties in the ViewModel. On the other control, bind the IsEnabled to the IsChecked. This means that if one checkbox gets ticked, the other one becomes enabled.
  2. You can not only bind to properties in code, you can bind to properties on other controls. Set the name of the control using x:Name, then you can bind to any property on that control.

As for the details on how to do this, use my answer to find keywords to Google. Good luck!

Sign up to request clarification or add additional context in comments.

3 Comments

hi i want to do this by using triggers
hi i i edited my answer with the above changes by using data trigger everything is working fine but ischecked property is not working in the trigger...

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.