XamDatagrid UnboundField Checkbox绑定不起作用

时间:2015-12-07 00:20:47

标签: checkbox binding xamdatagrid

需要帮助。为什么下面的绑定不起作用。我希望每行数据都有复选框。选中/取消选中该复选框时,它应调用某个事件。

<Grid.Resources>
        <Style x:Key="CheckboxStyle" TargetType="{x:Type igDP:CellValuePresenter}">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type igDP:CellValuePresenter}">
                         <CheckBox Command="{Binding DataContext.IsCheckedBoolean, RelativeSource={RelativeSource AncestorType={x:Type igDP:XamDataGrid}}}" CommandParameter="{Binding}" />
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
</Grid.Resources>



<igDP:UnboundField Label="Action" Width="auto">
      <igDP:UnboundField.Settings>
            <igDP:FieldSettings CellValuePresenterStyle="{StaticResource CheckboxStyle}" />
       </igDP:UnboundField.Settings>
</igDP:UnboundField>

为了测试绑定,我使用viewmodel中返回的以下属性。默认值为false。

public Boolean IsCheckedBoolean
    {
        get { return _isChecked; }
        set
        {
            _isChecked = value;
            RaisePropertyChanged("IsCheckedBoolean");
        }
    }

我指的是WPF Binding : Add Button to Unbound Field in grid

1 个答案:

答案 0 :(得分:0)

如果您只想在command {@ 1}}上调用/取消选中CheckBox而不是:

event

<CheckBox HorizontalAlignment="Center" Command="{Binding RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type rControl:GridView}},Path=DataContext.ReviewRequiredCommand}" CommandParameter="{Binding RelativeSource={RelativeSource Self},Path=IsChecked}" BorderThickness="1,1,0,0" BorderBrush="Gray"/> CommandParameter检查状态作为CheckBox的参数发送。

如果您想根据代码绑定command

property

,但由于您使用的是 <CheckBox IsChecked="{Binding DataContext.IsCheckedBoolean, RelativeSource={RelativeSource AncestorType={x:Type igDP:XamDataGrid}}}" /> property,因此您无法找到cellValuePresenterStylecell获得的binding希望对你来说不是问题。):