1

I have two checkboxes chkone,chktwo. when i am trying to check the first checkbox(chkone) i am disabling the second checkbox and ischeckd is true, but when i was executed disabling working properly but ischecked in not working?

       <CheckBox x:Name="chkone"
                                      Content="QA Review Mandatory" Margin="22,12,289,275"
                                  IsChecked="{Binding Ischkone}"/>
            <CheckBox  x:Name="chktwo"
                                   Content="Question Mandatory" HorizontalAlignment="Left"
                                   Margin="22,85,0,201" IsChecked="{Binding Ischktwo}">
                <CheckBox.Style>
                    <Style TargetType="CheckBox">
                        <Style.Triggers>
                            <DataTrigger Binding="{Binding ElementName=chkone,Path=IsChecked}" Value="True">
                                <Setter Property="IsChecked" Value="True"/>
                                <Setter Property="IsEnabled" Value="False"/>
                            </DataTrigger>
                            <DataTrigger Binding="{Binding ElementName=chkone,Path=IsChecked}" Value="False">
                                <Setter Property="IsChecked" Value="False"/>
                                <Setter Property="IsEnabled" Value="True"/>
                            </DataTrigger>
                        </Style.Triggers>
                    </Style>
                </CheckBox.Style>
            </CheckBox>
2
  • looks like u r setting wrong ElementName.. It should be chkone.. right? Commented Jun 25, 2015 at 19:27
  • sorry, i edited the above question can u please look in to this.... Commented Jun 25, 2015 at 19:51

1 Answer 1

7

Try below code and let me know if you are still facing issue,

<CheckBox x:Name="chkone"
          Content="QA Review Mandatory" Margin="22,12,289,275"
          IsChecked="{Binding Ischkone}"/>

<CheckBox  x:Name="chktwo"
           Content="Question Mandatory" HorizontalAlignment="Left"
           Margin="22,85,0,201" >                
   <CheckBox.Style>
                    <Style TargetType="CheckBox">
                        <Style.Triggers>
                            <DataTrigger Binding="{Binding ElementName=chkone,Path=IsChecked}" Value="True">
                                <Setter Property="IsChecked" Value="True"/>
                                <Setter Property="IsEnabled" Value="False"/>
                            </DataTrigger>
                            <DataTrigger Binding="{Binding ElementName=chkone,Path=IsChecked}" Value="False">
                                <Setter Property="IsChecked" Value="False"/>
                                <Setter Property="IsEnabled" Value="True"/>
                            </DataTrigger>
                        </Style.Triggers>
                    </Style>
                </CheckBox.Style>
            </CheckBox>
Sign up to request clarification or add additional context in comments.

2 Comments

i am ok with that answer but my binding value of second check box value is removed why ?
is it not possible without removing that binding , because i am doing some operations on viewmodels by using that binding name

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.