Skip to content

Instantly share code, notes, and snippets.


Peter Foot peterfoot

View GitHub Profile
peterfoot / NavigationViewHelper.cs
Created Mar 10, 2022
Add AccessKeys to standard NavigationView elements
View NavigationViewHelper.cs
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Input;
namespace InTheHand.UI.Xaml.Controls
public static class NavigationViewHelper
/// <summary>
/// Add standard access keys to the NavigationView control.
/// </summary>
peterfoot / BluetoothComPort.cs
Last active Jan 17, 2022
enumerate the Bluetooth COM ports on desktop Windows. Determine the mappings between Bluetooth addresses and COM port names.
View BluetoothComPort.cs
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Text;
namespace BluetoothDiagnostics
public sealed class BluetoothComPort
peterfoot / NotificationMessageGeneric.cs
Created Jul 14, 2021
MvvmLight style NotificationMessage<T> for Microsoft.Toolkit.Mvvm
View NotificationMessageGeneric.cs
namespace Microsoft.Toolkit.Mvvm.Messaging.Messages
public sealed class NotificationMessage<T>
public NotificationMessage(T content, string notification)
Content = content;
Notification = notification;
peterfoot / BrightnessHelper.cs
Last active Mar 30, 2021
Set the display brightness from a Win32 application
View BrightnessHelper.cs
public static class BrightnessHelper
public static void SetBrightness(uint brightness)
if (brightness > 100)
throw new ArgumentOutOfRangeException("brightness");
// get handle to primary display
peterfoot / BluetoothTest.cs
Created Apr 23, 2018
Sample Bluetooth printing from Unity
View BluetoothTest.cs
var devices = DeviceInformation.FindAll(RfcommDeviceService.GetDeviceSelector(RfcommServiceId.SerialPort));
var deviceInfo = devices[0]; // this makes some assumptions about your paired devices so really the results should be enumerated and checked for the correct device
var device = BluetoothDevice.FromDeviceInformation(deviceInfo);
var serResults = device.GetRfcommServices(BluetoothCacheMode.Cached);
foreach(RfcommDeviceService serv in serResults.Services)
if(serv.ServiceId == RfcommServiceId.SerialPort)
var stream = serv.OpenStream();
byte[] buff = System.Text.Encoding.ASCII.GetBytes("Testing\r\n");
View ColorExtensions.cs
using System;
namespace Xamarin.Forms.Platform.WinRT
public static class ColorExtensions
public static Windows.UI.Color ToWindows(this Xamarin.Forms.Color color)
return Windows.UI.Color.FromArgb(Convert.ToByte(color.A * 255), Convert.ToByte(color.R * 255), Convert.ToByte(color.G * 255), Convert.ToByte(color.B * 255));
View App.xaml.cs
public App()
this.Suspending += OnSuspending;
_watcher = new BluetoothLEAdvertisementWatcher();
_watcher.Received += _watcher_Received;
peterfoot / BluetoothImagingMinorClass.cs
Created Mar 27, 2017
Get the minor Class of Device value for a Bluetooth Imaging device.
View BluetoothImagingMinorClass.cs
using System;
using Windows.Devices.Bluetooth;
namespace InTheHand.Devices.Bluetooth
/// <summary>
/// Defines missing values in the <see cref="BluetoothMinorClass"/> enumeration for devices with a <see cref="BluetoothClassOfDevice.MajorClass"/> of Imaging.
/// </summary>
public enum BluetoothImagingMinorClass
View MainPage.xaml
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns=""
<forms:MediaElement HorizontalOptions="Fill" VerticalOptions="Center" HeightRequest="240" x:Name="Media" AreTransportControlsEnabled="true" Source=""/>
View MainPage.xaml