May 022013
 May 2, 2013  Posted by at 8:10 am C# & F#, Motion Tracking, Uncategorized  Add comments
Developing for leap Motion in C# Tutorial (video, slides and code)

Developing for leap Motion in C# Tutorial (video, slides and code)

I did a presentation on Leap Motion at the virtual conference DotnetConf last week, and I’ve spent the weekend cleaning up the code a little bit an putting together a simple video tutorial as it seems quite a few were interested and wanted some help to get started, and a step by step guide on how to develop for Leap Motion.

As soon as I find some time I will put together a detailed article on the Leap Motion- but I reckon you will get very far,- i not further with the video tutorial, the code, the conference session and the slides.

Here is everything you need – apart from the SDK and the device- to get started developing for Leap Motion in C#!

The slides

Slides on Leap Motion development can be found on my Slideshare account

Video tutorial with quick demo

I walk you through the what is it, how does it work (not as detailed as in the conference session), and then the code – step by step. The code is a WPF application using MVVM designpattern (not to 100%) and is a modified version of the application I made for the conference session. The Leap Motion application in C# and XAML can be found in my GitHhub repo Leap Motion (link provided below).

Developing for Leap Motion in C# Part 1
Developing for Leap Motion in C# Part 2

The conference session:

I demonstrate the Leap with several applications, get more into details of how it works, and I show both the code for three different console applications (that actually do the same thing LOL), and a WPF application.

The conference session on Leap Motion can be watched here. Slides used are the same as above, and can be found on Slideshare.

The code

The code for the application used for the tutorial can be found here, DLL’s for Leap Motion are not included as I’m not allowed to share those. Sign up, download the SDK and add the DLL’s as described in the tutorial or the slides.

Big thank you to Jeff Fritz for taking the time to discuss code with me, where would we be without great colleagues and friends 🙂 Also a big thanks to Carey, Scott and Michael 🙂 – you know you rock 😉

  27 Responses to “Developing for Leap Motion in C# Tutorial (video, slides and code)”

  1. Thanks for the excellent tutorials Iris, i have a question “when the MainWindow is not in focus, leap doesnt try to read the fingers, how can we change that to read always? “

    • Do you mean that you want a program that runs in the background as a service?

      • I think that Sandeep wants to say : if the mainwindow is open but an other windows of an other program has the focus.

        Very nice job

  2. Thanks for thème vidéo ! I Will receivethe leap Motion and of this week and used your code


  3. I just want to tell you THANK YOU for the tutorial. This is awesome. You are AWESOME.

  4. love it! I want to tray that with Sensoria Gaming/Fitness

  5. I downloaded the sample code provided by you for Leap Motion.I added the all api required to run application but it is showing error in below line:

    var screen = _controller.CalibratedScreens.ClosestScreenHit(fingers[0]);
    Error Details :
    ‘Leap controller could not contain a definition for ‘CalibratedScreens’ and no extension method ‘CalibratedScreens’ accepting a first argument of type ‘LeapController’ could be found (are your missing a using directive or an assembly reference?)

    Can you help me out ?


  6. well,I am zero at c#.And unfortunately i have just got an assignment where I have to design a gesture based powerpoint presentation?

    Can any body guide me..i am absolute begineer at it..

  7. Hej,
    I have a question about the Leap Motion Controller used as a mouse. I’m writing my bachelor thesis and I need exactly that :D. I watched your videos above and also downloaded the code. You ‘ve said that the code in the “LeapAsMouse” Class is absolutely enough to enable this feature. Would this work the same way in C++?
    I’m more a java programmer than a C++/C# programmer so maybe you can help me.

    Många hälsningar

  8. i am creating new assembly file .dll which i will be using in maxscript. how should i add leap.dlll and leapCsharp.dll in my assembly .dll file.. (c# code)

    • I haven’t worked with maxscript before, but if its is an ‘ordinary’ .Net application then add the C# dll’s and set copy to output always.

      If you can give me some more information I might be able to better help you!

      I (and a fellow dev) are publishing a course on developing for Leap Motion in C# next week, I’ll email you once the course is out, there is a free trial where the course is published ( ) 🙂 It’s a very good course that covers both a simple example, and a more complete example.

  9. Thank you, for the brief – but however extremely efficient- tutorial 🙂

  10. Hi, encountered with 2 errors and the programme can’t be run..

    Error 1 ‘Leap.HandList’ does not contain a definition for ‘Empty’ and no extension method ‘Empty’ accepting a first argument of type ‘Leap.HandList’ could be found (are you missing a using directive or an assembly reference?) C:\Users\L31006\Desktop\Leap-Motion-master\Leap_WPF\Util\CustomListener.cs 33 29 Leap_WPF

    Error 2 ‘Leap.Controller’ does not contain a definition for ‘locatedScreens’ and no extension method ‘locatedScreens’ accepting a first argument of type ‘Leap.Controller’ could be found (are you missing a using directive or an assembly reference?) C:\Users\L31006\Desktop\Leap-Motion-master\Leap_WPF\ViewModel\MainViewModel.cs 58 38 Leap_WPF

    Do help if you can.. Thanks!

  11. No code errors but this was prompted and stop the program from running.

    ‘The invocation of the constructor on type ‘Leap_WPF.MainWindow’ that matches the specified binding constraints threw an exception.’ Line number ‘3’ and line position ‘9’

    • Hi the tutorial was done on one of the first versions of the SDK and a lot has changed since then. I’ll see if I can find some time and update this tutorial.

  12. Hey, thanks a lot for your tutorial…. but i have a problem… how i know which finger is doing a tap???

  13. Hi Iris, I downloaded and extracted the tutorial code and am getting two errors.
    “Leap.Controller’ does not contain a definition for ‘CalibrateScreens and no extension method…” lines 58 and 86…
    Do you have an idea of how to fix this error? As I am new to Leap Motion and want to really understand all help and advice are appreciated. Thank you!

  14. Hi Iris

    I’m new on Leap Motion Development, I was try to use a sample from,

    but when I try to run it, the creation of a controller (Controller controller = new Controller();)

    shows the error message:
    “The type initializer for Leap.LeapPINVOKE threw an exception”

    Please, help me

Leave a Reply to DIego Cancel reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>



What is 12 + 13 ?
Please leave these two fields as-is:
IMPORTANT! To be able to proceed, you need to solve the following simple math (so we know that you are a human) :-)