This is a migrated thread and some comments may be shown as answers.

DataGridTemplateColumn Event Behavior

1 Answer 52 Views
DataGrid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Perry
Top achievements
Rank 2
Perry asked on 03 Dec 2014, 11:01 AM
I want to have the Checked Event Binded to my RelayCommand in the ViewModel. I try to do this via an behavior but every possible implementation I try isn't working.
Do I miss something?

<grid:DataGridTemplateColumn.CellContentTemplate>
                                        <DataTemplate>
                                        <StackPanel>
                                            <CheckBox IsChecked="{Binding InCollection}">
                                                <interactivity:Interaction.Behaviors>
                                                    <core:EventTriggerBehavior EventName="Checked">
                                                        <core:InvokeCommandAction
                                                            Command="{Binding InCollectionCommand, Mode=OneWay}"
                                                            InputConverter="{StaticResource CheckBoxEventArgsConverter}"/>
                                                    </core:EventTriggerBehavior>
                                                </interactivity:Interaction.Behaviors>
                                            </CheckBox>
                                        </StackPanel>
                                    </DataTemplate>
                                </grid:DataGridTemplateColumn.CellContentTemplate>
                            </grid:DataGridTemplateColumn>

Thank you in advance.
Perry van der Meeren

1 Answer, 1 is accepted

Sort by
0
Rosy Topchiyska
Telerik team
answered on 08 Dec 2014, 10:06 AM
Hi Perry,

Thank you for contacting us.

The problem is that the context of the cell template is the item from the ItemsSource collection, not the ViewModel. You can either define the command in the data item, or you can define the ViewModel as a static resource in order to be able to bind to its properties in the cell template. I have attached a sample project that demonstrates the second scenario.

I hope this helps. Please, let us know if you have further questions.

Regards,
Rosy Topchiyska
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
DataGrid
Asked by
Perry
Top achievements
Rank 2
Answers by
Rosy Topchiyska
Telerik team
Share this question
or