/// <summary>
        /// Initializes camera.
        /// </summary>
        /// <param name="sensorLocation">Camera sensor to initialize</param>
        private async Task InitializeCamera(CameraSensorLocation sensorLocation)
        {
            IReadOnlyList<Windows.Foundation.Size> availablePreviewResolutions = PhotoCaptureDevice.GetAvailablePreviewResolutions(sensorLocation);

            Windows.Foundation.Size previewResolution = new Windows.Foundation.Size(int.MaxValue, int.MaxValue);
            for (int i = 0; i < availablePreviewResolutions.Count; i++)
            {
                double ratio = availablePreviewResolutions[i].Width / availablePreviewResolutions[i].Height;
                if (ratio > 1.32 && ratio < 1.34 && PerfectCamera.DataContext.Instance.CameraRatio == CameraRatio.Ratio_4x3)
                {
                    if (previewResolution.Width > availablePreviewResolutions[i].Width)
                    {
                        previewResolution = availablePreviewResolutions[i];
                    }
                }
                else if (ratio > 1.7 && ratio < 1.8 && PerfectCamera.DataContext.Instance.CameraRatio == CameraRatio.Ratio_16x9)
                {
                    if (previewResolution.Width > availablePreviewResolutions[i].Width)
                    {
                        previewResolution = availablePreviewResolutions[i];
                    }
                }
            }

            PerfectCamera.DataContext.Instance.PreviewResolution = previewResolution;

            IReadOnlyList<Windows.Foundation.Size> availableResolutions = PhotoCaptureDevice.GetAvailableCaptureResolutions(sensorLocation);

            //find 4:3 (2048 x 1536) or 16:9 (1280x720)
            Windows.Foundation.Size captureResolution = new Windows.Foundation.Size(0, 0);
            for (int i = 0; i < availableResolutions.Count; i++)
            {
                double ratio = availableResolutions[i].Width / availableResolutions[i].Height;
                if (ratio > 1.32 && ratio < 1.34 && PerfectCamera.DataContext.Instance.CameraRatio == CameraRatio.Ratio_4x3)
                {
                    if (captureResolution.Width < availableResolutions[i].Width)
                    {
                        captureResolution = availableResolutions[i];
                    }
                }
                else if (ratio > 1.7 && ratio < 1.8 && PerfectCamera.DataContext.Instance.CameraRatio == CameraRatio.Ratio_16x9)
                {
                    if (captureResolution.Width < availableResolutions[i].Width)
                    {
                        captureResolution = availableResolutions[i];
                    }
                }
            }
            //
            

            PhotoCaptureDevice device = await PhotoCaptureDevice.OpenAsync(sensorLocation, captureResolution);

            await device.SetPreviewResolutionAsync(previewResolution);
            await device.SetCaptureResolutionAsync(captureResolution);

            Camera = device;

            if (PerfectCamera.DataContext.Instance.CameraType == PerfectCameraType.Selfie)
            {
                _cameraEffect = new Effects()
                {
                    PhotoCaptureDevice = Camera
                };

                _cameraStreamSource = new CameraStreamSource(_cameraEffect, previewResolution);
            }

            if (Camera != null)
            {
                if (Camera.SensorLocation == CameraSensorLocation.Front)
                {
                    FlashButton.IsHitTestVisible = false;
                    FlashButton.Opacity = 0.5;
                }
                else
                {
                    FlashButton.IsHitTestVisible = true;
                    FlashButton.Opacity = 1.0;
                }
            }

            SetOrientation(this.Orientation);
        }
        private void Uninitialize()
        {
            if (_mediaElement != null)
            {
                _mediaElement.Source = null;
                _mediaElement = null;
            }

            if (_cameraStreamSource != null)
            {
                _cameraStreamSource = null;
            }

            _cameraEffect = null;
        }