Using WinRT API in WPF application for Orientation (Windows 8.1, VS issues)

2

I have followed this tutorial. My first issue is that when I want to add the reference to Windows, I have a full list of referencesenter image description here

As you can see, I added all to my project to make it works, and the other references of the tutorial. But my application won't compile :(

I have this error :

Not implemented (Exception HRESULT : 0x80004001 (E_NOTIMPL))

And this one

Cannot resolve dependency to Windows Runtime type 'Windows.Foundation.Metadata.PlatformAttribute'. When using the ReflectionOnly APIs, dependent Windows Runtime assemblies must be resolved on demand through the ReflectionOnlyNamespaceResolve event.'

I have seen this post but it seems that the issue the author encounter is not the same as mine, because he had it to runtime (exception thrown), whereas I have to compile-time.

Is anyone have an idea how to proceed ?

For information : the main purpose of this is to have access to Windows.Devices.Sensor to have the screen orientation, cause we have an application that takes photo from WebCam in WPF, and when we use it on Surface tablet, the picture display on screen didn't follow the orientation of the tablet, which makes picture really hard to take.

Thanks all

c#
wpf
windows-8
windows-runtime
microsoft-metro
asked on Stack Overflow May 28, 2015 by cdie • edited May 23, 2017 by Community

1 Answer

1

This works fine for me - not sure why you're getting the runtime metadata (one winmd per top-level namespaces) rather than the design-time metadata (single winmd). This is what I did on my 8.1 machine:

  1. File -> New Project -> C# WPF
  2. Unload the project and edit it
  3. Add <TargetPlatformVersion>8.1</TargetPlatformVersion> directly below the existing <TargetFrameworkVersion>4.5</TargetFrameworkVersion> element
  4. References -> Add Reference -> Windows -> Core -> Windows

Then I added the following code to MainWindow.InitializeComponent:

var sos = Windows.Devices.Sensors.SimpleOrientationSensor.GetDefault();
Debug.WriteLine(sos == null ? "No sensor" : sos.GetCurrentOrientation().ToString());

It compiles and runs correctly, but there is no sensor on my desktop, so prints "No sensor".

If you can't get the references UI to show you the design-time metadata, browse to C:\Program Files (x86)\Windows Kits\8.1\References\CommonConfiguration\Neutral\Windows.winmd

answered on Stack Overflow May 30, 2015 by Peter Torr - MSFT

User contributions licensed under CC BY-SA 3.0