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

RadGridView CellTemplate send arguments with relaycommand

3 Answers 179 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Prashant
Top achievements
Rank 1
Prashant asked on 21 Oct 2019, 07:31 AM

Hi All,

I am using RadGridView in WPF application with MVVM light. In celltemplate i am able to bind relay command for button but i am getting null argument on click event.

Sample Code:

<UserControl

                      ..

                       DataContext="{Binding SearchControlVM, Source={StaticResource Locator}}"

</UserControl>

..

 <telerik:RadGridView

  ..
                        <telerik:GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <telerik:RadButton Content="View" Command="{Binding Path=DataContext.ViewCommand,
                                                    RelativeSource={RelativeSource FindAncestor,AncestorType=telerik:RadGridView}}"  />
                                ..

 </telerik:RadGridView>

How to pass argument to MVVMlight relay command. Any help would be appreciated.

 

Thanks,

Prashant

 

 

3 Answers, 1 is accepted

Sort by
0
Accepted
Vladimir Stoyanov
Telerik team
answered on 23 Oct 2019, 04:24 PM

Hello Prashant,

Thank you for the provided code snippet. 

May I ask you to try setting the CommandParameter property of the RadButton? Please, give this a try and let me know how it goes. 

On a side note, you can also check out Telerik's EventToCommandBehavior, which allows for handling an event with a command from the viewmodel.

I hope you find this helpful. Let me know, if I can be of any further assistance.

Regards,
Vladimir Stoyanov
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Prashant
Top achievements
Rank 1
answered on 28 Oct 2019, 02:05 AM

Hi Vladimir,

Thanks for reply,

CommandParameter and EventToCommandBehavior  really helped me to understand behavior for command binding but unfortunately not working with MVVM light.

But i tried below code and that worked with my project architecture,

   <telerik:GridViewColumn.CellTemplate>
                                <DataTemplate>
                                    <telerik:RadButton Content=" View" >
                                        <i:Interaction.Triggers>
                                            <i:EventTrigger EventName="Click">
                                                <glevnt2cmd:EventToCommand Command="{Binding Path=DataContext.ViewAssetCommand,RelativeSource={RelativeSource FindAncestor,AncestorType=telerik:RadGridView}}" 
                                                                       PassEventArgsToCommand ="True"/>
                                            </i:EventTrigger>
                                        </i:Interaction.Triggers>
                                    </telerik:RadButton>
                                </DataTemplate>
                            </telerik:GridViewColumn.CellTemplate>

Really appreciate your help,

Prashant

 

 

 

0
Vladimir Stoyanov
Telerik team
answered on 30 Oct 2019, 12:57 PM

Hello Prashant,

I am glad to hear that you found my previous reply helpful and that you managed to achieve the desired result. 

Thank you for sharing your solution with the community.

Regards,
Vladimir Stoyanov
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
GridView
Asked by
Prashant
Top achievements
Rank 1
Answers by
Vladimir Stoyanov
Telerik team
Prashant
Top achievements
Rank 1
Share this question
or