DataGrid and Double Click

Topics: Prism v2 - Silverlight 2
May 7, 2009 at 1:28 PM
How would you implement a double click event on a datagrid row using  and MVVM?
May 7, 2009 at 4:57 PM
Double click isn't implemented natively either on Silverlight 2 nor 3 beta.

Check this out

F
May 7, 2009 at 6:59 PM
Thanks for your reply. 

    I do know that this is not implemented in Silverlight and I've read many articles on how to implenment using codebehind. I was wondering if there is a way to basically do the same thing following the MVVM patteren. Maybe using an attached behavior or commanding etc...
May 7, 2009 at 9:06 PM
Edited May 8, 2009 at 8:13 PM

 

Hi

 

In my personal opinion the best approach would be using a command with an attached behavior. As frantic0 said, there is no double click event is Silverlight, so you will have to “simulate” the double click event.

The following blog post explains how to create an attached behavior for a command in a Silverlight 3 DataForm, but it should help you create your behavior.

 

To simulate the double click you could write a similar code to the following behavior:

        public class DataGridMouseLeftButtonDownCommandBehavior : CommandBehaviorBase<DataGrid>

        {

       

                          private long lastClickTicks;

 

          public DataGridMouseLeftButtonDownCommandBehavior(DataGrid dataGrid)

            : base(dataGrid)

        {

            dataGrid.MouseLeftButtonDown += OnMouseLeftButtonDown;

        }

 

        private void OnMouseLeftButtonDown (object sender, MouseButtonEventArgs e)

        {                       

           if ((DateTime.Now.Ticks - this.lastClickTicks) < 5000000)

            {

                ExecuteCommand();

                this.lastClickTicks = 0;

            }

 

            this.lastClickTicks = DateTime.Now.Ticks; 

            }

        }

 

You can read more about command attached behaviors in these articles:

·         ICommand for Silverlight with Attached Behaviors

·         Commands

 

 Please let me know if this helps.

 

Damian Schenkelman

http://blogs.southworks.net/dschenkelman

May 8, 2009 at 7:41 PM

Thanks dschenkelman, Your links helped resolve my issue.