最佳重载方法匹配有一些无效参数C#WPF LEAP
错误1与“LeapController1.LeapEventListener.LeapEventListener(LeapController1.ILeapEventDelegate)”匹配的最佳重载方法具有一些无效参数 错误2参数1:无法从“LeapController1.MainWindow”转换为“LeapController1.ILeapEventDelegate” 我正在尝试将数据更新到GUI上的标签,我不知道出了什么问题 这是我的代码:最佳重载方法匹配有一些无效参数C#WPF LEAP,c#,wpf,leap-motion,C#,Wpf,Leap Motion,错误1与“LeapController1.LeapEventListener.LeapEventListener(LeapController1.ILeapEventDelegate)”匹配的最佳重载方法具有一些无效参数 错误2参数1:无法从“LeapController1.MainWindow”转换为“LeapController1.ILeapEventDelegate” 我正在尝试将数据更新到GUI上的标签,我不知道出了什么问题 这是我的代码: using System; using Sys
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Leap; //using leap motion library
namespace LeapController1
{
public partial class MainWindow : Window
{
private Controller controller = new Controller();
private LeapEventListener listener;
public MainWindow()
{
InitializeComponent();
this.controller = new Controller();
this.listener = new LeapEventListener(this);
controller.AddListener(listener);
Console.ReadKey(); //prevent console output from closing
controller.RemoveListener(listener); //remove listener from controller
controller.Dispose(); //dispose controller
}
delegate void LeapEventDelegate(string EventName);
public void LeapEventNotification(string EventName)
{
if (this.CheckAccess())
{
switch (EventName)
{
case "onInit":
txtInit.Content = "Initialised";
break;
case "onConnect":
txtConnect.Content = "Connected";
this.connectHandler();
break;
case "onDisconnect":
txtConnect.Content = "Disconnected";
break;
case "onFrame":
txtFrame.Content = " on Frame";
this.movement(this.controller.Frame());
break;
}
}
else
{
Dispatcher.Invoke(new LeapEventDelegate(LeapEventNotification), new object[] { EventName });
}
}//end method LeapEventNotification
public void connectHandler()
{
this.controller.SetPolicyFlags(Controller.PolicyFlag.POLICY_IMAGES);
this.controller.SetPolicy(Controller.PolicyFlag.POLICY_BACKGROUND_FRAMES);
this.controller.EnableGesture(Gesture.GestureType.TYPE_KEY_TAP);
this.controller.EnableGesture(Gesture.GestureType.TYPE_SCREEN_TAP);
this.controller.EnableGesture(Gesture.GestureType.TYPE_SWIPE);
this.controller.EnableGesture(Gesture.GestureType.TYPE_CIRCLE);
this.controller.Config.SetFloat("Gesture.Swipe.MinLength", 100.0f);
}
public void movement(Leap.Frame frame)
{
HandList allHands = frame.Hands; //get hand data array
foreach (Hand hand in allHands) //run for each element in array
{
Leap.Vector normal = hand.PalmNormal; //get hand.PalmNormal data
Leap.Vector direction = hand.Direction; //get hand.Direction data
double pitch = direction.Pitch; //get pitch data
double pitch1 = (pitch) * (180 / Math.PI); //convert rad to deg
int finalpitch = (int)(pitch1); //nearest whole number
double roll = normal.Roll; //get roll data
double roll1 = (roll) * (180 / Math.PI); //convert rad to deg
int finalroll = (int)(roll1); //nearest whole number
txtPitch.Content = finalpitch; //assign data to label
txtRoll.Content = finalroll; //assign data to label
}
GestureList gestures = frame.Gestures(); //returns a list of gestures
for (int i = 0; i < gestures.Count(); i++) //run when gesture made
{
Gesture gesture = gestures[i]; //gesture at that instant
switch (gesture.Type) //check gesture type
{
//if gesture.Type == TYPE_SWIPE
case Gesture.GestureType.TYPE_SWIPE:
txtGesture.Content = "SWIPE";
break;
//if gesture.Type == TYPE_SCREEN_TAP
case Gesture.GestureType.TYPE_SCREEN_TAP:
txtGesture.Content = "SCREEN TAP";
break;
//if gesture.Type == TYPE_KEY_TAP
case Gesture.GestureType.TYPE_KEY_TAP:
txtGesture.Content = "KEY TAP";
break;
//if gesture.Type == neither of the above
default:
txtGesture.Content = "UNKNOWN";
break;
}
}
}
}
public interface ILeapEventDelegate
{
void LeapEventNotification(string EventName);
}
public class LeapEventListener : Listener
{
ILeapEventDelegate eventDelegate;
public LeapEventListener(ILeapEventDelegate delegateObject)
{
this.eventDelegate = delegateObject;
}
public override void OnInit(Controller controller)
{
this.eventDelegate.LeapEventNotification("onInit");
}
public override void OnConnect(Controller controller)
{
this.eventDelegate.LeapEventNotification("onConnect");
}
public override void OnDisconnect(Controller controller)
{
this.eventDelegate.LeapEventNotification("onDisconnect");
}
public override void OnFrame(Controller controller)
{
this.eventDelegate.LeapEventNotification("onFrame");
}
}
使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用系统文本;
使用System.Threading.Tasks;
使用System.Windows;
使用System.Windows.Controls;
使用System.Windows.Data;
使用System.Windows.Documents;
使用System.Windows.Input;
使用System.Windows.Media;
使用System.Windows.Media.Imaging;
使用System.Windows.Navigation;
使用System.Windows.Shapes;
使用Leap//使用leap运动库
命名空间控制器1
{
公共部分类主窗口:窗口
{
专用控制器=新控制器();
私人监听;
公共主窗口()
{
初始化组件();
this.controller=新控制器();
this.listener=新的LeapEventListener(this);
controller.AddListener(监听器);
Console.ReadKey();//防止关闭控制台输出
controller.RemovelListener(侦听器);//从控制器中删除侦听器
controller.Dispose();//Dispose控制器
}
委托无效LeapEventDelegate(字符串EventName);
公共void LeapEventNotification(字符串EventName)
{
if(this.CheckAccess())
{
开关(EventName)
{
案例“onInit”:
txtInit.Content=“初始化”;
打破
案例“onConnect”:
txtConnect.Content=“已连接”;
这个.connectHandler();
打破
案例“onDisconnect”:
txtConnect.Content=“断开”;
打破
案例“onFrame”:
txtFrame.Content=“在框架上”;
this.movement(this.controller.Frame());
打破
}
}
其他的
{
Invoke(新的LeapEventDelegate(LeapEventNotification),新对象[]{EventName});
}
}//结束方法LeapEventNotification
public-void-connectHandler()
{
this.controller.SetPolicyFlags(controller.PolicyFlag.POLICY_映像);
this.controller.SetPolicy(controller.PolicyFlag.POLICY_背景_帧);
this.controller.enableShipt(手势.GestureType.TYPE\u键\u点击);
this.controller.enableShipt(手势.GestureType.TYPE\u屏幕\u点击);
this.controller.enableShipt(手势.GestureType.TYPE\u滑动);
this.controller.enableSpirate(手势.GestureType.TYPE\u圆圈);
this.controller.Config.SetFloat(“signature.Swipe.MinLength”,100.0f);
}
公共空间移动(Leap.Frame)
{
HandList allHands=frame.Hands;//获取手数据数组
foreach(手牵手)//为数组中的每个元素运行
{
Leap.Vector normal=hand.PalmNormal;//获取hand.PalmNormal数据
Leap.Vector direction=hand.direction;//获取hand.direction数据
双节距=方向.节距;//获取节距数据
双螺距1=(螺距)*(180/Math.PI);//将rad转换为deg
int finalpitch=(int)(pitch1);//最近的整数
双滚动=正常。滚动;//获取滚动数据
双辊1=(辊)*(180/Math.PI);//将rad转换为deg
int finalroll=(int)(roll1);//最近的整数
txtPitch.Content=finalpitch;//将数据分配给标签
txtRoll.Content=finalroll;//将数据分配给标签
}
GestureList signities=frame.signities();//返回手势列表
对于(int i=0;i
}通过这一行,您正试图通过pa创建一个新的
LeapEventListener
this.listener = new LeapEventListener(this);
public partial class MainWindow : Window, ILeapEventDelegate
{
...