SfDataGrid InputBindings
This grid have context menu to run different commands from ViewModel at selected item (get info, edit, copy and more).
Example:
...
<syncfusion:SfDataGrid.InputBindings>
<KeyBinding Gesture="Enter" Command="{Binding DataGridMouseDoubleClickComm,Source={StaticResource MVViewModel}}" />
We have analyzed your query, you can achieve your requirement by creating the custom event triggers instead of InputBindings. You have to create two different custom EventTriggers for MouseDoubleClick and KeyUp event in SfDataGrid. Please refer the below code example and attached sample for more details.
C#
|
//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); } } |
XAML
|
<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> |
Please find the sample from the below location.
Sample Location: http://www.syncfusion.com/downloads/support/forum/123777/ze/SfDataGrid2119996377
Regards,
Srinivasan
- 1 Reply
- 2 Participants
-
AR Artem
- Apr 20, 2016 04:02 PM UTC
- Apr 21, 2016 05:58 PM UTC