将命令绑定到 wpf 中 xamdatagrid 中的 onclick 复选框不起作用

Binding a command to a checkbox for onclick inside a xamdatagrid in wpf not working

我的 XamDataGrid 中有一个复选框,如下所示:-

<igDp:UnboundField Width="1*" Label="{LocText props:Resources.GROUPLIST_SYNC}" BindingMode="TwoWay"  BindingPath="IsSynchronise.Value" Converter="{StaticResource BoolToUMDirectoryFilter}" ConverterParameter="Enabled"  ToolTip="{LocText props:Resources.GROUPLIST_SYNC}">
    <igDp:UnboundField.Settings>
        <igDp:FieldSettings AllowEdit="True">
            <igDp:FieldSettings.LabelPresenterStyle >
                <Style  TargetType="igDp:LabelPresenter"  BasedOn="{StaticResource GmsLabelStyle }">
                    <Setter Property="AutomationProperties.AutomationId" Value="Group_SYNC"></Setter>
                </Style>
            </igDp:FieldSettings.LabelPresenterStyle>
            <igDp:FieldSettings.CellValuePresenterStyle>
                <Style TargetType="{x:Type igDp:CellValuePresenter}">
                    <Setter Property="Margin" Value="2"></Setter>
                    <Setter Property="Template">
                        <Setter.Value>
                            <ControlTemplate TargetType="igDp:CellValuePresenter">
                                <CheckBox Name="chkSynchronise"  IsChecked="{Binding Path=DataContext.DataItem.IsSynchronise.Value,  RelativeSource={ RelativeSource Mode=TemplatedParent}}"
                                              HorizontalAlignment="Center"  Command="{Binding SynchroniseGroups,RelativeSource={RelativeSource Mode=Self}}" HorizontalContentAlignment="Left" >

                                </CheckBox>
                                <!--<CheckBox IsChecked="{Binding Path=DataContext.DataItem.IsSynchronise.Value, Mode=TwoWay,UpdateSourceTrigger=PropertyChanged, RelativeSource={ RelativeSource Mode=TemplatedParent}}"  
                                                           Command="{Binding SynchroniseGroups,RelativeSource={RelativeSource Mode=Self}}"
                                                          HorizontalAlignment="Center" HorizontalContentAlignment="Left"  >

                                </CheckBox>-->
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                </Style>
            </igDp:FieldSettings.CellValuePresenterStyle>
        </igDp:FieldSettings>
    </igDp:UnboundField.Settings>
</igDp:UnboundField>

那么,我应该如何将命令绑定到复选框,以便通过单击来处理它,并在我的 ViewModel 中获得选中和未选中的行为?任何帮助将非常感激。提前致谢。

首先我想补充一点:自 infragistics 14.2 版以来,未绑定字段已过时 (look here).

为了将布尔值绑定到 XamDataGrid,我更喜欢使用 CheckBoxField

Class:

public class YourClass : NotificationObject
{
    private bool _checkBoxValue;

    public bool CheckboxValue
    {
        get
        {
            return this._checkBoxValue;
        }

        set
        {
            if (this._checkBoxValue != value)
            {
                this._checkBoxValue = value;

                // Do something: Event, Method, ...

                this.RaisePropertyChanged(nameof(this.CheckboxValue));
            }
        }
    }
}

XAML:

 <igDp:FieldLayout>
     <igDp:CheckBoxField BindingType="UseAlternateBinding"
                         Name="CheckerField"
                         Label="YourCheckerFieldLabel"
                         ToolTip="YourTooltip"
                         AlternateBinding="{Binding CheckboxValue, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                         />
 </igDp:FieldLayout>