Click here to Skip to main content
13,054,615 members (67,166 online)
Rate this:
Please Sign up or sign in to vote.
See more:
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 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 11-Jul-12 17:15pm
simple and (compared to other solutions) elegant. Thanks!
XmaiquelX 11-Jun-14 23:02pm
Margareta Dwiyanti 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
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.170713.1 | Last Updated 28 Nov 2011
Copyright © CodeProject, 1999-2017
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