1

I am using the following code to implement three state checkbox using MVVM:

<CheckBox IsChecked="{Binding
              Path=IsValueChecked, 
              Mode=TwoWay, 
              UpdateSourceTrigger=Explicit}"
          Margin="3,10,0,0"
          IsThreeState="True">
  <i:Interaction.Triggers>
    <i:EventTrigger EventName="Checked">
      <i:InvokeCommandAction Command="{Binding Path=CheckCommand, 
                      RelativeSource={RelativeSource AncestorType={x:Type DataGrid}}}"/>
    </i:EventTrigger>

    <i:EventTrigger EventName="Unchecked">
      <i:InvokeCommandAction Command="{Binding Path=CheckCommand, 
                      RelativeSource={RelativeSource AncestorType={x:Type DataGrid}}}"/>
    </i:EventTrigger>
  </i:Interaction.Triggers>
</CheckBox>

And in viewmodel, a notifiable property "IsValueChecked" of type Nullable<bool> is created. The problem is that the event "Checked" and "Unchecked" are not triggered on clicking of checkbox. What am i missing, Please suggest.

shilovk
  • 11,718
  • 17
  • 75
  • 74
Ena Jain
  • 103
  • 1
  • 12

1 Answers1

0

Expanding on Funk's comment above, it looks like you're trying to bind to the DataContext present at the level of the DataGrid but your binding is actually going to try binding to a property of the DataGrid itself. Given the DataGrid doesn't have a CheckCommand property, this will fail.

Try changing the binding path to:

{Binding Path=DataContext.CheckCommand, RelativeSource={RelativeSource AncestorType={x:Type DataGrid}}}

ibebbs
  • 1,963
  • 2
  • 13
  • 20