Search code examples
c#bluetoothbluetooth-lowenergygatt

How do I configure a WPF project to use BLE?


Update 2: Below are the details of where I am at the moment, but I didn't want the detail to derail any general answers that may bear on the base question of finding any path to BLE / GATT in WPF.

Build system version:

Microsoft Visual Studio Community 2017 
Version 15.7.4
VisualStudio.15.Release/15.7.4+27703.2035
Microsoft .NET Framework
Version 4.7.03056

So far, I have changed the project file to target windows 8.1, <TargetPlatformVersion>8.1</TargetPlatformVersion>.

Currently, I am getting local BLE advertisements, but when I try to access a GATT service:

var _service = await GattDeviceService.FromIdAsync(deviceId);

Update 1: I have attempted to include WinRT. Here is my Reference and it's properties:

Reference Properties

Any help will be greatly appreciated.


Solution

  • Install the Windows 10 SDK.

    Then add three References for:

    Windows
    Windows.Foundation.FoundationContract
    WindowsBase
    

    Then set 'Copy Local' to 'true' in the properties.

    Possible Location Hints:

    D:\Windows Kits\10\UnionMetadata\10.0.17134.0\Windows.winmd
    D:\Windows Kits\10\References\10.0.17134.0\Windows.Foundation.FoundationContract\3.0.0.0\en\Windows.Foundation.FoundationContract.xml
    C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\WindowsBase.dll
    

    Be sure to do a full update on the target machine. As of this writing, there were a few items that did not work right until the Win10 update was done.

    Another possible way to do this is through NuGet UWP-Desktop, though I never got the chance to try it.