Click here to Skip to main content
11,496,146 members (584 online)
The site is currently in read-only mode for maintenance. Posting of new items will be available again shortly.
See more: MVVM DataGrid
Is there any simple way to handle the row double click event in a silverlight datagrid using the MVVM approach.

Thanks in advance.
Posted 24-Jun-11 8:35am
Thanks Valery.

Here's how I resolved it using code behind mouse up event:

Private _LastClick As DateTime = DateTime.MinValue
    Private _DoubleClickTime As Double = 1500
    Private _LastDataGridRow As MyModel= Nothing
 

Private Sub DataGrid1_MouseLeftButtonUp(ByVal sender As Object, ByVal e As System.Windows.Input.MouseButtonEventArgs) Handles DataGrid1.MouseLeftButtonUp
        Dim viewModel As MyViewModel = CType(Me.DataContext, MyViewModel )
        Dim clickTime As DateTime = DateTime.Now
        Dim currentRowClicked As MyModel
        If viewModel.CanRetrieveQuote Then
          currentRowClicked = CType(CType(sender, DataGrid).SelectedItem, MyModel)
          Dim isDoubleClick As Boolean = (currentRowClicked.Equals(_LastDataGridRow)) And clickTime.Subtract(_LastClick) <= TimeSpan.FromMilliseconds(_DoubleClickTime)
            If isDoubleClick Then
                viewModel.RetrieveQuote()
            End If
            _LastClick = clickTime
            _LastDataGridRow = currentRowClicked
        End If
 
    End Sub
 

Hope this might be helpful for anyone trying to resolve this issue.

Thanks!
  Permalink  
Comments
Tarun K.S at 27-Jun-11 8:47am
   
Great! 5+
DateTime lastClick = DateTime.Now;
private void dgv_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
    if ((DateTime.Now - lastClick).Ticks < 2500000)
    {
        //this.View();
        MessageBox.Show("Double click!");
    }
    lastClick = DateTime.Now;
}
  Permalink  
Comments
ronnotel at 11-Jul-12 17:15pm
   
simple and (compared to other solutions) elegant. Thanks!
XmaiquelX at 11-Jun-14 23:02pm
   
Thanks!!
Margareta Dwiyanti at 16-Sep-14 23:39pm
   
simple code that helps a lot! Thanks.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 10,401
1 OriginalGriff 8,910
2 Sascha Lefèvre 3,899
3 Maciej Los 3,422
4 Richard Deeming 2,600


Advertise | Privacy | Mobile
Web02 | 2.8.150520.1 | Last Updated 28 Nov 2011
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100