简体   繁体   中英

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM