DataGrid 没有双击事件所以要自己写。看了很多双击事件 都是用time 什么的。。 好不用意找到了个简单的。自己整理记录下。
xaml:
<data:DataGrid x:Name="MainDataGrid" LoadingRow="Grid_LoadingRow" UnloadingRow="Grid_UnloadingRow" IsReadOnly="True"> <data:DataGrid.Columns> <data:DataGridTextColumn Binding="{Binding TopicGuid, Mode=TwoWay}" Header="话题ID" Width="0.3*"/> <data:DataGridTextColumn Binding="{Binding TopicStartDate, Mode=TwoWay}" Header="起始时间" Width="0.5*"/> <data:DataGridTextColumn Binding="{Binding TopicEndDate, Mode=TwoWay}" Header="结束时间" Width="0.5*"/> <data:DataGridTextColumn Binding="{Binding TopicOrganizer, Mode=TwoWay}" Header="发起人" Width="0.5*"/> </data:DataGrid.Columns> </data:DataGrid>
cs:
private void Grid_LoadingRow(object sender, DataGridRowEventArgs e) { e.Row.MouseLeftButtonUp += Row_MouseLeftButtonUp; } private void Grid_UnloadingRow(object sender, DataGridRowEventArgs e) { e.Row.MouseLeftButtonUp -= Row_MouseLeftButtonUp; } private void Row_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) { TimeSpan t = DateTime.Now.TimeOfDay; if (this.MainDataGrid.Tag != null) { TimeSpan oldT = (TimeSpan)this.MainDataGrid.Tag; if (t != oldT && (t - oldT) < TimeSpan.FromMilliseconds(300)) { MessageBox.Show("双击事件"); } } this.MainDataGrid.Tag = t; }