//Handle MouseClick
public class EventTriggerExt : System.Windows.Interactivity.EventTrigger { protected override void OnEvent(EventArgs eventArgs) { if (this.AssociatedObject is SfDataGrid && eventArgs is MouseButtonEventArgs) { var args = eventArgs as MouseButtonEventArgs; var dataGrid = this.AssociatedObject as SfDataGrid; var point = args.GetPosition(dataGrid.GetVisualContainer()); var rowcolindex = dataGrid.GetVisualContainer().PointToCellRowColumnIndex(point, false);
if (rowcolindex.IsEmpty) return;
var lineinfo = dataGrid.GetVisualContainer().ScrollColumns.GetVisibleLines().GetVisibleLineAtPoint(point.X); if (point.X > lineinfo.ClippedCorner) return; } base.OnEvent(eventArgs); } }
//Handle Enter Key public class SpaceKeyDownEventTrigger : System.Windows.Interactivity.EventTrigger {
public SpaceKeyDownEventTrigger() : base("KeyUp") { }
protected override void OnEvent(EventArgs eventArgs) { var e = eventArgs as KeyEventArgs; if (e != null && e.Key == Key.Enter) base.OnEvent(eventArgs); } } |
<Syncfusion:SfDataGrid AllowEditing="True" Name="datagrid" AutoGenerateColumns="True" ItemsSource="{Binding Orders}" SelectedItem="{Binding Selectedvalue}"> <i:Interaction.Triggers> <local:EventTriggerExt EventName="MouseDoubleClick"> <i:InvokeCommandAction Command="{Binding DoubleClickCommand}"/> </local:EventTriggerExt> <local:SpaceKeyDownEventTrigger EventName="KeyUp"> <i:InvokeCommandAction Command="{Binding DoubleClickCommand}"/> </local:SpaceKeyDownEventTrigger> </i:Interaction.Triggers> |