Search code examples
c#windows-phone-8.1screen-rotation

Adapting to screen rotation windows phone


I am creating a camera app using MediaCapture. I am trying to adapt to screen rotation and thus I have created the following method:

        private void Current_SizeChanged(object sender, Windows.UI.Core.WindowSizeChangedEventArgs e)
    {
        width = Window.Current.Bounds.Width;
        height = Window.Current.Bounds.Height;
        //captureManager.SetPreviewRotation(VideoRotation.Clockwise90Degrees);
        //if (ApplicationView.GetForCurrentView().Orientation.ToString() == "Portrait") capturePreview.Stretch = Stretch.Fill;
        capturePreview.Width = width;
        capturePreview.Height = height;
        imagePreview.Width = width;
        imagePreview.Height = height;
        //if (ApplicationView.GetForCurrentView().Orientation.ToString() == "Portrait") capturePreview.Stretch = Stretch.Fill;
        //else capturePreview.Stretch = Stretch.Uniform;
    }

When I open my app the camera fills the whole page but when I flip the camera the capturePreview only takes half of the page, It doesn't matter if I start the app in portrait or horizontal mode, the other mode won't work but the first mode will also if flipped in to.

Another question is about the actual capturePreview layout, I found that if I keep the screen at horizontal layout the camera works great but if the device is in portrait mode I cant fill the whole page without stretching the photo, is there a way to keep only one element on the screen in a certain rotation (capturePreview) I tried rotating it with a rotation tranform but that also affects the actual place of the element. Thank you


Solution

  • In WP you get the CurrentViewState through the Window.Sizechanged Event.

    See this MSDN article (first result from google)