Hide checkbox until mouseover and make it stay once checked WPF

311 views Asked by At

The checkbox is invisible until I mouse over which is what I want, but now I want it to stay visible once it is checked. I've tried implementing a multi trigger, but it doesn't seem to be working:

<DataGridTemplateColumn.CellTemplate>
   <DataTemplate>
      <CheckBox Name="cbkSelect" 
                IsChecked="{Binding Path=IsSelectedForOrder, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
         <CheckBox.Style>
            <Style TargetType="{x:Type CheckBox}">
               <Setter Property="Visibility" Value="Hidden"/>
               <Style.Triggers>
                  <MultiDataTrigger>
                     <MultiDataTrigger.Conditions>
                        <Condition Binding="{Binding IsMouseOver, RelativeSource={RelativeSource AncestorType={x:Type DataGridRow}}}" Value="True"></Condition>
                        <Condition Binding="{Binding IsChecked, RelativeSource={RelativeSource AncestorType={x:Type DataGridRow}}}" Value="True"></Condition>
                     </MultiDataTrigger.Conditions>
                     <MultiDataTrigger.Setters>
                        <Setter Property="Visibility" Value="Visible"/>
                     </MultiDataTrigger.Setters>
                  </MultiDataTrigger>
               </Style.Triggers>
            </Style>
         </CheckBox.Style>
      </CheckBox>
   </DataTemplate>
</DataGridTemplateColumn.CellTemplate>
1

There are 1 answers

3
thatguy On BEST ANSWER

A MultiDataTrigger will only apply the setter when all conditions are met.

Represents a trigger that applies property values or performs actions when the bound data meet a set of conditions.

Apart from that, binding to the DataGridRow does not work, as it has no IsChecked property. Instead, add a Trigger that acts on the IsChecked property of the associated CheckBox.

<Style TargetType="{x:Type CheckBox}">
   <Setter Property="Visibility" Value="Hidden"/>
   <Style.Triggers>
      <Trigger Property="IsChecked" Value="True">
         <Setter Property="Visibility" Value="Visible"/>
      </Trigger>
      <DataTrigger Binding="{Binding IsMouseOver, RelativeSource={RelativeSource AncestorType={x:Type DataGridRow}}}" Value="True">
         <Setter Property="Visibility" Value="Visible"/>
      </DataTrigger>
   </Style.Triggers>
</Style>