Click here to Skip to main content
15,617,116 members
Articles / Desktop Programming / WPF
Posted 10 Oct 2012


14 bookmarked

Fun with Win8 its sensors/XNA/MVVM/Javascript

Rate me:
Please Sign up or sign in to vote.
4.91/5 (4 votes)
10 Oct 2012CPOL3 min read
An article which will use Win8 sensors from the desktop and will show XNA and Javascript interop from WPF


I first saw this contest a while ago and thought ok, what could I do that would be interesting here. I read the brief of what we are meant to do, and I thought this might be a time to try and mess with a few things that have been on my Radar for a while.

So my plan is to create a desktop application that will make use of some  of the sensors that are available both to WinRT and desktop APIs  for applications running on Windows 8.

For example I plan to make use of the following sensors:

  1. LightSenor : which will be used to visually change the application skin when the ambient light goes above and below a certain threshold
  2. Gyrometer: which I plan to use to alter the position of a WebView hosted google earth
  3. Accelerometer : which I plan to use to spin the position of a WebView hosted google earth, when I see the Shaken event

I will obviously also be using MVVM (as I have a nice framework for working with WPF and MVVM, and I will also be making use of the System.ComponentModel.Composition namespace.

The Proposed UI

This is obviously just a sketched up mock, but the idea would be to have an extremely clean UI, which looked something like that shown below. Obviously this rubbish sketch does not do it justice, and it will be more polished that this.  

Image 1

The idea being that the left hand side of the screen would hold a Farseer physhics panel that would hold physhics bodies, within a XNA Game class. I would be ensuring that this XNA based code is able to sit inside a regular WPF application.  

Hosting XNA as a native WPF element is not discussed that much anywhere on the web, their are loads of nasty P/Invoke hasks, but I want to try and find a solution that allows me to treat the XNA Game screen as a regular WPF control. This will be a challenge in itself. But I will also need to implement some form of messaging from the XNA Game screen to WPF land, ir order for data to flow from one to the other and vice-versa.

The Farseer physhics panel would hold simple physhics bodies that had some geographical metadata associated to them, such that when they are clicked the WebView hosted Google Earth (which is done using Javascript I might add) will be animated to the clicked location. For fun the physhics bodies will obviously have to crash into each other, and be bounded by walls to confine their movements.

This will involve using the ScriptNotify interop method available from WinRT to communicate with the JavaScript which in turn will alter the Google Earth location.

I will also be allowing the user to click a link which will do an image search using the currently selected metadata from the Farseer physhics panel physhics body.

I know this doesn't sound that crazy, but I think the real fun will come when I start messing around with the sensors, it will be pretty fund I think to watch the earth shake as you shake the device, and watch the visuals change when the ambient light changes.

I don't have any code right now, but this is the plan, I hope you can see there is enough potential there to have some fun and create a pretty fun application. So if I manage to get through round 1, I will do my best to try and do all of this to the best of my abilities 


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Written By
Software Developer (Senior)
United Kingdom United Kingdom
I currently hold the following qualifications (amongst others, I also studied Music Technology and Electronics, for my sins)

- MSc (Passed with distinctions), in Information Technology for E-Commerce
- BSc Hons (1st class) in Computer Science & Artificial Intelligence

Both of these at Sussex University UK.


I am lucky enough to have won a few awards for Zany Crazy code articles over the years

  • Microsoft C# MVP 2016
  • Codeproject MVP 2016
  • Microsoft C# MVP 2015
  • Codeproject MVP 2015
  • Microsoft C# MVP 2014
  • Codeproject MVP 2014
  • Microsoft C# MVP 2013
  • Codeproject MVP 2013
  • Microsoft C# MVP 2012
  • Codeproject MVP 2012
  • Microsoft C# MVP 2011
  • Codeproject MVP 2011
  • Microsoft C# MVP 2010
  • Codeproject MVP 2010
  • Microsoft C# MVP 2009
  • Codeproject MVP 2009
  • Microsoft C# MVP 2008
  • Codeproject MVP 2008
  • And numerous codeproject awards which you can see over at my blog

Comments and Discussions

GeneralMy vote of 5 Pin
Adam David Hill10-Oct-12 22:33
professionalAdam David Hill10-Oct-12 22:33 
GeneralRe: My vote of 5 Pin
Sacha Barber10-Oct-12 23:22
Sacha Barber10-Oct-12 23:22 
GeneralRe: My vote of 5 Pin
Adam David Hill10-Oct-12 23:43
professionalAdam David Hill10-Oct-12 23:43 
GeneralRe: My vote of 5 Pin
Adam David Hill13-Oct-12 2:01
professionalAdam David Hill13-Oct-12 2:01 
GeneralRe: My vote of 5 Pin
Sacha Barber13-Oct-12 11:36
Sacha Barber13-Oct-12 11:36 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.