且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

SilverLight Datagrid Row doubleclick事件

更新时间:2023-02-09 16:30:58



我在google上找到了:

http://www.dansoltesz.com/post/2010/02/19/Silverlight-datagrid-double-click-behavior.aspx [
Hi,

I found that on google:

http://www.dansoltesz.com/post/2010/02/19/Silverlight-datagrid-double-click-behavior.aspx[^]

Valery.


感谢瓦莱里.

这是我使用鼠标上移事件背后的代码解决的方法:

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!


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;
}