复选框检查使用触发器

时间:2015-06-25 19:20:57

标签: wpf xaml mvvm

我有两个复选框chkone,chktwo。当我试图检查第一个复选框(chkone)我禁用第二个复选框并且缺陷是真的,但当我被执行禁用正常工作但缺乏不工作?

       <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>

1 个答案:

答案 0 :(得分:3)

尝试以下代码,如果您仍然面临问题,请告诉我,

<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>