We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

SfDataGrid InputBindings

Thread ID:

Created:

Updated:

Platform:

Replies:

123777 Apr 20,2016 04:02 PM UTC Apr 21,2016 05:58 PM UTC WPF 1
loading
Tags: SfDataGrid
Artem
Asked On April 20, 2016 04:02 PM UTC

Hello.
I am using SfDataGrid in read-only mode.
This grid have context menu to run different commands from ViewModel at selected item (get info, edit, copy and more).
All is OK.
BUT to "Edit" command i have advanced view (another window).
For user expierence i want to add InputBindings ("Enter" and "Mouse Double click") for run "Edit" command.
Nothing works.
Can you help me?
Example:
...
<syncfusion:SfDataGrid.InputBindings>
    <KeyBinding Gesture="Enter" Command="{Binding DataGridMouseDoubleClickComm,Source={StaticResource MVViewModel}}" />
    <MouseBinding MouseAction="LeftDoubleClick" Command="{Binding DataGridMouseDoubleClickComm,Source={StaticResource  MVViewModel}}" />
 </syncfusion:SfDataGrid.InputBindings>
...
With standart MS DataGrid control this code works perfectly.
P.S. Sorry for my English.

Srinivasan Vasu [Syncfusion]
Replied On April 21, 2016 05:58 PM UTC

Hi Artem,
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>
    </Syncfusion:SfDataGrid>


Please find the sample from the below location.

Sample Location: http://www.syncfusion.com/downloads/support/forum/123777/ze/SfDataGrid2119996377

Regards,
Srinivasan
 

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;