title: UWP BarcodeScanner Preview: CaptureElement doesn't show any Preview
body: <p>My CaptureElements are showing strange behavior. When I set a instantiated MediaCapture as the CaptureElements Source and then call MediaCapture.StartPreviewAsync() the CaptureElement doesn't show anything.</p>
  
  <p>I have one Application (main-app) with a functional BarcodeScanner on the LoginPage.
  -> Works!</p>
  
  <p>Then I wanted to copy the same code to the SettingsPage with small modifications so in case of several attached cameras, the default one can be set.
  -> Doesn't work</p>
  
  <p>Then I tried to run the main-app with the help of the remote debugger on other windows tablets with same Windows 10 Version as my machine (keep in mind, that the BarcodeScanner on the Login-Screen works on my machine).
  -> doesn't work</p>
  
  <p>Because of these failures I copied the running code from the main-apps LoginPage to a completely new solution (lets call it test-app) with the same settings as the original one. I even experimented with referencing the same Dlls, implementing the same design pattern etc.
  -> doesn't work</p>
  
  <p>My Machine:
  Win 10 Pro
  Version 1809
  Build 17763.652</p>
  
  <p>DevEnv:
  MS Visual Studio 2019 Pro
  Vers. 16.1.6</p>
  
  <blockquote>
    <p>EDIT: As minimum required Windows Version I selected Build 16229 and
    my target Version is Build 17763 (my systems Win version)</p>
    
    <p>The "Allow apps to access your camera"-Option in the Widows Settings is switched to ON, so all apps are allowed to access the camera.</p>
  </blockquote>
  
  <p>Xaml</p>
  
  <pre class="lang-xml prettyprint-override"><code>    &lt;Page
          x:Class="QrCodeTest.MainPage"
          xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
          xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
          xmlns:local="using:QrCodeTest"
          xmlns:vm="using:QrCodeTest.ViewModels"
          xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
          xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
          mc:Ignorable="d"&gt;
  
          &lt;Page.DataContext&gt;
              &lt;vm:TestViewModel x:Name="ViewModel" /&gt;
          &lt;/Page.DataContext&gt;
  
          &lt;ScrollViewer&gt;
              &lt;StackPanel&gt;
                  &lt;Button Content="Start Preview" HorizontalAlignment="Center" Click="Button_Click" Margin="5" /&gt;
  
                  &lt;CaptureElement x:Name="capturePreview" HorizontalAlignment="Center" Stretch="Uniform" Width="0" Height="0" Margin="10" /&gt;
  
                  &lt;Button Content="Stop Preview" HorizontalAlignment="Center" Click="Button_Click_1" Margin="5" /&gt;
  
                  &lt;TextBlock Text="{Binding Etikett, Mode=TwoWay}" HorizontalAlignment="Center" Margin="5" /&gt;
              &lt;/StackPanel&gt;
          &lt;/ScrollViewer&gt;
      &lt;/Page&gt;
  </code></pre>
  
  <p>CodeBehind</p>
  
  <pre class="lang-cs prettyprint-override"><code>private BarcodeScanner scanner { get; set; }
  private ClaimedBarcodeScanner claimedScanner { get; set; }
  private MediaCapture captureManager { get; set; }
  
  internal async Task StartScannerAsync () {
              capturePreview.Visibility = Visibility.Visible;
              capturePreview.Width = 400; capturePreview.Height = 300;
  
              scanner = null;
              scanner = await DeviceHelpers.GetFirstDeviceAsync(BarcodeScanner.GetDeviceSelector(connectionTypes), async (id) =&gt; await BarcodeScanner.FromIdAsync(id));
  
              if (scanner != null) {
                  captureManager = new MediaCapture();
                  claimedScanner = await scanner.ClaimScannerAsync();
  
                  if (claimedScanner != null) {
                      claimedScanner.ReleaseDeviceRequested += claimedScanner_ReleaseDeviceRequested;
                      claimedScanner.DataReceived += claimedScanner_DataReceived;
  
                      claimedScanner.IsDecodeDataEnabled = true;
                      IReadOnlyList&lt;uint&gt; supportedSymbologies = await scanner.GetSupportedSymbologiesAsync();
  
                      foreach (uint symbology in supportedSymbologies) {
                          listOfSymbologies.Add(new SymbologyListEntry(symbology));
                      }
  
                      await claimedScanner.EnableAsync();
  
                      MediaCaptureInitializationSettings _captureInitSettings = new MediaCaptureInitializationSettings {
                          VideoDeviceId = scanner.VideoDeviceId,
                          StreamingCaptureMode = StreamingCaptureMode.AudioAndVideo,
                          PhotoCaptureSource = PhotoCaptureSource.VideoPreview
                      };
  
                      await captureManager.InitializeAsync(_captureInitSettings);
                      capturePreview.Source = captureManager;
  
                      try {
                          // Change to false, in case you wanna compare different methods of doing the same
                          bool Like_MP_PAT_UWP = false;
  
                          if (Like_MP_PAT_UWP) {
                              await capturePreview.Source.StartPreviewAsync();
                              await claimedScanner.StartSoftwareTriggerAsync();
                          } else {
  
  
                              LocalDataContext.Etikett = "await captureManager.StartPreviewAsync();";
                              await captureManager.StartPreviewAsync();
                              await claimedScanner.StartSoftwareTriggerAsync();
                              Thread.Sleep(2000);
                              await claimedScanner.StopSoftwareTriggerAsync();
                              await captureManager.StopPreviewAsync();
  
                              LocalDataContext.Etikett = "await capturePreview.Source.StartPreviewAsync();";
                              await capturePreview.Source.StartPreviewAsync();
                              await claimedScanner.StartSoftwareTriggerAsync();
                              Thread.Sleep(2000);
                              await claimedScanner.StopSoftwareTriggerAsync();
                              await capturePreview.Source.StopPreviewAsync();
  
                              LocalDataContext.Etikett = "await claimedScanner.ShowVideoPreviewAsync();";
                              await claimedScanner.ShowVideoPreviewAsync();
                              await claimedScanner.StartSoftwareTriggerAsync();
                              Thread.Sleep(2000);
                              await claimedScanner.StopSoftwareTriggerAsync();
                              claimedScanner.HideVideoPreview();
                          }
  
                      } catch (Exception e) {
                          Exception x = e; displayRequest.RequestRelease();
                      } finally {
                          LocalDataContext.Etikett = string.Empty;
                      }
  
                  }
              }
          }
  </code></pre>
  
  <p>ViewModel:</p>
  
  <pre class="lang-cs prettyprint-override"><code>public class TestViewModel: INotifyPropertyChanged {
          public static TestViewModel Instance { get; set; }
  
          private string _Etikett;
          public string Etikett { get { return _Etikett; } set { _Etikett = value; NotifyPropertyChanged(); } }
  
          public event PropertyChangedEventHandler PropertyChanged;
          public void NotifyPropertyChanged ([CallerMemberName] String propertyName = "") {
              //PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
  
              if (PropertyChanged != null) {
                  PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propertyName));
              }
          }
  }
  </code></pre>
  
  <p>I've wasted already 4 working days just to compare the solutions, the codes etc. The above code was copied from the test-app but it's mostly identical to the one on the main-apps LoginPage (except for the "if (Like_MP_PAT_UWP) {...}".</p>
  
  <p>Every hint is welcome.</p>
  
  <p>Thank you in advance.</p>