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 7747195
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T10:28:08+00:00 2026-06-01T10:28:08+00:00

private void Page_KeyDown(object sender, KeyEventArgs e) { if (e.Key == Key.Right) { if (shipPosition

  • 0
 private void Page_KeyDown(object sender, KeyEventArgs e)
        {
           if (e.Key == Key.Right)
            {
                if (shipPosition < right)
                {
                    x = x + 10;
                    shipPosition = shipPosition + 10;
                    ship.Margin = new Thickness(shipPosition, y, 0, 0);
                }
            }
         }

   XAML - KeyDown="Page_KeyDown"

I have a rectangle named ship, and above is the function to move it, to be executed on right or left arrow key button press. For some reason, this doesn’t work. The “KeyDown=”Page_KeyDown”” is the xaml that links the button press with the event. There is another grid containing buttons that moves every time a timer ticks, and when I click on a button and highlight it, then press the arrow keys, the ship starts to move, with the highlighted button being changed as well. Does anyone have any idea what is going on?

Update: I removed the is focusable property on the buttons, and that then stopped ship movement all together. So I think it is something to do with the changing of focus on buttons.

  • 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-06-01T10:28:10+00:00Added an answer on June 1, 2026 at 10:28 am

    Try this :

    Keyboard.AddKeyDownHandler(this, Page_KeyDown);
    

    Put it in the appropriate method of your control (constructor, initialized, …)

    public MainWindow()
    {
        InitializeComponent();
        Keyboard.AddKeyDownHandler(this, Page_KeyDown);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

. private void Form1_Load(object sender, EventArgs e) { List<CaclulatedData> tests = new List<CaclulatedData> {
private void Form1_FormClosing(object sender, FormClosingEventArgs e) { if (e.CloseReason == CloseReason.UserClosing) { if (MessageBox.Show(this,
I am trying to display random images heres my code private void Page_Load(object sender,
I am using C#. Below is my sample code. private void Page_Load(object sender, System.EventArgs
private void validateXML(DOMSource source) throws Exception { URL schemaFile = new URL(http://www.csc.liv.ac.uk/~valli/modules.xsd); SchemaFactory schemaFactory
private void BindCountry() { XmlDocument doc = new XmlDocument(); doc.Load(Server.MapPath(countries.xml)); foreach (XmlNode node in
JLAdjustmentList.aspx.cs protected void Page_Load(object sender, EventArgs e) { LoadApprovalList(); } protected override void OnPreRender(EventArgs
Please take a look at this: protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) { int
protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { loadCountries(); loadRegions(); loadCities(); }
I have this code in my codebehind... protected void Page_Init(object sender, EventArgs e) {

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.