title: How to use Windows.Devices.Enumeration.DevicePicker with Prism (MVVM)?
body: <p>I am working on a new UWP application that interacts with some hardware via Bluetooth. Using the <a href="https://github.com/Microsoft/Windows-universal-samples/tree/master/Samples/DeviceEnumerationAndPairing" rel="nofollow noreferrer">windows-universal-samples repo</a> as a guide I was able to sucessfully get what I wanted working.</p>
  
  <p>Now I am trying to refactor the code I wrote in a click event handler into a view model class using Prism. However I don't know how to approach this. In other scenarios where I need to pass data between a View and ViewModel I would create a property on the ViewModel and bind it to the control in the view's XAML.</p>
  
  <p>The problem is that <code>Windows.Devices.Enumaration.DevicePicker</code> is used in a way that doesn't seem compatible with the MVVM pattern. In the click handler, the data and control are merged together and I don't see how I can make some kind of list property on the view model and then bind it to the view. Here is the simplest example of the code I am working with:</p>
  
  <pre><code>async void DiscoverButton_OnClick(object sender, RoutedEventArgs e)
  {
      var devicePicker = new DevicePicker();
      devicePicker.Filter.SupportedDeviceSelectors.Add(BluetoothLEDevice.GetDeviceSelectorFromPairingState(true));
  
      // Calculate the position to show the picker (right below the buttons)
      var ge = DiscoverButton.TransformToVisual(null);
      var point = ge.TransformPoint(new Point());
      var rect = new Rect(point, new Point(100, 100));
      var device = await devicePicker.PickSingleDeviceAsync(rect);
  
      var bluetoothLEDevice = await BluetoothLEDevice.FromIdAsync(device.Id);
  }
  </code></pre>
  
  <p>See <code>PickSingleDeviceAsync()</code> creates a control directly.</p>