private async void OnCapturePhotoButtonClick(object sender, RoutedEventArgs e)
        {
            var file = await TestedControl.CapturePhotoToStorageFileAsync(ApplicationData.Current.TemporaryFolder);

            var bi = new BitmapImage();

            IRandomAccessStreamWithContentType stream;

            try
            {
                stream = await TryCatchRetry.RunWithDelayAsync <Exception, IRandomAccessStreamWithContentType>(
                    file.OpenReadAsync(),
                    TimeSpan.FromSeconds(0.5),
                    10,
                    true);
            }
            catch (Exception ex)
            {
                // Seems like a bug with WinRT not closing the file sometimes that writes the photo to.
                new MessageDialog(ex.Message, "Error").ShowAsync();

                return;
            }

            bi.SetSource(stream);
            PhotoImage.Source = bi;
            CapturedVideoElement.Visibility = Visibility.Collapsed;
            PhotoImage.Visibility           = Visibility.Visible;
        }
        private async void OnCaptureVideoButtonClick(object sender, RoutedEventArgs e)
        {
            if (!_capturingVideo)
            {
                CaptureVideoButton.Content = "Stop";
                _capturingVideo            = true;
                _videoFile = await TestedControl.StartVideoCaptureAsync(ApplicationData.Current.TemporaryFolder);

                CapturedVideoElement.Visibility = Visibility.Visible;
                PhotoImage.Visibility           = Visibility.Collapsed;

                IRandomAccessStreamWithContentType stream;

                try
                {
                    stream = await TryCatchRetry.RunWithDelayAsync <Exception, IRandomAccessStreamWithContentType>(
                        _videoFile.OpenReadAsync(),
                        TimeSpan.FromSeconds(0.5),
                        10);
                }
                catch (Exception ex)
                {
#pragma warning disable 4014
                    // Seems like a bug with WinRT not closing the file sometimes that it writes the video to.
                    new MessageDialog(ex.Message, "Error").ShowAsync();
#pragma warning restore 4014

                    return;
                }

                if (this.CapturedVideoElement == null)
                {
                    return;
                }

                this.CapturedVideoElement.SetSource(stream, _videoFile.ContentType);
            }
            else
            {
                CaptureVideoButton.Content = "Record";
                _capturingVideo            = false;

                await TestedControl.StopCapture();
            }
        }
        private async void OnShowHidePreviewButtonClick(object sender, RoutedEventArgs e)
        {
            this.ShowHidePreviewButton.IsEnabled = false;

            if (this.ShowHidePreviewButton.IsChecked == true)
            {
                await TestedControl.HideAsync();

                this.ShowHidePreviewButton.Content = "Show";
            }
            else
            {
                var result = await TestedControl.ShowAsync();

                this.ShowHidePreviewButton.Content = "Hide";
            }

            this.ShowHidePreviewButton.IsEnabled = true;
        }
 private async void OnHidePreviewButtonClick(object sender, RoutedEventArgs e)
 {
     await TestedControl.HideAsync();
 }
 private async void OnShowPreviewButtonClick(object sender, RoutedEventArgs e)
 {
     var result = await TestedControl.ShowAsync();
 }
 private async void OnCycleCamerasButtonClick(object sender, RoutedEventArgs e)
 {
     await TestedControl.CycleCamerasAsync();
 }
        private void Test(Type ctrlType)
        {
            // Absolute url with protocol.
            try
            {
                GHTSubTestBegin(ctrlType, "Absolute url with protocol:", false);
                AddToForm(TestedControl);
                GHTSubTestAddResult(TestedControl.ResolveUrl("http://localhost/GHTTests/"));
            }
            catch (Exception ex)
            {
                GHTSubTestUnexpectedExceptionCaught(ex);
            }
            GHTSubTestEnd();

            // Absolute url without protocol.
            try
            {
                GHTSubTestBegin(ctrlType, "Absolute url without protocol:", false);
                AddToForm(TestedControl);
                GHTSubTestAddResult(TestedControl.ResolveUrl("/GHTTests/"));
            }
            catch (Exception ex)
            {
                GHTSubTestUnexpectedExceptionCaught(ex);
            }
            GHTSubTestEnd();

            // Relative url.
            try
            {
                GHTSubTestBegin(ctrlType, "Relative url:", false);
                AddToForm(TestedControl);
                GHTSubTestAddResult(TestedControl.ResolveUrl("aa/bb"));
            }
            catch (Exception ex)
            {
                GHTSubTestUnexpectedExceptionCaught(ex);
            }
            GHTSubTestEnd();

            // Relative url with a leading ../.
            try
            {
                GHTSubTestBegin(ctrlType, "Relative url with a leading ../:", false);
                AddToForm(TestedControl);
                GHTSubTestAddResult(TestedControl.ResolveUrl("../aa/bb"));
            }
            catch (Exception ex)
            {
                GHTSubTestUnexpectedExceptionCaught(ex);
            }
            GHTSubTestEnd();

            // Relative url only  ../.
            try
            {
                GHTSubTestBegin(ctrlType, "Relative url only  ../:", false);
                AddToForm(TestedControl);
                GHTSubTestAddResult(TestedControl.ResolveUrl("../"));
            }
            catch (Exception ex)
            {
                GHTSubTestUnexpectedExceptionCaught(ex);
            }
            GHTSubTestEnd();

            // Relative url higher then root.
            try
            {
                GHTSubTestBegin(ctrlType, "Relative url higher then root:", false);
                AddToForm(TestedControl);
                GHTSubTestAddResult(TestedControl.ResolveUrl("../../../../../"));
                GHTSubTestExpectedExceptionNotCaught("HttpException");
            }
            catch (HttpException ex)
            {
                GHTSubTestExpectedExceptionCaught(ex);
            }
            catch (Exception ex)
            {
                GHTSubTestUnexpectedExceptionCaught(ex);
            }
            GHTSubTestEnd();

            // A url  that uses \.
            try
            {
                GHTSubTestBegin(ctrlType, "A url  that uses \\:", false);
                AddToForm(TestedControl);
                GHTSubTestAddResult(TestedControl.ResolveUrl("aa\\bb\\cc"));
            }
            catch (Exception ex)
            {
                GHTSubTestUnexpectedExceptionCaught(ex);
            }
            GHTSubTestEnd();

            // A file path
            try
            {
                GHTSubTestBegin(ctrlType, "A file path:", false);
                AddToForm(TestedControl);
                GHTSubTestAddResult(TestedControl.ResolveUrl("c:\\GHTests\\file.vb"));
            }
            catch (Exception ex)
            {
                GHTSubTestUnexpectedExceptionCaught(ex);
            }
            GHTSubTestEnd();

            // Empty string
            try
            {
                GHTSubTestBegin(ctrlType, "Empty string:", false);
                AddToForm(TestedControl);
                GHTSubTestAddResult(TestedControl.ResolveUrl(String.Empty));
            }
            catch (Exception ex)
            {
                GHTSubTestUnexpectedExceptionCaught(ex);
            }
            GHTSubTestEnd();

            // 'A url that contains invalid charachters.
            try
            {
                GHTSubTestBegin(ctrlType, "A url that contains invalid charachters:", false);
                AddToForm(TestedControl);
                GHTSubTestAddResult(TestedControl.ResolveUrl("~!@#$%^&*()_+-=[]\\{}|;':,./<>?"));
            }
            catch (Exception ex)
            {
                GHTSubTestUnexpectedExceptionCaught(ex);
            }
            GHTSubTestEnd();
        }