没有类的定义,也找不到参数c#

时间:2016-05-13 15:36:14

标签: c# wpf xaml

我一直致力于克隆砖块,以便在C#中获得更好的效果,但不断出现此错误 “错误1'WPFGame1.Gammer'不包含'Window_KeyDown'的定义,并且没有可以找到接受类型'WPFGame1.Gammer'的第一个参数的扩展方法'Window_KeyDown'(你是否缺少using指令或汇编引用? )” 它是一个WPF,我在课堂上声明了它 有很多无用的CS你不需要,但我只是希望一切都在那里,以防你需要别的东西。 这是相关的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" 
    >

和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;

                }
            }
            }}

1 个答案:

答案 0 :(得分:2)

public class Gammer : Window, IComponentConnector{

尝试将其切换到此

public partial class Gammer : Window, IComponentConnector{