Click here to Skip to main content
15,843,145 members
Please Sign up or sign in to vote.
5.00/5 (1 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

 
Share this answer
 
Thanks Valery.

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

VB
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!
 
Share this answer
 
Comments
Tarun.K.S 27-Jun-11 8:47am    
Great! 5+
C#
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;
}
 
Share this answer
 
Comments
ronnotel 11-Jul-12 17:15pm    
simple and (compared to other solutions) elegant. Thanks!
XmaiquelX 11-Jun-14 23:02pm    
Thanks!!
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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900