0

我有一个功能有一个记录按钮

    protected void StartRecord(object sender, RoutedEventArgs e)
    {
        MessageBox.Show("Start Recording");
        //string generatedName = Guid.NewGuid().ToString();
        string generatedName = @"c:\Desktop\Stream.recorded";
        //recordStreamPathAndName = @"C:" + generatedName + ".recorded";
        //this.recordStream = File.Create(recordStreamPathAndName);
        this.recordStream = File.Create(generatedName);
        this.Recorder = new KinectRecorder(KinectRecordOptions.Color | KinectRecordOptions.Skeletons, recordStream);
    }

此代码是否允许我创建记录按钮?如果确实如此,我如何创建它以显示在主窗口上并实际开始录制?在这里回答:这是 .xaml 代码

  <Button Click ="StartRecord" DataContext="{Binding}" Name="StartRecording" Width="50" Height="50" Canvas.Left="709" Canvas.Top="0" />

更新:创建按钮并创建文件。但是没有任何东西保存到文件中。

    void sensor_AllFramesReady(object sender, AllFramesReadyEventArgs e)
    {
          // some stuff

        using (SkeletonFrame skeletonFrame = e.OpenSkeletonFrame())
        {
          if (skeletonFrame == null)
          {
              return;
          }


           // Start recorder
            this.StartRecord(sender, e);  
         // parameter asks for (object, Routedeventargs)
         // but I have only (object, AllFramesReadyargs) declared in this function.


         // some stuff here

        }
   }
4

1 回答 1

1

您需要在 XAML 中创建按钮并将其连接到回调。就像是:

<Button Click="StartRecord">

在您的代码隐藏中,您的函数声明如下所示:

private void StartRecord(object sender, RoutedEventArgs e)
{
    // code here
}

告诉你的程序当按钮被点击时你想做什么。

于 2012-12-04T16:16:38.290 回答