[英]No definition for class and cannot find the argument c#
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. 我一直在研究砖断路器的克隆,以在C#中获得更好的结果,但始终收到此错误“错误1'WPFGame1.Gammer'不包含'Window_KeyDown'的定义,并且没有扩展方法'Window_KeyDown'接受类型的第一个参数可以找到“ WPFGame1.Gammer”(您是否缺少using指令或程序集引用?)”这是一个WPF,我在类中声明了它。您不需要很多无用的CS,但是我只是希望一切都在那里,以防您需要其他东西。 Here's the relevent XAML
这是相关的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 和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;
}
}
}}
public class Gammer : Window, IComponentConnector{
尝试将其切换为此
public partial class Gammer : Window, IComponentConnector{
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.