0

I am trying to bind command like below for a checkbox present in RadGridView's Column Header.

<telerik:GridViewCheckBoxColumn DataMemberBinding="{Binding IsSelected, Mode=TwoWay}" Width="85" AutoSelectOnEdit="True" EditTriggers="CellClick">                                                
  <telerik:GridViewCheckBoxColumn.Header>
     <CheckBox Command="{Binding ShowAllInDTCClickedCommand}" Content="Sh">
         <i:Interaction.Triggers>
              <i:EventTrigger EventName="Checked">                                                                
                  <i:InvokeCommandAction Command="{Binding ShowAllInDTCCheckedCommand}"/>
              </i:EventTrigger>
              <i:EventTrigger EventName="Unchecked">                                                                
                  <i:InvokeCommandAction Command="{Binding ShowAllInDTCUncheckedCommand}"/>
              </i:EventTrigger>
         </i:Interaction.Triggers>
      </CheckBox>
   </telerik:GridViewCheckBoxColumn.Header>
</telerik:GridViewCheckBoxColumn>

And trying to implement them in ViewModel like below.

    public DelegateCommand ShowAllInDTClickedCommand { get; set; }
    public DelegateCommand ShowAllInDTCCheckedCommand { get; set; }
    public DelegateCommand ShowAllInDTCUncheckedCommand { get; set; }


    ShowAllInDTClickedCommand = new DelegateCommand(ShowAllInDTClicked);
    ShowAllInDTCCheckedCommand = new DelegateCommand(ShowAllInDTCChecked);
    ShowAllInDTCUncheckedCommand = new DelegateCommand(ShowAllInDTCUnchecked);

    private void ShowAllInDTClicked()
    {
        //Do Something
    }

    private void ShowAllInDTCChecked()
    {
        //Do Something
    }

    private void ShowAllInDTCUnchecked()
    {
        //Do Something
    }                  

But these commands are not executing i.e. code is not reachable at all. What I am missing?

1 Answers1

1

If the DelegateCommand properties are defined in your view model, you should bind to them like this:

<i:EventTrigger EventName="Checked">
    <i:InvokeCommandAction Command="{Binding DataContext.ShowAllInDTCCheckedCommand, 
                                RelativeSource={RelativeSource AncestorType=telerik:RadGridView}}"/>
</i:EventTrigger>
mm8
  • 163,881
  • 10
  • 57
  • 88