I am trying to move an image which represents the players avatar using the arrow key in WPF. The code should allow the player to move the image using the arrow keys however this is not working. This is the code I have written to move the image.
private void Canvas_KeyDown(object sender, KeyEventArgs e)
{
if(e.Key == Key.Down)
{
Canvas.SetTop(player, Canvas.GetTop(player) -10);
}
else if (e.Key == Key.Up)
{
Canvas.SetTop(player, Canvas.GetTop(player) - 10);
}
else if (e.Key == Key.Left)
{
Canvas.SetLeft(player, Canvas.GetLeft(player) - 10);
}
else if (e.Key == Key.Right)
{
Canvas.SetLeft(player, Canvas.GetLeft(player) + 10);
}
}