title: Is it possible to connect to a BTLE device in a WPF application?
body: <p>So I am trying to connect to a Polar H7 Heart Rate Monitor, and I need to use a WPF application to do it. I'm using Windows 10.</p>
  
  <p>Now I have done this with a UWP application already and it works perfectly, but I'd like to use WPF (if it is possible) instead to do the same.</p>
  
  <p>I found <a href="https://blogs.windows.com/buildingapps/2017/01/25/calling-windows-10-apis-desktop-application/" rel="nofollow noreferrer">this post</a> on how to use Windows 10 APIs in WPF/winforms/etc and thought perfect, that's what I need. I successfully added the Bluetooth API to my WPF project and threw in the code that was working for my UWP project, but it doesn't work.</p>
  
  <p>Here's a snippet of my code up to where it stops working:</p>
  
  <pre><code>        DeviceInformation _devicePolar = null;
          string StatusInformation;
          string StatusInformation2;
          var devices = await DeviceInformation.FindAllAsync(GattDeviceService.GetDeviceSelectorFromUuid(GattServiceUuids.HeartRate));
          foreach(var d in devices)
          {
              Debug.WriteLine(d.Name + " " + d.Id);
          }
          if (null == devices || devices.Count &lt;= 0) return;
          foreach (var device in devices.Where(device =&gt; device.Name == "Polar H7 DCB16C16"))
          {
              _devicePolar = device;
              StatusInformation = string.Format("Found {0}", _devicePolar.Name);
              break;
          }
          if (_devicePolar == null) return;
          var service = await GattDeviceService.FromIdAsync(_devicePolar.Id);
          if (service == null) return;
  </code></pre>
  
  <p>Now, this call </p>
  
  <pre><code>await GattDeviceService.FromIdAsync(_devicePolar.Id) 
  </code></pre>
  
  <p>is returning null. I was actually having the same problem when I made the UWP application and I found out it was because I forgot to throw in this </p>
  
  <pre><code>  &lt;Capabilities&gt;
      &lt;Capability Name="internetClient" /&gt;
      &lt;DeviceCapability Name="bluetooth" /&gt;
    &lt;/Capabilities&gt;
  </code></pre>
  
  <p>Into my manifest file. Once I put that in (on my UWP application) it worked fine. But there seems to be no equivalent place for this piece in a WPF application. Now going back to the blog post on how to add Win 10 libraries to WPF, this bit seems to be telling me that was the case all along:</p>
  
  <blockquote>
    <p>The second set of APIs that you can’t use are ones that depend on an app’s package identity. UWP apps have package identities while PC software does not. Package identity information can be found in the app manifest file.</p>
  </blockquote>
  
  <p>And looking further into the Microsoft topic linked in the post it does specify about Bluetooth that "Not all APIs are currently supported for packaged apps." Which is terribly non-specific.</p>
  
  <p>Also should mention, before trying this I tried to use the 32feet library, but my device was not showing up at all while other devices (not LE) were, so I am assuming that 32feet just doesn't support BTLE. I found <a href="https://social.msdn.microsoft.com/Forums/vstudio/en-US/c58894f8-bc10-46dc-a42d-f454874d2d44/c-desktop-application-to-connect-to-ble-device-through-bluetooth?forum=csharpgeneral" rel="nofollow noreferrer">this</a> asking the same about 32feet and that is what led me to try what I have detailed above instead, but I'm still not 100% clear on whether or not I can simply use 32feet to connect to BTLE devices.</p>
  
  <p>So my question is, am I right that what am I trying to do (WPF application using Windows 10 API to connect to Bluetooth device) can't currently be done? If not, what am I doing wrong?</p>