Click here to Skip to main content
11,790,816 members (57,728 online)
Rate this: bad
Please Sign up or sign in to vote.
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 7:35am
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Rate this: bad
Please Sign up or sign in to vote.

Solution 2

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
            End If
            _LastClick = clickTime
            _LastDataGridRow = currentRowClicked
        End If
    End Sub

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

Tarun K.S at 27-Jun-11 8:47am
Great! 5+
Rate this: bad
Please Sign up or sign in to vote.

Solution 4

DateTime lastClick = DateTime.Now;
private void dgv_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
    if ((DateTime.Now - lastClick).Ticks < 2500000)
        MessageBox.Show("Double click!");
    lastClick = DateTime.Now;
ronnotel at 11-Jul-12 17:15pm
simple and (compared to other solutions) elegant. Thanks!
XmaiquelX at 11-Jun-14 23:02pm
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 OriginalGriff 385
1 ppolymorphe 339
2 Richard MacCutchan 118
3 Maciej Los 70
4 George Swan 70
0 OriginalGriff 1,154
1 Maciej Los 825
2 KrunalRohit 686
3 ppolymorphe 660
4 CPallini 621

Advertise | Privacy | Mobile
Web02 | 2.8.1509028.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