Reputation: 13
I have been working on a clone of brick breaker to get better in C# but keep getting this error "Error 1 'WPFGame1.Gammer' does not contain a definition for 'Window_KeyDown' and no extension method 'Window_KeyDown' accepting a first argument of type 'WPFGame1.Gammer' could be found (are you missing a using directive or an assembly reference?)" It's a WPF and I have the it declared in the class There is a lot of useless CS that you don't need, but I just wanted everything to be there in case you needed something else. Here's the relevent XAML
<Window x:Class="WPFGame1.Gammer" Name="myWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
WindowStyle="None"
AllowsTransparency="True"
ResizeMode="CanMinimize"
Title="Brick Breaker" Height="650" Width="700"
KeyDown="Window_KeyDown" <!--error occurs here-->
WindowStartupLocation="CenterScreen"
>
And the CS
public class Gammer : Window, IComponentConnector{
private void Window_KeyDown(object sender, KeyEventArgs e)
{
if (Gammer.movingTimer.IsEnabled && e.Key == Key.Space)
{
Gammer.movingTimer.Stop();
Pause p = new Pause(this);
p.ShowDialog();
}
Key key = e.Key;
if (key <= Key.F)
{
switch (key)
{
case Key.Left:
{
double leftRed = Canvas.GetLeft(this.rectangleRed);
if (leftRed > 0.0)
{
Canvas.SetLeft(this.rectangleRed, leftRed - 20);
return;
}
break;
}
case Key.Up:
break;
case Key.Right:
double rightRed = Canvas.GetLeft(this.rectangleRed);
if (rightRed < 550.0)
{
Canvas.SetLeft(this.rectangleRed, rightRed + 20);
return;
}
break;
default:
if (key != Key.F)
{
return;
}
double rightBlue = Canvas.GetLeft(this.rectangleBlue);
if (rightBlue < 550.0)
{
Canvas.SetLeft(this.rectangleBlue, rightBlue + 20);
}
break;
}
}
else if(key != Key.F)
{
if(key == Key.F1)
{
Help h = new Help();
h.Show();
return;
}
if(key != Key.F5)
{
return;
}
Touch.FrameReported += new TouchFrameEventHandler(this.Touch_FrameReportedRed);
Gammer.movingTimer.Start();
this.currentGameState = 1;
this.setInitialState();
this.clearCanvas();
this.brickGenerator(this.currentGameState);
return;
}else
{
double leftBlue = Canvas.GetLeft(this.rectangleBlue);
if(leftBlue > 0.0)
{
Canvas.SetLeft(this.rectangleBlue, leftBlue - 20.0);
return;
}
}
}}
Upvotes: 0
Views: 115
Reputation: 89
public class Gammer : Window, IComponentConnector{
Try switching that to this
public partial class Gammer : Window, IComponentConnector{
Upvotes: 2