BluetoothLEDeviceDisplay.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. using System.ComponentModel;
  2. using Windows.Devices.Enumeration;
  3. namespace BluetoothLENet.Classes
  4. {
  5. /// <summary>
  6. /// Display class used to represent a BluetoothLEDevice in the Device list
  7. /// </summary>
  8. public class BluetoothLEDeviceDisplay : INotifyPropertyChanged
  9. {
  10. public BluetoothLEDeviceDisplay(DeviceInformation deviceInfoIn)
  11. {
  12. DeviceInformation = deviceInfoIn;
  13. }
  14. public DeviceInformation DeviceInformation { get; private set; }
  15. public string Id => DeviceInformation.Id;
  16. public string Name => DeviceInformation.Name;
  17. public bool IsPaired => DeviceInformation.Pairing.IsPaired;
  18. public bool IsConnected => (bool?)DeviceInformation.Properties["System.Devices.Aep.IsConnected"] == true;
  19. public bool IsConnectable => (bool?)DeviceInformation.Properties["System.Devices.Aep.Bluetooth.Le.IsConnectable"] == true;
  20. public IReadOnlyDictionary<string, object> Properties => DeviceInformation.Properties;
  21. public event PropertyChangedEventHandler PropertyChanged;
  22. public void Update(DeviceInformationUpdate deviceInfoUpdate)
  23. {
  24. DeviceInformation.Update(deviceInfoUpdate);
  25. OnPropertyChanged("Id");
  26. OnPropertyChanged("Name");
  27. OnPropertyChanged("DeviceInformation");
  28. OnPropertyChanged("IsPaired");
  29. OnPropertyChanged("IsConnected");
  30. OnPropertyChanged("Properties");
  31. OnPropertyChanged("IsConnectable");
  32. }
  33. protected void OnPropertyChanged(string name)
  34. {
  35. PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
  36. }
  37. }
  38. }