Welcome to the Xceed Community | Help
Community Search  
More Search Options

WPF KeyBinding for Enter key does not work (But does work on DevExpress grid)

Sort Posts: Previous Next
  •  05-30-2012, 6:10 PM Post no. 32189

    WPF KeyBinding for Enter key does not work (But does work on DevExpress grid)

    So, I convinced my team that Xceed has the better WPF Grid.  I talked them into moving over from Dev Express.  I got my boss to put it in the budget to purchase (we are planning to purchase in July (the start of our fiscal year)).

    Since it was all a done deal, I figured, lets start switching our DevExpress grid out for our shiny new Xceed grid (using the Demo).  It was all rainbows and butterflies until we got to the InputBindings.

    Our DevExpress grid is setup similar to this:

    <dxg:GridControl ItemsSource="{Binding MySource, Mode=TwoWay}">
        <dxg:GridControl.Columns>
            <dxg:GridColumn Header="Name" Width="100" DisplayMemberBinding="{Binding ItemObject}" />
        </dxg:GridControl.Columns>
        <dxg:GridControl.View>
            <dxg:TableView FocusedRow="{Binding MySelectedItem, Mode=TwoWay}" />                    
        </dxg:GridControl.View> 
        <dxg:GridControl.InputBindings>
            <KeyBinding Key="Enter" Command="{Binding SelectItemCommand}" />
        </dxg:GridControl.InputBindings>
    </dxg:GridControl>

    That all works fine with DevExpress's grid.  We then went and swapped out the DevExpress grid for the Xceed grid like this: (I removed extra properties)

    <xcdg:DataGridControl ItemsSource="{Binding MySource, Mode=TwoWay}" SelectedItem="{Binding MySelectedItem, Mode=TwoWay}">
        <xcdg:DataGridControl.Columns>
            <xcdg:Column FieldName="ItemObject" Title="Name" Width="100" IsMainColumn="True" />
        </xcdg:DataGridControl.Columns>
        <xcdg:DataGridControl.View>
            <xcdg:TableView >
                <xcdg:TableView.FixedHeaders>
                    <DataTemplate>
                        <xcdg:ColumnManagerRow AllowColumnReorder="False"/>
                    </DataTemplate>
                </xcdg:TableView.FixedHeaders>
            </xcdg:TableView>
        </xcdg:DataGridControl.View>
        <xcdg:DataGridControl.InputBindings>         <KeyBinding Key="Enter" Command="{Binding SelectItemCommand}" CommandTarget="{Binding ElementName=GridControl}"/>     </xcdg:DataGridControl.InputBindings> </xcdg:DataGridControl>
    The big difference here is that the Dev Express one works like we would expect 
    (pressing enter while in the grid causes the Select Item Command to fire). But the Xceed grid
    does not work. Pressing enter does nothing.... Why?
    I am really hoping that the Xceed grid is actually better than the Dev Express grid and there is 
    a nice easy way to get my enter key to fire my command. (So I don't look like I got us to change to a worse grid.)
    Can someone please let me know how to setup this KeyBinding?
    (NOTE: Other keyBindings work just fine, so it is not a syntax error or some such thing.) 
     
    Filed under:
  •  05-31-2012, 2:14 PM Post no. 32195 in reply to 32189

    Re: WPF KeyBinding for Enter key does not work (But does work on DevExpress grid)

    Hi Stephen,

    The Enter key is most likely being handled by the DataGrid and not making its way to your command.

    We do expose Preview events that allow you to capture the Up/Down of key or mouse presses.

    For example, in your scenario, you would want the PreviewKeyUp (or Down, depending which behavior you prefer):

       <xcdg:DataGridControl x:Name="myGrid" PreviewKeyUp="myGrid_PreviewKeyUp" ... >

       private void myGrid_PreviewKeyUp(object sender, System.Windows.Input.KeyEventArgs e)
       {
          if (e.Key == Key.Enter)
          {
             // your code here
          }
       }

     


    ** Quick Tip: Clients with an active support subscription should be sending their questions by email if they wish to benefit from the faster response time. Thanks!


    Diane Lafontaine
    Technical Support
    Xceed Software Inc.
  •  06-01-2012, 11:03 AM Post no. 32198 in reply to 32195

    Re: WPF KeyBinding for Enter key does not work (But does work on DevExpress grid)

    Yes that would work if I was doing WinForms style programming.

    One of the reasons we are switching (well now it is downgraded to thinking about switching) to Xceed is because it was supposed to have MVVM support.

    I was hoping to not have to use events for things that should be commands.  Or have to hack events into commands... (yes I know it can be done). I was looking (and thought I had found) a grid that can do MVVM out of the box.

    Filed under:
  •  06-01-2012, 1:24 PM Post no. 32201 in reply to 32198

    Re: WPF KeyBinding for Enter key does not work (But does work on DevExpress grid)

    Hi Stephen,

    I did not know that you were working in MVVM. I will look for another solution.



    ** Quick Tip: Clients with an active support subscription should be sending their questions by email if they wish to benefit from the faster response time. Thanks!


    Diane Lafontaine
    Technical Support
    Xceed Software Inc.
  •  06-05-2012, 10:46 AM Post no. 32212 in reply to 32201

    Re: WPF KeyBinding for Enter key does not work (But does work on DevExpress grid)

    Hi Stephen,

    While we do want to properly support MVVM, there are obviously still some situations that we did not think of.

    After verification with developers, we will open a new feature request to properly allow the Enter key press to bubble back up to the surface. Unfortunately, it is not something that would be done in the short term, as it might cause many behavior changes that we would have to make sure to properly handle.

    As a quick note, if your plan was to purchase the Blueprint Edition, that would give you access to the source code, and would therefore allow you to make any changes you want and compile a custom version of the DataGrid.



    We will post an update in this forum thread when the feature request is done and available for download. Thank you for your patience.

     


    ** Quick Tip: Clients with an active support subscription should be sending their questions by email if they wish to benefit from the faster response time. Thanks!


    Diane Lafontaine
    Technical Support
    Xceed Software Inc.
View as RSS news feed in XML
Contact | Site Map | Reviews | Legal Terms of Use | Trademarks | Privacy Statement Copyright 2011 Xceed Software Inc.