Figuratively speaking, there is an image of a tank that can move in any direction with the help of the arrow buttons on the keyboard + the picture of the tank does not crawl over the edges (it stops at the edge), but at the same time I need the picture to turn not so that it turns out that I'm going upstairs sideways.
below the code as it goes and stops in front of the window (not perfect but in my version works as it should)
private void KeyDowdDo(object sender, KeyEventArgs e) { if (e.Key == Key.Left) if (image.Margin.Left > 10) image.Margin = new Thickness(image.Margin.Left - 15,image.Margin.Top, 0, 0); else image.Margin = new Thickness(image.Margin.Left, image.Margin.Top, 0, 0); if (e.Key == Key.Right) if (image.Margin.Left < 1330) image.Margin = new Thickness(image.Margin.Left + 15, image.Margin.Top, 0, 0); else image.Margin = new Thickness(image.Margin.Left, image.Margin.Top, 0, 0); if (e.Key == Key.Up) if (image.Margin.Top > 10) image.Margin = new Thickness(image.Margin.Left, image.Margin.Top - 15, 0, 0); else image.Margin = new Thickness(image.Margin.Left, image.Margin.Top, 0, 0); if (e.Key == Key.Down) if (image.Margin.Top < 760) image.Margin = new Thickness(image.Margin.Left, image.Margin.Top + 15, 0, 0); else image.Margin = new Thickness(image.Margin.Left, image.Margin.Top, 0, 0); }