Mark W
Mark W

Reputation: 3909

DataGrid CheckboxColumn bound to VM property not calling setter

ETA: I'm using Caliburn.Micro so the x:Name property for the Grid is being bound to a Property on the VM called MyData which in turn has the property IsTrue. MyData does inherit from PropertyChangeBase

I have a DataGrid with the a column bound to a bool property on the ViewModel:

<DataGrid x:Name="MyData"
                  AutoGenerateColumns="False"
                      Width="282"
                      RowHeaderWidth="0"
                      CanUserAddRows="false">
  <DataGrid.Columns>
     <DataGridCheckBoxColumn Header="MyChckColumn"
                     Binding="{Binding IsTrue, Mode=TwoWay}"
                     Width="80"/>
   </DataGrid.Columns>
</DataGrid>

it only goes into the setter when something else on the grid is selected, but not when I actually check a box that was empty.

  public bool IsTrue
  {
     get
     {
        return _isTrue;
     }
     set
     {
        if (value.Equals(_isTrue)) return;
        _isTrue= value;
        NotifyOfPropertyChange(() => IsTrue);
     }
  }

Is there some validation method I need to call, or a trigger that needs to be set?

Upvotes: 0

Views: 494

Answers (1)

Peter Hansen
Peter Hansen

Reputation: 8907

To get the behavior you are after, you would have to set the UpdateSourceTrigger property of the binding to PropertyChanged.

By default the binding source is updated when the cell looses focus.

Binding="{Binding IsTrue, UpdateSourceTrigger=PropertyChanged}"

Upvotes: 1

Related Questions