初学者 Kinect 编程 - “'args' 在当前上下文中不存在”?

Beginner Kinect Programming - "'args' does not exsist in the current context"?

好的,所以我开始按照 Microsoft 的 how-to-kinect 系列编写一个应用程序,一切都很顺利,直到我写下这篇文章:

  using (InfraredFrame IRFrame = args.FrameReference.AcquiredFrame())
  {
  }

出于某种原因,它一直说 args 在当前上下文中不存在,我不知道为什么..这是我的完整代码:

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using Windows.UI.Xaml.Media.Imaging;
using WindowsPreview.Kinect;

// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238

namespace KinectApp1
{
    /// <summary>
    /// An empty page that can be used on its own or navigated to within a Frame.
    /// </summary>
    public sealed partial class MainPage : Page
    {
        public MainPage()
        {
            this.InitializeComponent();
            this.Loaded += MainPage_Loaded;
        }
        /*Getting the Kinect Sensor*/
        KinectSensor Sensor;

        /*Getting the Infared Reader*/
        InfraredFrameReader IRReader;

        /*This is IR Data Form*/
        ushort[] IRData;
    /*Converting the Data (Buffer) */
    byte[] IRDataConverted;

    /*Writing the Bitmap Image Described in XAML*/
    WriteableBitmap IRBitmap;

    void MainPage_Loaded(object sender, RoutedEventArgs e)
    {
        /*Get the sensor in the loaded frame*/
        Sensor = KinectSensor.GetDefault();

        /*Get the reader from the Source on the Sensor*/
        IRReader = Sensor.InfraredFrameSource.OpenReader();

        /*Frame Description for the Infrared and see how big they are*/
        FrameDescription FD = Sensor.InfraredFrameSource.FrameDescription;

        IRData = new ushort[FD.LengthInPixels];
        IRDataConverted = new byte[FD.LengthInPixels * 4];
        IRBitmap = new WriteableBitmap(FD.Width, FD.Height);
        Image.Source = IRBitmap;

        /*Start Sensor*/
        Sensor.Open();

        /*Subscribe to the event off the Reader*/
        IRReader.FrameArrived += IRReader_FrameArrived;

    }

    void IRReader_FrameArrived(InfraredFrameReader sender, InfraredFrameArrivedEventArgs e)
    {
        using (InfraredFrame IRFrame = args.FrameReference.AcquiredFrame())
        {
            if (IRFrame != null)
            {
                IRFrame.CopyFrameDataToArray(IRData);


                for (int i = 0; i < IRData.Length; i++)
                {
                    byte intensity = (byte)(IRData[i]>>8);
                    IRDataConverted[i*4] = intensity;
                    IRDataConverted[i*4 + 1] = intensity;
                    IRDataConverted[i*4 + 2] = intensity;
                    IRDataConverted[i*4 + 3] = 255;
                }

                IRDataConverted.CopyTo(IRBitmap.PixelBuffer);
                IRBitmap.Invalidate();

            }
        }
    }
}
}

谁能解释一下为什么会这样?我很困惑,

提前致谢。

P.S 这是我关注的视频: http://www.microsoft.com/en-us/kinectforwindows/develop/how-to-videos.aspx

嗯,已经回答了所以我不知道除了回答它还能做什么:

正如 Preston Guillot 在评论中所说:

"There is no variable named args in scope in the IRReader_FrameArrived method. You have a parameter of type InfraredFrameArrivedEventArgs named e that I'm guessing you meant to use"