Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4023578
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T10:36:56+00:00 2026-05-20T10:36:56+00:00

In my Silverlight 4 DataGrid control, I wanted to attach a very simple Behavior

  • 0

In my Silverlight 4 DataGrid control, I wanted to attach a very simple Behavior which executes a custom command on key Press – actually, commit the selected item in the DataGrid on ENTER key press.

While the Behavior actually works (see my code…

//.... in "OnAttached()..."
this.AssociatedObject.AddHandler(Control.KeyDownEvent, new KeyEventHandler(OnKeyDown), true);

private void OnKeyDown(object sender, KeyEventArgs e)
    {
        if (e.Key == Key.Enter)
        {
            InvokeCommand();
        }
    }

…) I have the problem, that the DataGrid seems to handle the ENTER key press itself and proceeds to the next row. Obviously, what happens is that the wrong Row is committed, because when I handle the Key Press, the row selectedion has already changed.

Here is the XAML:

<data:DataGrid
      AutoGenerateColumns="False"
      IsReadOnly="True"
      ItemsSource="{Binding Path=Data}"
      SelectedItem="{Binding SelectedRow, Mode=TwoWay}">
   <data:DataGrid.Columns>
      <data:DataGridTextColumn Binding="{Binding A}" />
      <data:DataGridTextColumn Binding="{Binding B}" />
      <data:DataGridTextColumn Binding="{Binding C}" />
   </data:DataGrid.Columns>
   <i:Interaction.Behaviors>
      <behaviors:EnterBehavior Command="{Binding CommitCommand}" />
   </i:Interaction.Behaviors>
</data:DataGrid>

Can you tell me how I can prevent the default ENTER event?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T10:36:57+00:00Added an answer on May 20, 2026 at 10:36 am

    Guess it’s a bit late now to help the OP, but I solved this by subclassing the data grid and overriding the KeyDown method to set e.Handled to true. That stops the default enter processing of the DataGrid, then your own actions can take effect.

    (Obviously you have to replace instances of DataGrid in the XAML with YourCustomDataGrid)

    public class YourCustomDataGrid : DataGrid
    {
        protected override void OnKeyDown(KeyEventArgs e)
        {
            // Stop "Enter" selecting the next row in the grid
            if (e.Key == Key.Enter)
            {
                e.Handled = true;
            }
            base.OnKeyDown(e);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When I first load data into a Silverlight DataGrid control, how can I make
I'm currently playing with the Silverlight(Beta 2) Datagrid control. Before I wired up the
Continuing my problem from yesterday, the Silverlight datagrid I have from this issue is
I have the following grid as the LayoutRoot control in my Silverlight page: <Grid.RowDefinitions>
I want to bind an 'ObservableCollection' to a Silverlight dataGrid and allow the contents
I am trying to affect the background pattern on a DataGrid in Silverlight 4.
Silverlight works on client side so putting any sensitive data like connection strings, passwords
Silverlight v2.0 is getting closer and closer to RTM but I have yet to
Silverlight has been available since quite some time, and Silverlight 2 allows .Net programming
Could Silverlight be used for the same things as jQuery, or are they intended

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.