views:

317

answers:

3

Is it possible to access the Windows 7 Sensor and Location platform from Silverlight? In particular I would like to know about the location data (GPS) and the ambient light sensor.

Edit: I would assume that the way to do this would be with C# in the code behind file.

+1  A: 

No. Silverlight is supposed to be cross-platform and the Sensor and Location stuff in Win7 is not available anywhere other than Win7. You could try some complicated mix of Silverlight + .NET, but then it would be silly to use Silverlight when the whole .NET/WPF platform is available.

McAravey
Yes, Silverlight is cross platform. It is not true that SIlverlight applications are limited to cross platform functions. A Silverlight app can use lots of .NET calls on Windows that are not available on a Mac.
JonnyBoats
Such as what? If you are referring to the PowerPC Macs, then the answer is sortof. The PowerPC run only Silverlight 1.0 which is the media streaming version of Silverlight.The whole point of Silverlight is that you can write one, deploy once, and use anywhere. And as such, why in the world would they create Silverlight to favor Windows and procced to destroy their architecture. It just makes no sense why it would be that way.And as my credibility, I have been programming Silverlight 2 as part of my job since it was released, and I test most of my work on a Mac.
McAravey
"Such as what?" For example, monitoring the mouse wheel http://silverlightfoundry.blogspot.com/2009/04/how-to-zoom-in-and-out-with-mousewheel.html. I don't have a Mac, but I don't think Apple mice have mouse wheels do they? I agree with you that one could use these Win 7 features from other applications (.NET/WPF), but my question is not "What is the best framework to use Win 7 features", I have a client that wants a SIlverlight web app (WPF is not an option) and wants support for the abbient light sensor at a minimum. I just need to know if it is possible?
JonnyBoats
The simple answer is no. Your example will still work on a Mac (yes, it does have a wheel) but the problem is Macs are not Win7. Even if it is possible to dodge around through JavaScript or something, you whould still need to download a small library of some sort to report the ambient light. At this point it is now a requirement to have .NET, which is not good.
McAravey
+1  A: 

The Silverlight security model is explained (somewhat) here http://blogs.msdn.com/shawnfa/archive/2007/05/09/the-silverlight-security-model.aspx

The Win7 Sensor API is a native API and from .NET requires P/Invoke calls, this in a silverlight context is referred to as critical code (IMO very poorly named, but there you have it) and needs to be in an intermediate layer, so it should be doable but will not be portable.

Tim Jarvis
While the sensor API is native, there is a .NET Sensor and Location Interop Library - see http://windowsteamblog.com/blogs/developers/archive/2009/04/02/windows-7-sensor-and-location-net-interop-sample-library.aspx.
JonnyBoats
A: 

With the new features in Silverlight 4, specifically out of browser and com-inter-op this is definitely possible.

I still don't know about Silverlight 3.

JonnyBoats