最好的重载方法匹配有一些无效的参数C#WPF LEAP

时间:2015-05-06 03:32:35

标签: c# wpf leap-motion

错误1'LeapController1.LeapEventListener.LeapEventListener(LeapController1.ILeapEventDelegate)'的最佳重载方法匹配有一些无效的参数

错误2参数1:无法从'LeapController1.MainWindow'转换为'LeapController1.ILeapEventDelegate'

我正在尝试将数据更新到GUI上的标签,我不知道出了什么问题。

这是我的代码:

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");
    }       
} 

}

1 个答案:

答案 0 :(得分:2)

使用此行,您尝试通过传入(function(){ angular.module('donateApp') .controller('MainCtrl', mainCtrl); mainCtrl.$inject = ['donateFactory', 'donateService', '$location']; function mainCtrl(donateFactory, donateService, $location){ var vm = this, checked = false; vm.submitted = false; vm.submitingForm = false; vm.amounts = [ 5, 10, 25, 50, 100 ]; vm.regions = donateService.getRegion(); vm.states = donateService.getStates(); 类的当前实例来创建新的'use strict'; describe('Controller: MainCtrl', function () { // load the controller's module beforeEach(module('donateApp')); var MainCtrl, scope; // Initialize the controller and a mock scope beforeEach(inject(function ($controller, $rootScope) { scope = $rootScope.$new(); MainCtrl = $controller('MainCtrl as ctrl', { $scope: scope }); $scope.ctrl = MainCtrl; })); it('Expect the form start with submitted as false', function () { expect(MainCtrl.ctrl.submitted).toBeTruthy(); }) });

LeapEventListener

MainWindow没有构造函数需要this.listener = new LeapEventListener(this); ,而且无法将LeapEventListener隐式转换为MainWindow

您需要创建一个实现接口MainWindow的类。该类需要实现方法ILeapEventDelegate的行为。

<小时/>

更新

Charles Ward在对此答案的评论中指出......

  

Leap Motion docs中有一个例子 - 注意到MainWindow类也实现了ILeapEventDelegate。

查看原始问题中的代码,您的ILeapEventDelegate已经实施了LeapEventNotification方法。您需要做的就是更改类声明以显式实现MainWindow接口。

LeapEventNotification