Getting change event from checkbox in grid using WPF / MVVM?

I have a dataset, which is essentially a list of objects with a Boolean property in them associated with a DataGrid (specific DXGrid). I am trying to get the IsChecked property to fill when I click this checkbox. In the case of a standalone text field, I would use the UpdateSourceTrigger parameter for Binding, but at least in DXGrid it seems to be unavailable. Be that as it may, I have to lose the focus of the checkbox in order to update the property.

Any ideas?

Suppose the RaisePropertyChanged function below is an implementation of INotifyPropertyChanged.

Data object

public class MyObject
{
  bool _isChecked;
  string _name;
  int _id;

  public MyObject(OtherObject oo)
  {
       _name = oo.Name;
       _id = oo.ID;
  }

  public int ID
  { get { return _id; }}

  public string Name
  { get { return _name; }}

  public bool IsChecked
  {
      get { return _isChecked; }
      set
      {
          if (value == _isChecked)
              return;
          _isChecked = value;
          RaisePropertyChanged("IsChecked");
      }
  }
}    

ViewModel

class MyTestViewModel : BaseViewModel
{
    #region Fields
    #endregion

    public MyTestViewModel(Message message)
        : base(message)
    {
        AvailableObjects = PopulateDataSet();
    }

    #region Properties
    public List<MyObject> AvailableObjects { get; set; }
}

view xaml

  <dxg:GridControl x:Name="SearchGrid" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" MaxHeight="1024" AutoPopulateColumns="True" DataSource="{Binding Path=AvailableObjects}" >
      <dxg:GridControl.Columns>
          <dxg:GridColumn Header="Select" Width="60" FixedWidth="True" FieldName="IsChecked" ImmediateUpdateColumnFilter="True"></dxg:GridColumn>
          <dxg:GridColumn Header="ID Number" Width="130" FixedWidth="True" ReadOnly="True"  FieldName="ID"></dxg:GridColumn>
          <dxg:GridColumn Header="Name"  FieldName="Name" ReadOnly="True"></dxg:GridColumn>
      </dxg:GridControl.Columns>
      <dxg:GridControl.View>
          <dxg:TableView AllowEditing="True" x:Name="view" IndicatorWidth="0" AutoWidth="True"/>
      </dxg:GridControl.View>
  </dxg:GridControl>
+3
source share
2

:

                    <dxg:GridColumn>
                    <dxg:GridColumn.CellTemplate>
                        <DataTemplate>
                            <dxe:CheckEdit Checked="{Binding Path=IsChecked, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
                        </DataTemplate>
                    </dxg:GridColumn.CellTemplate>
                </dxg:GridColumn>
+1

(, DXCheckbox - ) WPF. IsChecked = {Binding Path = IsChecked, Mode = TwoWay, UpdateSourceTrigger = PropertyChanged}.

?

0

Source: https://habr.com/ru/post/1779274/


All Articles