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

[Solved] How to create double click behavior and bind to GridView cell?

3 Answers 173 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Andrew Chan
Top achievements
Rank 1
Andrew Chan asked on 16 Sep 2010, 05:13 AM
Hi there,

In my project, I need to call a command in my viewmodel when the user click on those cells in the particular column of the GridView. I found GridViewCell supports CellDoubleClickEvent andI would like to use behavior to accomplish it since it's more testable. Could you provide me some ideas how to do it? How to attach the behavior to cell level?

Thanks.

Regards,
Andrew

3 Answers, 1 is accepted

Sort by
0
Milan
Telerik team
answered on 16 Sep 2010, 06:52 AM
Hi Andrew Chan,

You can subscribe to this double click event in the following

public Example()
       {
           this.InitializeComponent();
 
           this.RadGridView1.AddHandler(GridViewCellBase.CellDoubleClickEvent, new EventHandler<RadRoutedEventArgs>(OnCellDoubleClick), true);
       }
 
       private void OnCellDoubleClick(object sender, RadRoutedEventArgs args)
       {
           GridViewCellBase cell = args.OriginalSource as GridViewCellBase;
           if (cell != null)
           {
               this.ClickedCell = cell;
           }
       }
way:


Best wishes,
Milan
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Andrew Chan
Top achievements
Rank 1
answered on 16 Sep 2010, 07:31 AM
Hi Milan,

Thanks for your suggestion. However, I would like to achieve using behavior (InvokeCommandAction) and Command.

Can I do something similar as below?

            <i:Interaction.Triggers>
                <i:EventTrigger EventName="CellDoubleClickEvent">
                    <i:InvokeCommandAction Command="{Binding NewEntityCommand}"/>
                </i:EventTrigger>
            </i:Interaction.Triggers>

Regards,
Andrew
0
Maya
Telerik team
answered on 20 Sep 2010, 04:48 PM
Hi Andrew Chan,

In order to meet your requirements a couple of things need to be done. Firstly, a new class inheriting the EventTriggerBase is to be created and it has to expose a RoutedEvent Property. Furthermore, due to some limitations in the Framework, another class - GridViewEvents is to be added whose only functionality is to expose a CellDoubleClick Property of type RoutedEvent. Once created in the code-behind, you have to set them in the xaml file - just in the way you want it with the only difference that you are using the custom RoutedEventTrigger class instead of the EventTrigger one.
I am sending you a sample project illustrating the proposed solution.


Greetings,
Maya
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
GridView
Asked by
Andrew Chan
Top achievements
Rank 1
Answers by
Milan
Telerik team
Andrew Chan
Top achievements
Rank 1
Maya
Telerik team
Share this question
or