1

Help needed. Why the below binding is not working. I want to have checkbox on each row of data. When the checkbox is checked/unchecked, it should invoke some event.

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

In order to test the binding, I use the below property returned in my viewmodel. The default value is false.

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

I'm referring to this WPF Binding : Add Button to Unbound Field in grid

Community
  • 1
  • 1
Donna
  • 7
  • 4

1 Answers1

0

If you just want to invoke some command on CheckBox check/uncheck event than:

<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 to send CheckBox check status as argument of command.

If you want to bind a property then as per you code:

 <CheckBox IsChecked="{Binding DataContext.IsCheckedBoolean, RelativeSource={RelativeSource AncestorType={x:Type igDP:XamDataGrid}}}" />

(but since you are using this one property to cellValuePresenterStyle. You won't be able to find out from which cell this binding is getting reflected. I Hope that's not a problem for you.):

Kylo Ren
  • 8,551
  • 6
  • 41
  • 66