Selecting The Front Or Back Camera in Windows / Phone

I recently had a project where I needed a camera from a specific panel (the front-facing camera) in my Windows / Windows Phone app. It took me a little bit to track down all the information, so I thought I’d pull it all together here:

Make sure you add the Webcam and Microphone capabilities to your Package.appxmanifest or you’re get an Unauthorized Access Exception:

My XAML had a single CaptureElement to hold the video:

<CaptureElement x:Name=”CameraCaptureThingy” />

And I used the following code. The key here is line 5, where you enumerate which panel (front or back) has the camera you want to show video from.