Hej mam problem z obsługą klawiatury w c#. Problem jest w tym ,że po napisaniu kodu tego poniżej po kliknięciu W nic się nie dzieje. Przekopałem połowę internetu w poszukiwaniu rozwiązania ale nic z tego każdy kod nie działał. Wie ktoś może gdzie popełniłem błąd ? PS. Wiem ,że jest podobny temat lecz on w niczym mi nie pomógł :(
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace Gra
{
/// <summary>
/// Logika interakcji dla klasy MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void W_Press(object sender, KeyEventArgs e)
{
if(Keyboard.IsKeyDown(Key.W))
{
int a=100;
Thickness m = A.Margin;
m.Left = a= a+5;
A.Margin = m;
}
}
}
}
)
<Window x:Class="Gra.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:Gra"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525">
<Grid >
<Image HorizontalAlignment="Left" Height="320" VerticalAlignment="Top" Width="517" x:Name="A" />
</Grid>
</Window>